explicitly bind generic attribute locations
This commit is contained in:
parent
1371328c8b
commit
d3c509e966
@ -27,7 +27,10 @@ const GLushort indices[] = {
|
||||
0, 1, 2, 3, 4, 5
|
||||
};
|
||||
GLuint program, vs, fs, data_vbo, index_vbo;
|
||||
GLint pos_loc, color_loc;
|
||||
enum Locations {
|
||||
LOC_POSITION,
|
||||
LOC_COLOR
|
||||
};
|
||||
|
||||
char * loadFile(const char *fname)
|
||||
{
|
||||
@ -145,6 +148,10 @@ bool init(int width, int height)
|
||||
program = glCreateProgram();
|
||||
glAttachShader(program, vs);
|
||||
glAttachShader(program, fs);
|
||||
|
||||
glBindAttribLocation(program, LOC_POSITION, "pos");
|
||||
glBindAttribLocation(program, LOC_COLOR, "color");
|
||||
|
||||
glLinkProgram(program);
|
||||
|
||||
GLint link_status;
|
||||
@ -159,9 +166,6 @@ bool init(int width, int height)
|
||||
return false;
|
||||
}
|
||||
|
||||
pos_loc = glGetAttribLocation(program, "pos");
|
||||
color_loc = glGetAttribLocation(program, "color");
|
||||
|
||||
data_vbo = makeBuffer(GL_ARRAY_BUFFER, data, sizeof(data));
|
||||
index_vbo = makeBuffer(GL_ELEMENT_ARRAY_BUFFER, indices, sizeof(indices));
|
||||
|
||||
@ -173,14 +177,14 @@ void display(void)
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, data_vbo);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_vbo);
|
||||
glEnableVertexAttribArray(pos_loc);
|
||||
glEnableVertexAttribArray(color_loc);
|
||||
glVertexAttribPointer(pos_loc, 3, GL_FLOAT, GL_FALSE,
|
||||
glEnableVertexAttribArray(LOC_POSITION);
|
||||
glEnableVertexAttribArray(LOC_COLOR);
|
||||
glVertexAttribPointer(LOC_POSITION, 3, GL_FLOAT, GL_FALSE,
|
||||
STRIDE(&data[0], &data[1]), OFFSET(&data[0], &data[0][0]));
|
||||
glVertexAttribPointer(color_loc, 3, GL_FLOAT, GL_FALSE,
|
||||
glVertexAttribPointer(LOC_COLOR, 3, GL_FLOAT, GL_FALSE,
|
||||
STRIDE(&data[0], &data[1]), OFFSET(&data[0], &data[0][1]));
|
||||
glDrawElements(GL_TRIANGLES, sizeof(indices)/sizeof(indices[0]),
|
||||
GL_UNSIGNED_SHORT, STRIDE(&indices, &indices[0]));
|
||||
GL_UNSIGNED_SHORT, OFFSET(&indices, &indices[0]));
|
||||
SDL_GL_SwapBuffers();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user