Advertisement

glDrawElements question???

Started by March 10, 2003 12:42 AM
2 comments, last by dnagcat 21 years, 8 months ago
I only started with openGL this weekend so my knowledge is quit a stretch...anyway Im reading OpenGL Programming Guide and have gotten to the function glDrawElements...from what I can tell the book says it is like writing
    
glBegin(mode);
for(int i=0; i<count; i++)
     glArrayElement(indices[i]);
glEnd();
  
so I wrote this but it doesn't do anything...can anyone help..
  
void display()
{
	
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0, 1.0, 1.0);

	GLubyte indices[] = 
	{
		4, 5, 6, 7, 1, 2, 6, 5,
		0, 1, 5, 4, 0, 3, 2, 1,
		0, 4, 7, 3, 2, 3, 7, 6
	};

	glEnableClientState(GL_VERTEX_ARRAY);				//specifies array to enable

	glVertexPointer(4, GL_UNSIGNED_BYTE, 0, indices);
	

	glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, indices);
	glFlush();
}
         
[edited by - dnagcat on March 10, 2003 1:49:29 AM]
Your vertex pointer needs to be an array of the actual vertices while your index array should be an array of INDEXes into the vertex array.
Advertisement
so are you saying I''m using the wrong pointer?
quote:
glVertexPointer(4, GL_UNSIGNED_BYTE, 0, indices);

You''re telling OpenGL to use your index array as vertex array. Meaning, it will use the index array to get the vertex data. In this case, OpenGL will think the first vertex in the array has the coordinate (x,y,z,w)=(4,5,6,7), the second vertex has coordinate (1,2,6,5), and so on.

What you need to do is to create a second array which holds the vertices. A quick look in the index arrays tells me you''re trying to draw a cube, and if so, you should have an array of vertices with the coordinates of the 8 corners of the cube.

This topic is closed to new replies.

Advertisement