View Full Version : How do I use glVertexPointer?

01-04-2003, 06:16 AM
How do I use glVertexPointer?

01-04-2003, 07:58 AM
The vertex pointer will have to point to your home made vertex array. This array can be a 2D array (x elements long, 3 elements wide) to contain the vertices. Next you tell OpenGL to use that specific array, and then you draw the array.
Important is that you enable the right clientstates first.
You'll also need an INDEX ARRAY. This array will contain the order in which the indexes of the vertex array are given to the card. I haven't figured out a way NOT to use this though, so I keep on defining an Index array every time.

Example code:

glEnableClientState(GL_VERTEX_ARRAY); //enable vertex array
glEnableClientState(GL_NORMAL_ARRAY); //enable normal array
glEnableClientState(GL_TEXTURE_COORD_ARRAY); //enable texcoord array

glVertexPointer( 3, GL_FLOAT, 0, &vertexA[start]); //give vertex array to OGL
glTexCoordPointer( 2, GL_FLOAT, 0, &texcoordA[start]); //same with texcoord array
glNormalPointer( GL_FLOAT, 0, &normalA[start]); //and normal array

glDrawElements( GL_QUADS, len, GL_UNSIGNED_INT, indexA); //draw the whole set in one go

glDisableClientState(GL_VERTEX_ARRAY); //disable the client states again

I use this as reference when I tried to figure out how to use the vertex array: http://www.3dlabs.com/support/developer/GLmanpages/

01-07-2003, 11:23 PM
Is this faster than just traversing the array by your self and using glVertex?

01-08-2003, 02:01 AM
Depending on what you do, it can be anywherefrom a little to a lot faster.