GLuint setupShaders char vs NULL fs NULL fs2 NULL GLuint glCreateShade

 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
GLuint setupShaders() {
char *vs = NULL,*fs = NULL,*fs2 = NULL;
GLuint p,v,f;
v = glCreateShader(GL_VERTEX_SHADER);
f = glCreateShader(GL_FRAGMENT_SHADER);
vs = textFileRead(vertexFileName);
fs = textFileRead(fragmentFileName);
const char * vv = vs;
const char * ff = fs;
glShaderSource(v, 1, &vv,NULL);
glShaderSource(f, 1, &ff,NULL);
free(vs);free(fs);
glCompileShader(v);
glCompileShader(f);
printShaderInfoLog(v);
printShaderInfoLog(f);
p = glCreateProgram();
glAttachShader(p,v);
glAttachShader(p,f);
glBindFragDataLocation(p, 0, "output");
glBindAttribLocation(p,vertexLoc,"position");
glBindAttribLocation(p,normalLoc,"normal");
glBindAttribLocation(p,texCoordLoc,"texCoord");
glLinkProgram(p);
glValidateProgram(p);
printProgramInfoLog(p);
program = p;
vertexShader = v;
fragmentShader = f;
GLuint k = glGetUniformBlockIndex(p,"Matrices");
glUniformBlockBinding(p, k, matricesUniLoc);
glUniformBlockBinding(p, glGetUniformBlockIndex(p,"Material"), materialUniLoc);
texUnit = glGetUniformLocation(p,"texUnit");
return(p);
}