Flat shading and vertex arrays

Started by
3 comments, last by zedz 15 years, 3 months ago
I want a flat shading effect in my game, where colours are assigned to each polygon instead of each vertex (I don't want any vertex colour blending). I know that flat shading is available, but the polygon colours can only be controlled by setting the colour for the right vertex in a polygon (either the first or last one; I don't remember). Since I'm loading/converting my models from files like OBJ, I'm not sure how much control over the final ordering of the vertices in each polygon I have. Also, I intend to use vertex arrays (probably switch to vertex buffer objects later) and as far as I can tell the colour arrays specify the colours for each vertex only. I'm also planning on using some basic shaders instead of OpenGL's built-in lighting and colouring model. Would this effect anything?
Advertisement
unless u use immediate mode
u will need to duplicate the vertices, ie have multiple vertex positions in the same place but each having a different normal
It's not possible

http://www.opengl.org/wiki/FAQ#Multi_indexed_rendering
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Well, in that case I guess I'll have duplicate vertices; each triangle has their own vertices, and each vertex of a triangle has the same normal.

The thing is that I'm going for a retro look, sort of like Darwinia, which is why I'm trying so hard to get the flat shading "right."

Though I guess I'll ask: say my models have 50 to 200 triangles. With the vertex duplication thing, I'll have to store 150 to 600 vertices. Would vertex arrays/VBOs still be faster than immediate mode (which wouldn't have duplicate vertices, and would let me keep a normal for each triangle instead of each vertex)?
yes most likely faster.

dont be afraid of duplicating vertices, most games even back in the quake2 days do it.
eg a quake2 model might have actual 300vertices but have 800 unique ones in the file,
its not just cause of normals but any data eg texture coordinates

This topic is closed to new replies.

Advertisement