Flat rendering with index arrays?

Hi,

How do you force flat rendering when using vertex arrays?

I mean, how do you assign a normal for each face using for example glDrawElements, without decreasing performance?

Thanks,

Billy.

[This message has been edited by billy (edited 07-11-2002).]

glShadeModel(GL_FLAT) maybe?

Anyways, shared vertex with more than one normal must be duplicated.

That’s the problem. I want to avoid sending duplicate vertices to the rendering buffer.

Either duplicate, or… or… use something other than vertex arrays. Since you can’t have different indices for different arrays, you can’t use more than one normal per vertex.

Now, the alternatives you have, immediate more rendering or display lists, all have their pros and cons. Display lists can be faster than vertex arrays, but are static. Immediate more is the by far most flexible, but can be as slow as it’s flexible. Vertex arrays can be seen as a mixture of immediate mode and display lists.

Given what OpenGL provides, you make a choise. Given that OpenGL doesn’t privide exactly what you want, you make some compromises; duplicate a few vertices.

The performance hit of sending a few more vertices, the duplicated ones, if far less that moving to immediate mode rendering without the need of duplicating.

[This message has been edited by Bob (edited 07-11-2002).]

You can’t.
Generate your normals like this:-
for every triangle defined in your indices array…
calculate the surface normal

then, for every triangle in your indices array…
check the 3 neighbouring triangles’ surface normals against ‘this’ triangles’ surface normal - if the dot product between ‘this’ surface normal and the neighbour surface normal is less than a certain threshold (such as 0.75), then you’ll have to create two more vertices for the edge they share, assign the surface normal to those new vertices, and assign the neighbours surface normal to its vertices. This will give you a hard edge where two connected faces are at an accute angle to each other, while still keeping the majority of your vertices shared.
Maybe there isn’t enough detail for you, but you get the jist?

…I’ve run out of steam…

Thanks knackered.