So whenever you render anything in OpenGL, sticking a glColor3f or 4f call in front of it will change it’s colour e.g:
@@glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_QUADS);
glVertex2f(0, 0);
glVertex2f(10, 0);
glVertex2f(10, 10);
glVertex2f(0, 10);
glEnd();
produces a red square.
In my buffer object class, I have a function to render to vbo:
public void render() {
if (editing)
throw new RuntimeException("Buffer is still being edited!");
if (hasTexture);
img.bindGLTexture();
if (useVBO) {
GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY);
GL11.glEnableClientState(GL11.GL_COLOR_ARRAY);
GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, ID);
GL11.glVertexPointer(3, GL11.GL_FLOAT, 4 * 8, 0);
GL11.glColorPointer(3, GL11.GL_FLOAT, 4 * 8, 4 * 3);
GL11.glTexCoordPointer(2, GL11.GL_FLOAT, 4 * 8, 4 * 6);
GL11.glDrawArrays(GL11.GL_QUADS, 0, vertexCount);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
GL11.glDisableClientState(GL11.GL_COLOR_ARRAY);
GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY);
} else {
GL11.glCallList(ID);
}
}
I recently discovered i cannot precede this with a glColor3f call to change the colour e.g:
BufferObject bo = new BufferObject();
//Generate object
@@glColor3f(1.0f, 0.0f, 0.0f);
bo.render();
will not work. Is there something I’m doing wrong to make this work? If not, how could I emulate an effect like this without having to make a seperate VBO for each colour?
(Please note, none of this code is copy and pasted so spelling or syntax errors are not the issue)
Thanks