PDA

View Full Version : Normals and textures with GL_TRIANGLE_STRIP



anuchka
08-27-2008, 03:52 AM
Hi

I'm trying to optimize terrain rendering by replacing GL_TRIANGLES
with GL_TRIANGLE_STRIP

1.Is following code correct for normal vector passing for 2 triangles built of 4 vertices - i.e does OpenGL automatically assign normals properly ?

2.The same question regarding texture coordinates?

//normal for first triangle
glNormal3fv(Triangles[iTri].fNorm);

glTexCoord2f(fTexx1,fTexy1);
glVertex3f(Vertices[iy][ix].fX,Vertices[iy][ix].fY,Vertices[iy][ix].fZ);

glTexCoord2f(fTexx2,fTexy1);
glVertex3f(Vertices[iy][ix+1].fX,Vertices[iy][ix+1].fY,Vertices[iy][ix+1].fZ);

glTexCoord2f(fTexx1,fTexy2);
glVertex3f(Vertices[iy+1][ix].fX,Vertices[iy+1][ix].fY,Vertices[iy+1][ix].fZ);

//normal for second triangle
glNormal3fv(Triangles[iTri+1].fNorm);

glTexCoord2f(fTexx2,fTexy2);
glVertex3f(Vertices[iy+1][ix+1].fX,Vertices[iy+1][ix+1].fY,Vertices[iy+1][ix+1].fZ);


Thanks



P.S. Sorry for off-topic - but is it possible to change a nickname? (or delete account ,because opening new requires different valid email?)

Zengar
08-27-2008, 06:25 AM
This is exactly how vertex attributes work in OpenGL. Imagine a set of registers, where each register holds a value. This values are attributes like normal, texcoord, color, etc. The corresponding commands just change the values in this registers, nothing more. And when a vertex is submitted, by calling glVertex, all the attribute values will be submitted along with it. With another words, if you set a normal (or another per-vertex attribute), it will be valid for all subsequent glVertex calls. Even more, you can use the same technique with vertex arrays.