GL_NORMAL_ARRAY and GL_TEXTURE_COORD_ARRAY

So, if I’m drawing objects with glVertexPointer(…), and I’d like to use the associated Normal and Texture functions.

But I can’t get my head around the ordering and packing of the latter functions:

Surely each single vertex can have multiple texture and normal coordinates?

So my question is, how do I pack my normal and texture arrays so that I can specify a normal for each vertex of every triangle? Or do these functions not support this arrangement?

Thanks in Advance,

  • Jorj

they do. for best performance (correct me someone if im wrong) you better pack all data into one array and later specify only the offset of the type in glPointer() call. also possible to have separate buffers for data but again afaik packed data gives best performance.

[b]struct Vertex {
float[3] pos;
float[3] normal;
float[2] st1; // tex0
float[2] st2; // tex1
};

glNormalPointer(GL_FLOAT,12,NULL);
glClientActiveTexture(GL_TEXTURE0);
glTexCoordPointer(2,GL_FLOAT,24,NULL);
glClientActiveTexture(GL_TEXTURE1);
glTexCoordPointer(2,GL_FLOAT,32,NULL);
glVertexPointer(3,GL_FLOAT,0,NULL);[/b]

Ok, thanks for your help.

  • Jorj

@NK47: Are you sure that should works? The stride parameter is the space between two consecutive data.
So the normal should be


glNormalPointer(GL_FLOAT,sizeof(GLfloat)*(2+2+3), arrayPointer+sizeof(GLfloat)*3);
glTexCoordPointer(2,GL_FLOAT,sizeof(GLfloat)*(2+3+3), arrayPointer+sizeof(GLfloat)*(3+3));
and so on...

where arrayPointer should be NULL if you are using VBO.

@NK47: Are you sure that should works? The stride parameter is the space between two consecutive data.
So the normal should be

_NK47 is right and was speaking about the last parameter. When you use a vbo this one, is an offset inside the vbo data. If you want to use the entire vbo data you set NULL.