PDA

View Full Version : vertex buffer arrays, one normal per polygon?



bensmith87
04-09-2008, 03:30 PM
Hey all,
I'm programming this little benchmark for linux to test out the different methods of precompiling the vertex data.
I'm rendering bunch of cubes to the screen, and each face on the cube has only one normal.
I want to draw them using vertex buffer arrays, so far my code looks like the following, it is obviously wrong, as it will be looking for a normal for each vertex, and runs out of data, as well as the normals being all screwed up.


cube_mesh.vertex_qty = VertexQty;
cube_mesh.vertex = malloc(VertexQty * 3 * sizeof(float));
cube_mesh.texture = malloc(VertexQty * 2 * sizeof(float));
cube_mesh.normal = malloc(VertexQty / 4 * 3 * sizeof(float));

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);

glVertexPointer(3, GL_FLOAT, 0, cube_mesh.vertex);
glNormalPointer(GL_FLOAT, 0, cube_mesh.normal);
glDrawArrays(GL_QUADS, 0, cube_mesh.vertex_qty);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);

So, it will render, but not what I want.
Is there anything I can do?

Thanks in advance

zed
04-09-2008, 03:51 PM
not really u will have to supply the same normal to multiple verts so theres a 1:1 mapping
eg for a flat shaded cube instead of 8 vertices u will need to make 24

if u use immediate mode though u can get around this
glNormal(..)
glVertex(..) // will use current normal
glVertex(..) // will use current normal
glVertex(..) // will use current normal

bensmith87
04-09-2008, 04:21 PM
Thanks, thats what I thought.