normals and vertex arrays

Started by
2 comments, last by TinyGameDev 17 years, 6 months ago
I've just tried for the first time to use vertex arrays and started by rendering a cube. What I'm wondering is, I now have 8 vertices for the cube...how can I compute the normals for them? The "normal" way of rendering a cube is with 6 polygons, 4 vertices each. Then I can set 4 normal for every polygon and that causes some vertices to have several normals. The gourad shading takes care of that, to my understanding, to create somewhat realistic lighting. How does this work when I use vertex arrays and I have only one vertex (and one normal) per corner? How should I calculate the normals to get the same lighting as before? Thanx for any replies

Making Terralysia, wishlist now on Steam <3!

Advertisement
If you're drawing them using indices, to cut down on the number of vertices, then you can't. One normal per vertex does not easily support cubes or angular shapes.

But you can draw all 6 sides by throwing all 24 vertices into the vertex array, then putting your associated normals into your normal array, ignoring an index array, or at least, make your index array point to the correct vertex AND normal comination. Cubes are the worst things to draw with arrays. :)
What I do is create 3 indices for every triangle in my model. Only the vertex xoords are shared, but the UVs and the normals will be different, so technically, they are not the same vertex.

So the size of all my arrays is number of triangles * 3, then glDrawArray can just work through it in order.
Ok, thanx guys for the replies. I thought it was gonna be inefficient in the long run to ignore indices if I use vertex arrays, but then again, I probably won't fill a world with cubes... =)

Making Terralysia, wishlist now on Steam <3!

This topic is closed to new replies.

Advertisement