White polygons

Hi, I’ve got a ‘little’ problem. Look at this code:

[b] glTranslatef(0,0,-12.0f);

for(int i=0; i<20;i++)
{
for(int j=0;j<20;j++)
{
glPushMatrix();
glTranslatef(i-10,j-10,-i*j*0.2);
glRotatef(aaa*40,1.0f,1.0f,0.0f);
glBegin(GL_TRIANGLES);
glColor3f(1-i*0.05f,1-j*0.05f,0.0f);
glNormal3f(0.0f,0.0f,1.0f);
glVertex3f(-1.0f,0.0f,0.0f);
glVertex3f(1.0f,0.0f,0.0f);
glVertex3f(0.0f,1.0f,0.0f);
glEnd();
glPopMatrix();
};
};

// glEnable(GL_LIGHTING);
glColorMaterial(GL_FRONT,GL_DIFFUSE);
glLoadIdentity();
… some polygons are drew later.[/b]

Is it wrote properly? I think yes, because polygons are shaded properly (before this code GL_COLOR_MATERIAL is enabled). But when I change the place where glColorMaterial() function is written to place before all this code, that means:

[b] glColorMaterial(GL_FRONT,GL_DIFFUSE);
glTranslatef(0,0,-12.0f);

for(int i=0; i<20;i++)
{

(…)
[/b]

All polygons are white. I don’t know why. It happens even when all code between old and new place for glColorMaterial() is in commentary:
[b]
glColorMaterial(GL_FRONT,GL_DIFFUSE);
/* glTranslatef(0,0,-12.0f);

for(int i=0; i<20;i++)
{
for(int j=0;j<20;j++)
{
glPushMatrix();
glTranslatef(i-10,j-10,-i*j*0.2);
glRotatef(aaa*40,1.0f,1.0f,0.0f);
glBegin(GL_TRIANGLES);
glColor3f(1-i*0.05f,1-j*0.05f,0.0f);
glNormal3f(0.0f,0.0f,1.0f);
glVertex3f(-1.0f,0.0f,0.0f);
glVertex3f(1.0f,0.0f,0.0f);
glVertex3f(0.0f,1.0f,0.0f);
glEnd();
glPopMatrix();
};
};*/

// glEnable(GL_LIGHTING);
glLoadIdentity();
[/b]

What can be wrong?

Hi !

glColor will set the color for the polygons as long as lighting is disabled (glDisable( GL_LIGHTING)), when you enable lighting the color set by glColor is no longer used, you must set the materials properties to get the polygon in correct color (glMaterialfv for example).

Mikael

But the colors are set properly! ( Isn’t glEnable(GL_COLOR_MATERIAL) enable using of glColor3f()?) The polygons are white only when I change thge location of glColorMaterial().

Correct me if I am worng, but glEnable(GL_COLOR_MATERIAL) makes that colors of all vertices can be set by glColorxx() functions, doesn’t it?

http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/

I think #14 may shed some light on your problem

Thanks

It helped me, but as I wrote- polygons were lighted properly, and only displacement of one funciton before commentary make it white - it is mystery for me. But thanks a lot.