Original Post
Hi Everyone, I'm having a problem getting glDrawElements (openGL) to render my vertex buffer objects. Would someone please take a look at what I'm doing and explain to me what I'm doing wrong? The code below works fine
GLfloat flt [] = { -1.0, 1.0, 0.0,
1.0, 1.0, 0.0,
-1.0, -1.0, 0.0
};
GLubyte indices [] = {
0, 2, 1
};
GLuint buffId;
glGenBuffers(1,&buffId);
glBindBuffer(GL_ARRAY_BUFFER, buffId);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*9, flt, GL_STATIC_DRAW);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, 0);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, indices);
glDeleteBuffers(1, &buffId);
However, when I put the indices into a buffer nothing happens. The program doesn't crash...It just gives me a perfectly rendered white screen! And glGetError says that there is not an error so what ever is happening is ignored by openGL.
GLfloat flt [] = { -1.0, 1.0, 0.0,
1.0, 1.0, 0.0,
-1.0, -1.0, 0.0
};
GLubyte indices [] = {
0, 2, 1
};
GLuint buffId;
GLuint buffIndexId;
glGenBuffers(1,&buffId);
glGenBuffers(1, &buffIndexId);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffIndexId);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLubyte)*3, indices, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, buffId);
glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat)*9, flt, GL_STATIC_DRAW);
glVertexPointer(3, GL_FLOAT, 0, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, 0);
glDeleteBuffers(1, &buffId);
glDeleteBuffers(1, &buffIndexId);
Can anyone see what I'm doing wrong? Thanks in advance [Edited by - mudrugger on March 9, 2009 4:36:48 AM]