PDA

View Full Version : Problem about glDrawElements()



miglinda
08-07-2010, 10:26 AM
My Code can't Draw a quadrilateral.but,I'can't find any erro in My Code as follow.please Help me thanks!

int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity();
glTranslatef(0.0f,0.0f,-6.0f); static GLubyte points[] = {
0,0,0,
1,0,0,
1,1,0,
0,1,0

};

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,0,(GLfloat *)points);
glDrawElements(GL_QUADS,12,GL_UNSIGNED_BYTE,points );
return TRUE;
}

Jacek Nowak
08-07-2010, 01:59 PM
Read the documentation related to glDrawElements. It requires an index array, which you aren't providing. If you don't want to use indices, glDrawArrays is the way to go, like this:

glDrawArrays(GL_QUADS, 0, 4);

also, points[] should be of type GLfloat, not GLubyte, since the second parameter of glVertexPointer is set to GL_FLOAT

miglinda
08-07-2010, 09:12 PM
Thank you , I have resolved this problem . I could't understand the countent about glDrawElements() in OpenGL ProgramingGuid