I don’t think it has to with floating point errors.
And I’m not complaining that the colors are wrong or off.
The shading is being done with OpenGL lighting and vertex
normals, not vertex colors. I guess the example I gave
above was a bad comparison.
I think it has to do with OpenGL not knowing that these
two triangles need to be shaded together, not by themselves.
What I am trying to say, the shading does not cross the
edge where these two triangles meet:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
FLOAT LightAmbient[4] = { 0,0,0,1 };
FLOAT LightDiffuse[4] = { 1,1,1,1 };
FLOAT LightPosition[4] = { 0,0,1,0 };
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT1);
glLightfv( GL_LIGHT1, GL_AMBIENT, LightAmbient );
glLightfv( GL_LIGHT1, GL_DIFFUSE, LightDiffuse );
glLightfv( GL_LIGHT1, GL_POSITION, LightPosition );
glEnable( GL_LIGHTING );
///////////////
glShadeModel( GL_SMOOTH );
glBegin(GL_TRIANGLES);
glVertex3f( -1, 1, 0 ); glNormal3f( -0.666667f, 0.666667f, 0.333333f );
glVertex3f( -1, -1, 0 ); glNormal3f( -0.408248f, -0.408248f, 0.816497f );
glVertex3f( 1, 1, 0 ); glNormal3f( 0.408248f, 0.408248f, 0.816497f );
glVertex3f( -1, -1, 0 ); glNormal3f( -0.408248f, -0.408248f, 0.816497f );
glVertex3f( 1, -1, 0 ); glNormal3f( 0.666667f, -0.666667f, 0.333333f );
glVertex3f( 1, 1, 0 ); glNormal3f( 0.408248f, 0.408248f, 0.816497f );
// etc...
glEnd();
This is supposed to be one plane of a box facing in the z+ direction.
The normal values are vertex normals for each vertex and were pre-computed
beforehand.
If dump this data directly into a vertex buffer, it shades correctly.
But if I try to render it triangle by triangle like above, it doesn’t.
And, I really must use GL_TRIANGLES.