PDA

View Full Version : Normals & strip triangles



Mao
05-27-2003, 02:05 AM
Hi ! http://192.48.159.181/discussion_boards/ubb/smile.gif
How should I define my table when I want to work with strip triangles with normales when I use glDrawElements ?
With simples triangles are there just 1 normal defined for just 1 vertex, but with strip ones it is much less vertex definied (we don't should repeating the defiinition for some vertices).
I have really no ideo of how does it works, have someone any example ?
M@o http://192.48.159.181/discussion_boards/ubb/smile.gif

cragwolf
05-27-2003, 12:49 PM
You have an array of vertices which you pass to glVertexPointer. So, you then must have a corresponding array of normals which you pass to glNormalPointer. Now when you call glDrawElements, the index array will not only pick out the correct vertices, but also the correct normals, assuming that the elements in the normals array are in the same order as the elements in the vertex array.

If you want to know how to calculate the normals, just ask.

Mao
05-27-2003, 11:12 PM
Originally posted by cragwolf:
You have an array of vertices which you pass to glVertexPointer. So, you then must have a corresponding array of normals which you pass to glNormalPointer. Now when you call glDrawElements, the index array will not only pick out the correct vertices, but also the correct normals, assuming that the elements in the normals array are in the same order as the elements in the vertex array.

If you want to know how to calculate the normals, just ask.


Does it works normals array for Triangles strip ? With glDrawElements too ?
How do U make with the average ? (smooth shading it is ?)

http://192.48.159.181/discussion_boards/ubb/wink.gif M@o

cragwolf
05-28-2003, 05:15 PM
Originally posted by Mao:
Does it works normals array for Triangles strip ? With glDrawElements too ?

Yes.


How do U make with the average ? (smooth shading it is ?)

I assume you already know how to calculate the normal for a triangle. For an array of triangle strips, the normal for a particular vertex can be calculated by averaging the normals for each of the 6 triangles surrounding the vertex. You could do:

normvert := (n1+n2+n3+n4+n5+n6)/6;

But a slightly better method is to weight each of the six surrounding normals by the angle their triangles make at the vertex. You can also preserve some edges if you like, especially if adjacent normals differ by too much.