-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesAux6.h
640 lines (588 loc) · 23.7 KB
/
esAux6.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
/*
--------------------------------------------------
James William Fletcher (github.com/mrbid)
January 2024 - esAux6.h v6.0
--------------------------------------------------
A pretty good color converter: https://www.easyrgb.com/en/convert.php
Lambertian fragment shaders make a difference, but only if you normalise the
vertNorm in the fragment shader. Most of the time you won't notice the difference.
This focuses on using ML generated models from LUMA GENIE or MESHY.AI
converted to vertex colors and shaded via shadeLambert().
No Textures, No Phong, One view-space light with position, ambient and saturation control.
Default: ambient = 0.648, saturate = 0.26 or 1.0
The model header files have their own register function with the new ptf2.c
the idea is simply that the order you call the "<model-name>_register()" functions in
is the index of the model loaded, so the first 0, then, 1 and so on.
Then you use this index to call esBindModel(id) and esRenderModel()
or just esBindRender(id).
Requires:
- vec.h: https://gist.github.com/mrbid/77a92019e1ab8b86109bf103166bd04e
- mat.h: https://gist.github.com/mrbid/cbc69ec9d99b0fda44204975fcbeae7c
¿ptf2.c: https://gist.github.com/mrbid/35b1d359bddd9304c1961c1bf0fcb882
*/
#ifndef AUX_H
#define AUX_H
//#define VERTEX_SHADE // uncomment for vertex shaded, default is pixel shaded
//#define MAX_MODELS 32
//#define GL_DEBUG // allows you to use esDebug(1); to enable OpenGL errors to the console.
// https://gen.glad.sh/ and https://glad.dav1d.de/ might help
//#define MODEL_DATA_STRIDED // uncomment to load vertex data into GPU memory from one strided vertex buffer
#include "vec.h"
#include "mat.h"
// render state id's ~ ( just so you don't need to define them when using shadeLambert() or similar ) ~
GLint projection_id;
GLint modelview_id;
GLint position_id;
GLint normal_id;
GLint color_id;
GLint lightpos_id;
GLint ambient_id;
GLint saturate_id;
GLint opacity_id;
// ESModel ✨
typedef struct
{
GLuint vid; // Vertex Array Buffer ID
GLuint iid; // Index Array Buffer ID
GLuint cid; // Colour Array Buffer ID
GLuint nid; // Normal Array Buffer ID
#ifdef MAX_MODELS
GLuint itp; // Index Type (0:ubyte, 1:ushort, 2:uint)
GLuint ni; // Number of Indices
#endif
} ESModel;
// utility functions
GLuint esRand(const GLuint min, const GLuint max);
GLfloat esRandFloat(const GLfloat min, const GLfloat max);
void esBind(const GLenum target, GLuint* buffer, const void* data, const GLsizeiptr datalen, const GLenum usage);
void esRebind(const GLenum target, GLuint* buffer, const void* data, const GLsizeiptr datalen, const GLenum usage);
// set shader pipeline: single color for whole object
void shadeFullbrightSolid(GLint* position, GLint* projection, GLint* modelview, GLint* color, GLint* opacity);
void shadeLambertSolid(GLint* position, GLint* projection, GLint* modelview, GLint* lightpos, GLint* normal, GLint* color, GLint* ambient, GLint* saturate, GLint* opacity);
// set shader pipeline: color array for whole object
void shadeFullbright(GLint* position, GLint* projection, GLint* modelview, GLint* color, GLint* opacity);
void shadeLambert(GLint* position, GLint* projection, GLint* modelview, GLint* lightpos, GLint* normal, GLint* color, GLint* ambient, GLint* saturate, GLint* opacity);
// misc
GLuint debugShader(GLuint shader_program);
// make the shader programs before you use them with shadeFunctions()
void makeAllShaders(); // don't be this lazy!
void makeFullbrightSolid();
void makeLambertSolid();
void makeFullbright();
void makeLambert();
//*************************************
// UTILITY CODE
//*************************************
GLuint esRand(const GLuint min, const GLuint max){return (rand()%(max+1-min))+min;}
GLfloat esRandFloat(const GLfloat min, const GLfloat max)
{
static GLfloat rrndmax = 1.f/(GLfloat)RAND_MAX;
return (((GLfloat)rand()) * rrndmax) * (max-min) + min;
}
void esBind(const GLenum target, GLuint* buffer, const void* data, const GLsizeiptr datalen, const GLenum usage)
{
glGenBuffers(1, buffer);
glBindBuffer(target, *buffer);
glBufferData(target, datalen, data, usage);
}
void esRebind(const GLenum target, GLuint* buffer, const void* data, const GLsizeiptr datalen, const GLenum usage)
{
glBindBuffer(target, *buffer);
glBufferData(target, datalen, data, usage);
}
///
#ifdef GL_DEBUG
// https://registry.khronos.org/OpenGL-Refpages/gl4/html/glDebugMessageControl.xhtml
// https://registry.khronos.org/OpenGL-Refpages/es3/html/glDebugMessageControl.xhtml
// OpenGL ES 3.2 or OpenGL 4.3 and above only.
void GLAPIENTRY MessageCallback( GLenum source,
GLenum type,
GLuint id,
GLenum severity,
GLsizei length,
const GLchar* message,
const void* userParam )
{
printf("GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n",
( type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "" ),
type, severity, message );
}
void esDebug(const GLuint state)
{
if(state == 1)
{
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback(MessageCallback, 0);
glDebugMessageControl(GL_DEBUG_SOURCE_API, GL_DONT_CARE, GL_DEBUG_SEVERITY_NOTIFICATION, 0, NULL, GL_FALSE);
}
else
{
glDisable(GL_DEBUG_OUTPUT);
glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
}
}
#endif
/// just hiding this away down here, for the model_register() function system to load and index models into GPU memory.
#ifdef MAX_MODELS // Once the <*>_register() is called just esBindModel(id) and esRenderModel() or just esBindRender(id)
#ifdef MODEL_DATA_STRIDED
ESModel esModelArray[MAX_MODELS] = {0};
uint esModelArray_index = 0;
uint esBoundModel = 0;
void esBindModel(const uint id)
{
if(esModelArray[id].ni == 0){return;}
const GLsizei stride = 9*sizeof(GLfloat);
glBindBuffer(GL_ARRAY_BUFFER, esModelArray[id].vid);
glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, stride, (GLvoid*)0);
glEnableVertexAttribArray(position_id);
glBindBuffer(GL_ARRAY_BUFFER, esModelArray[id].vid);
glVertexAttribPointer(normal_id, 3, GL_FLOAT, GL_FALSE, stride, (GLvoid*)(3*sizeof(GLfloat)));
glEnableVertexAttribArray(normal_id);
glBindBuffer(GL_ARRAY_BUFFER, esModelArray[id].vid);
glVertexAttribPointer(color_id, 3, GL_FLOAT, GL_FALSE, stride, (GLvoid*)(6*sizeof(GLfloat)));
glEnableVertexAttribArray(color_id);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, esModelArray[id].iid);
esBoundModel = id;
}
void esRenderModel()
{
if(esModelArray[esBoundModel].ni == 0){return;}
//printf("esRenderModel(%u): %u %u\n", id, esModelArray[id].ni, esModelArray[id].itp);
glDrawElements(GL_TRIANGLES, esModelArray[esBoundModel].ni, esModelArray[esBoundModel].itp, 0);
}
void esBindRender(const uint id)
{
if(esModelArray[id].ni == 0){return;}
esBindModel(id);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, esModelArray[id].iid);
glDrawElements(GL_TRIANGLES, esModelArray[id].ni, esModelArray[id].itp, 0);
}
#else
ESModel esModelArray[MAX_MODELS]; // just create new "sub - index arrays" of categories that index this master array
uint esModelArray_index = 0; // e.g; 0-10 index of fruit 3d models A-Z by name?
uint esBoundModel = 0;
void esBindModel(const uint id)
{
glBindBuffer(GL_ARRAY_BUFFER, esModelArray[id].vid);
glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(position_id);
glBindBuffer(GL_ARRAY_BUFFER, esModelArray[id].nid);
glVertexAttribPointer(normal_id, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(normal_id);
glBindBuffer(GL_ARRAY_BUFFER, esModelArray[id].cid);
glVertexAttribPointer(color_id, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(color_id);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, esModelArray[id].iid);
esBoundModel = id;
}
void esRenderModel()
{
glDrawElements(GL_TRIANGLES, esModelArray[esBoundModel].ni, esModelArray[esBoundModel].itp, 0);
}
/// above is; bind it, draw a few instances of it. ... below is ... bind it, draw it, draw something different.
void esBindRender(const uint id)
{
glBindBuffer(GL_ARRAY_BUFFER, esModelArray[id].vid);
glVertexAttribPointer(position_id, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(position_id);
glBindBuffer(GL_ARRAY_BUFFER, esModelArray[id].nid);
glVertexAttribPointer(normal_id, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(normal_id);
glBindBuffer(GL_ARRAY_BUFFER, esModelArray[id].cid);
glVertexAttribPointer(color_id, 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(color_id);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, esModelArray[id].iid);
glDrawElements(GL_TRIANGLES, esModelArray[id].ni, esModelArray[id].itp, 0);
}
#endif
#endif // I like this system. It's amost frictionless and you can index what you like off it.
// but you need the new ptf2.c program: https://gist.github.com/mrbid/35b1d359bddd9304c1961c1bf0fcb882
//*************************************
// SHADER CODE
//*************************************
const GLchar* v0 = // ShadeFullbrightSolid() ]- vertex shader
"#version 100\n"
"uniform mat4 modelview;\n"
"uniform mat4 projection;\n"
"uniform vec3 color;\n"
"uniform float opacity;\n"
"attribute vec4 position;\n"
"varying vec4 fragcolor;\n"
"void main()\n"
"{\n"
"fragcolor = vec4(color, opacity);\n"
"gl_Position = projection * modelview * position;\n"
"}\n";
const GLchar* f0 = // ShadeFullbrightSolid() ]- fragment shader
"#version 100\n"
"precision highp float;\n"
"varying vec4 fragcolor;\n"
"void main()\n"
"{\n"
"gl_FragColor = fragcolor;\n"
"}\n";
///
const GLchar* v01 = // ShadeFullbright() ]- vertex shader
"#version 100\n"
"uniform mat4 modelview;\n"
"uniform mat4 projection;\n"
"attribute vec3 color;\n"
"uniform float opacity;\n"
"attribute vec4 position;\n"
"varying vec3 vertCol;\n"
"varying float vertOpa;\n"
"void main()\n"
"{\n"
"vertCol = color;\n"
"vertOpa = opacity;\n"
"gl_Position = projection * modelview * position;\n"
"}\n";
const GLchar* f01 = // ShadeFullbright() ]- fragment shader
"#version 100\n"
"precision highp float;\n"
"varying vec3 vertCol;\n"
"varying float vertOpa;\n"
"void main()\n"
"{\n"
"gl_FragColor = vec4(vertCol, vertOpa);\n"
"}\n";
///
#ifdef VERTEX_SHADE // on to ! the fun stuff ;)
///
// solid color + normal array ]- vertex shader
const GLchar* v1 =
"#version 100\n"
"uniform mat4 modelview;\n"
"uniform mat4 projection;\n"
"uniform vec3 color;\n"
"uniform float ambient;\n"
"uniform float saturate;\n"
"uniform float opacity;\n"
"uniform vec3 lightpos;\n"
"attribute vec4 position;\n"
"attribute vec3 normal;\n"
"varying vec4 fragcolor;\n"
"void main()\n"
"{\n"
"vec4 vertPos4 = modelview * position;\n"
"vec3 vertNorm = normalize(vec3(modelview * vec4(normal, 0.0)));\n"
"vec3 lightDir = normalize(lightpos - (vertPos4.xyz / vertPos4.w));\n"
"fragcolor = vec4((color*ambient) + (color * min(max(dot(lightDir, vertNorm), 0.0), saturate)), opacity);\n"
"gl_Position = projection * vertPos4;\n"
"}\n";
// color array + normal array ]- vertex shader
const GLchar* v2 =
"#version 100\n"
"uniform mat4 modelview;\n"
"uniform mat4 projection;\n"
"uniform float ambient;\n"
"uniform float saturate;\n"
"uniform float opacity;\n"
"uniform vec3 lightpos;\n"
"attribute vec4 position;\n"
"attribute vec3 normal;\n"
"attribute vec3 color;\n"
"varying vec4 fragcolor;\n"
"void main()\n"
"{\n"
"vec4 vertPos4 = modelview * position;\n"
"vec3 vertNorm = normalize(vec3(modelview * vec4(normal, 0.0)));\n"
"vec3 lightDir = normalize(lightpos - (vertPos4.xyz / vertPos4.w));\n"
"fragcolor = vec4((color*ambient) + (color * min(max(dot(lightDir, vertNorm), 0.0), saturate)), opacity);\n"
"gl_Position = projection * vertPos4;\n"
"}\n";
const GLchar* f1 = // fragment shader
"#version 100\n"
"precision highp float;\n"
"varying vec4 fragcolor;\n"
"void main()\n"
"{\n"
"gl_FragColor = fragcolor;\n"
"}\n";
///
#else /////////////////////////////////////// PIXEL SHADED BELOW ///////////////////////////////////////
///
// solid color + normal array ]- vertex shader
const GLchar* v1 =
"#version 100\n"
"uniform mat4 modelview;\n"
"uniform mat4 projection;\n"
"uniform vec3 color;\n"
"uniform float ambient;\n"
"uniform float saturate;\n"
"uniform float opacity;\n"
"uniform vec3 lightpos;\n"
"attribute vec4 position;\n"
"attribute vec3 normal;\n"
"varying vec3 vertPos;\n"
"varying vec3 vertNorm;\n"
"varying vec3 vertCol;\n"
"varying float vertAmb;\n"
"varying float vertSat;\n"
"varying float vertOpa;\n"
"varying vec3 vlightPos;\n"
"void main()\n"
"{\n"
"vec4 vertPos4 = modelview * position;\n"
"vertPos = vertPos4.xyz / vertPos4.w;\n"
"vertNorm = vec3(modelview * vec4(normal, 0.0));\n"
"vertCol = color;\n"
"vertAmb = ambient;\n"
"vertSat = saturate;\n"
"vertOpa = opacity;\n"
"vlightPos = lightpos;\n"
"gl_Position = projection * vertPos4;\n"
"}\n";
// color array + normal array ]- vertex shader
const GLchar* v2 =
"#version 100\n"
"uniform mat4 modelview;\n"
"uniform mat4 projection;\n"
"uniform float ambient;\n"
"uniform float saturate;\n"
"uniform float opacity;\n"
"uniform vec3 lightpos;\n"
"attribute vec4 position;\n"
"attribute vec3 normal;\n"
"attribute vec3 color;\n"
"varying vec3 vertPos;\n"
"varying vec3 vertNorm;\n"
"varying vec3 vertCol;\n"
"varying float vertAmb;\n"
"varying float vertSat;\n"
"varying float vertOpa;\n"
"varying vec3 vlightPos;\n"
"void main()\n"
"{\n"
"vec4 vertPos4 = modelview * position;\n"
"vertPos = vertPos4.xyz / vertPos4.w;\n"
"vertNorm = vec3(modelview * vec4(normal, 0.0));\n"
"vertCol = color;\n"
"vertAmb = ambient;\n"
"vertSat = saturate;\n"
"vertOpa = opacity;\n"
"vlightPos = lightpos;\n"
"gl_Position = projection * vertPos4;\n"
"}\n";
const GLchar* f1 = // fragment shader
"#version 100\n"
"precision highp float;\n"
"varying vec3 vertPos;\n"
"varying vec3 vertNorm;\n"
"varying vec3 vertCol;\n"
"varying float vertAmb;\n"
"varying float vertSat;\n"
"varying float vertOpa;\n"
"varying vec3 vlightPos;\n"
"void main()\n"
"{\n"
"vec3 lightDir = normalize(vlightPos - vertPos);\n"
"float lambertian = min(max(dot(lightDir, normalize(vertNorm)), 0.0), vertSat);\n"
"gl_FragColor = vec4((vertCol*vertAmb) + (vertCol*lambertian), vertOpa);\n"
"}\n";
#endif
/// <><><> ///
GLuint shdFullbrightSolid;
GLint shdFullbrightSolid_position;
GLint shdFullbrightSolid_projection;
GLint shdFullbrightSolid_modelview;
GLint shdFullbrightSolid_color;
GLint shdFullbrightSolid_opacity;
GLuint shdFullbright;
GLint shdFullbright_position;
GLint shdFullbright_projection;
GLint shdFullbright_modelview;
GLint shdFullbright_color;
GLint shdFullbright_opacity;
GLuint shdLambertSolid;
GLint shdLambertSolid_position;
GLint shdLambertSolid_projection;
GLint shdLambertSolid_modelview;
GLint shdLambertSolid_lightpos;
GLint shdLambertSolid_color;
GLint shdLambertSolid_normal;
GLint shdLambertSolid_ambient;
GLint shdLambertSolid_saturate;
GLint shdLambertSolid_opacity;
GLuint shdLambert;
GLint shdLambert_position;
GLint shdLambert_projection;
GLint shdLambert_modelview;
GLint shdLambert_lightpos;
GLint shdLambert_color;
GLint shdLambert_normal;
GLint shdLambert_ambient;
GLint shdLambert_saturate;
GLint shdLambert_opacity;
/// <><><> ///
GLuint debugShader(GLuint shader_program)
{
GLint linked;
glGetProgramiv(shader_program, GL_LINK_STATUS, &linked);
if(linked == GL_FALSE)
{
GLint infoLen = 0;
glGetProgramiv(shader_program, GL_INFO_LOG_LENGTH, &infoLen);
if(infoLen > 1)
{
char* infoLog = malloc(sizeof(char) * infoLen);
if(infoLog != NULL)
{
glGetProgramInfoLog(shader_program, infoLen, NULL, infoLog);
printf("!!! error linking shader !!!\n%s\n", infoLog);
free(infoLog);
}
}
else
{
printf("!!! failed to link shader with no returned debug output !!!\n");
}
glDeleteProgram(shader_program);
return linked;
}
return linked;
}
/// <><><> ///
void makeFullbrightSolid()
{
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &v0, NULL);
glCompileShader(vertexShader);
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &f0, NULL);
glCompileShader(fragmentShader);
shdFullbrightSolid = glCreateProgram();
glAttachShader(shdFullbrightSolid, vertexShader);
glAttachShader(shdFullbrightSolid, fragmentShader);
glLinkProgram(shdFullbrightSolid);
if(debugShader(shdFullbrightSolid) == GL_FALSE){return;}
shdFullbrightSolid_position = glGetAttribLocation(shdFullbrightSolid, "position");
shdFullbrightSolid_projection = glGetUniformLocation(shdFullbrightSolid,"projection");
shdFullbrightSolid_modelview = glGetUniformLocation(shdFullbrightSolid, "modelview");
shdFullbrightSolid_color = glGetUniformLocation(shdFullbrightSolid, "color");
shdFullbrightSolid_opacity = glGetUniformLocation(shdFullbrightSolid, "opacity");
}
void makeFullbright()
{
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &v01, NULL);
glCompileShader(vertexShader);
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &f01, NULL);
glCompileShader(fragmentShader);
shdFullbright = glCreateProgram();
glAttachShader(shdFullbright, vertexShader);
glAttachShader(shdFullbright, fragmentShader);
glLinkProgram(shdFullbright);
if(debugShader(shdFullbright) == GL_FALSE){return;}
shdFullbright_position = glGetAttribLocation(shdFullbright, "position");
shdFullbright_color = glGetAttribLocation(shdFullbright, "color");
shdFullbright_projection = glGetUniformLocation(shdFullbright, "projection");
shdFullbright_modelview = glGetUniformLocation(shdFullbright, "modelview");
shdFullbright_opacity = glGetUniformLocation(shdFullbright, "opacity");
}
void makeLambertSolid()
{
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &v1, NULL);
glCompileShader(vertexShader);
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &f1, NULL);
glCompileShader(fragmentShader);
shdLambertSolid = glCreateProgram();
glAttachShader(shdLambertSolid, vertexShader);
glAttachShader(shdLambertSolid, fragmentShader);
glLinkProgram(shdLambertSolid);
if(debugShader(shdLambertSolid) == GL_FALSE){return;}
shdLambertSolid_position = glGetAttribLocation(shdLambertSolid, "position");
shdLambertSolid_normal = glGetAttribLocation(shdLambertSolid, "normal");
shdLambertSolid_projection = glGetUniformLocation(shdLambertSolid, "projection");
shdLambertSolid_modelview = glGetUniformLocation(shdLambertSolid, "modelview");
shdLambertSolid_lightpos = glGetUniformLocation(shdLambertSolid, "lightpos");
shdLambertSolid_color = glGetUniformLocation(shdLambertSolid, "color");
shdLambertSolid_ambient = glGetUniformLocation(shdLambertSolid, "ambient");
shdLambertSolid_saturate = glGetUniformLocation(shdLambertSolid, "saturate");
shdLambertSolid_opacity = glGetUniformLocation(shdLambertSolid, "opacity");
}
void makeLambert()
{
GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShader, 1, &v2, NULL);
glCompileShader(vertexShader);
GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShader, 1, &f1, NULL);
glCompileShader(fragmentShader);
shdLambert = glCreateProgram();
glAttachShader(shdLambert, vertexShader);
glAttachShader(shdLambert, fragmentShader);
glLinkProgram(shdLambert);
if(debugShader(shdLambert) == GL_FALSE){return;}
shdLambert_position = glGetAttribLocation(shdLambert, "position");
shdLambert_normal = glGetAttribLocation(shdLambert, "normal");
shdLambert_color = glGetAttribLocation(shdLambert, "color");
shdLambert_projection = glGetUniformLocation(shdLambert,"projection");
shdLambert_modelview = glGetUniformLocation(shdLambert, "modelview");
shdLambert_lightpos = glGetUniformLocation(shdLambert, "lightpos");
shdLambert_ambient = glGetUniformLocation(shdLambert, "ambient");\
shdLambert_saturate = glGetUniformLocation(shdLambert, "saturate");
shdLambert_opacity = glGetUniformLocation(shdLambert, "opacity");
}
/// <><><> ///
void makeAllShaders()
{
makeFullbrightSolid();
makeFullbright();
makeLambertSolid();
makeLambert();
}
/// <><><> ///
void shadeFullbrightSolid(GLint* position, GLint* projection, GLint* modelview, GLint* color, GLint* opacity)
{
*position = shdFullbrightSolid_position;
*projection = shdFullbrightSolid_projection;
*modelview = shdFullbrightSolid_modelview;
*color = shdFullbrightSolid_color;
*opacity = shdFullbrightSolid_opacity;
glUseProgram(shdFullbrightSolid);
}
void shadeFullbright(GLint* position, GLint* projection, GLint* modelview, GLint* color, GLint* opacity)
{
*position = shdFullbright_position;
*projection = shdFullbright_projection;
*modelview = shdFullbright_modelview;
*color = shdFullbright_color;
*opacity = shdFullbright_opacity;
glUseProgram(shdFullbright);
}
void shadeLambertSolid(GLint* position, GLint* projection, GLint* modelview, GLint* lightpos, GLint* normal, GLint* color, GLint* ambient, GLint* saturate, GLint* opacity)
{
*position = shdLambertSolid_position;
*projection = shdLambertSolid_projection;
*modelview = shdLambertSolid_modelview;
*lightpos = shdLambertSolid_lightpos;
*color = shdLambertSolid_color;
*normal = shdLambertSolid_normal;
*ambient = shdLambertSolid_ambient;
*saturate = shdLambertSolid_saturate;
*opacity = shdLambertSolid_opacity;
glUseProgram(shdLambertSolid);
}
void shadeLambert(GLint* position, GLint* projection, GLint* modelview, GLint* lightpos, GLint* normal, GLint* color, GLint* ambient, GLint* saturate, GLint* opacity)
{
*position = shdLambert_position;
*projection = shdLambert_projection;
*modelview = shdLambert_modelview;
*lightpos = shdLambert_lightpos;
*color = shdLambert_color;
*normal = shdLambert_normal;
*ambient = shdLambert_ambient;
*saturate = shdLambert_saturate;
*opacity = shdLambert_opacity;
glUseProgram(shdLambert);
}// <> / / /
/// <><><> ///
/// <><> ///
/// <> ///
//////`
#endif