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
|
0, 1, 2, 3, 4, 5
|
||||||
};
|
};
|
||||||
GLuint program, vs, fs, data_vbo, index_vbo;
|
GLuint program, vs, fs, data_vbo, index_vbo;
|
||||||
GLint pos_loc, color_loc;
|
enum Locations {
|
||||||
|
LOC_POSITION,
|
||||||
|
LOC_COLOR
|
||||||
|
};
|
||||||
|
|
||||||
char * loadFile(const char *fname)
|
char * loadFile(const char *fname)
|
||||||
{
|
{
|
||||||
@ -145,6 +148,10 @@ bool init(int width, int height)
|
|||||||
program = glCreateProgram();
|
program = glCreateProgram();
|
||||||
glAttachShader(program, vs);
|
glAttachShader(program, vs);
|
||||||
glAttachShader(program, fs);
|
glAttachShader(program, fs);
|
||||||
|
|
||||||
|
glBindAttribLocation(program, LOC_POSITION, "pos");
|
||||||
|
glBindAttribLocation(program, LOC_COLOR, "color");
|
||||||
|
|
||||||
glLinkProgram(program);
|
glLinkProgram(program);
|
||||||
|
|
||||||
GLint link_status;
|
GLint link_status;
|
||||||
@ -159,9 +166,6 @@ bool init(int width, int height)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos_loc = glGetAttribLocation(program, "pos");
|
|
||||||
color_loc = glGetAttribLocation(program, "color");
|
|
||||||
|
|
||||||
data_vbo = makeBuffer(GL_ARRAY_BUFFER, data, sizeof(data));
|
data_vbo = makeBuffer(GL_ARRAY_BUFFER, data, sizeof(data));
|
||||||
index_vbo = makeBuffer(GL_ELEMENT_ARRAY_BUFFER, indices, sizeof(indices));
|
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);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, data_vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, data_vbo);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_vbo);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_vbo);
|
||||||
glEnableVertexAttribArray(pos_loc);
|
glEnableVertexAttribArray(LOC_POSITION);
|
||||||
glEnableVertexAttribArray(color_loc);
|
glEnableVertexAttribArray(LOC_COLOR);
|
||||||
glVertexAttribPointer(pos_loc, 3, GL_FLOAT, GL_FALSE,
|
glVertexAttribPointer(LOC_POSITION, 3, GL_FLOAT, GL_FALSE,
|
||||||
STRIDE(&data[0], &data[1]), OFFSET(&data[0], &data[0][0]));
|
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]));
|
STRIDE(&data[0], &data[1]), OFFSET(&data[0], &data[0][1]));
|
||||||
glDrawElements(GL_TRIANGLES, sizeof(indices)/sizeof(indices[0]),
|
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();
|
SDL_GL_SwapBuffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user