Archived

This topic is now archived and is closed to further replies.

glNormalPointer with Vertex Arrays

This topic is 5350 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I''m constructing a terrain and rendering it using glDrawElements, and I cannot get my lighting to work correctly. I have heard that if you use glNormalPointer you HAVE to have a normal for each vertex, but if I do that, the lighting will not be correct, since neighboring triangles share vertices, which means they''ll have to share normals, which means not good. My question is, is there a way to specify a normal for each ''triangle'' drawn, instead of each vertex?

Share on other sites
You need a normal per vertex... so you should have a packed array, vertex/normal/texcoord (or whatever the order is) then make that your interleaved array. You either have to repeat a lot of data and store it linearly without an index... or use an index array to draw from it (best option) this way, you can still define triangle strips, to send geometry potentially faster... and avoid repeating vertex/normal data.

Share on other sites
To get decent lighting each vertex needs it''s own normal, if just every triangle has it''s own normal you will see all the individual triagles that your mesh is made up of (unless it''s finely tessalated). To calulate the normal of a vertex average all the normals from the triangles to which the vertex belongs and then normalise the result. e.g. if a vertex is present in 3 triangles add together the x, y and z components of the normals for those 3 triangles then divide the x, y and z components by 3 then normalise the vector you have.

Share on other sites
You may also want to weight the average by the area of the triangles.... if a triangle is very small it should not contribute much to the normal....

Share on other sites
You may also want to weight the average by the area of the triangles.... if a triangle is very small it should not contribute much to the normal....

1. 1
Rutin
26
2. 2
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 20
• 14
• Forum Statistics

• Total Topics
632950
• Total Posts
3009382
• Who's Online (See full list)

There are no registered users currently online

×