PDA

View Full Version : White polygons



eror
03-19-2004, 11:52 AM
Hi, I've got a 'little' problem. Look at this code:

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.

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:

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

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


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:

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();


What can be wrong?

mikael_aronsson
03-19-2004, 12:27 PM
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

eror
03-19-2004, 02:55 PM
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?

chowe6685
03-19-2004, 05:13 PM
http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/

I think #14 may shed some light on your problem

eror
03-22-2004, 02:29 PM
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.