I’m trying to render a lightened scene with textured and colored polygons. Rendering textured polygons works well, but colored polygons are all white. So I tryed to use GL_COLOR_MATERIAL to render my colored polygons. My render loop is like that:
The problem is, glDisable(GL_COLOR_MATERIAL) doesn’t work! The first frame is rendered correctly, but once GL_COLOR_MATERIAL has been enabled, I can’t disable it, so the next frames are incorrect (textured objects are no longer lit because GL_COLOR_MATERIAL is enabled).
If you try to use glColor to change the color of a polygon that will not work unless you disable lighting first (glDiable( GL_LIGHTING))
Could that be the reason for the white polygons.
glDisable( GL_COLOR_MATERIAL) only disables the tracking, the last used glColor will still be active for the last changed material, so you would need to reset this with a last glColor before disable GL_COLOR_MATERIAL, or better reset the material before you start rendering.
I use GL_COLOR_MATERIAL so my colored polygons are not white. The problem is that GL_COLOR_MATERIAL cancel the light effect on my textured polygons(probably because I didn’t set any material property on those). Ans disabling GL_COLOR_MATERIAL doesn’t change anything.
As for reseting the color to white, it makes my textured polygons have the right colors, but I still have no lighting on them.
Hope you understanf what I mean. Maybe I should just use material for everything, but then it would be slower I think.
I’m having the same problem with lighting on a textured polygon. I’ve created a texture map and have generated colors according to a contour color scheme I want. I’ve set up the texture, material and lighting properties then display it like this:
//needed here for blended shading model at each redraw
glShadeModel(GL_SMOOTH);
if(texture){
//uses predefined texture from setParams()
glBindTexture(GL_TEXTURE_2D, textures[1]);
//turns on texturing
glEnable(GL_TEXTURE_2D);
}
glEnable(GL_COLOR_MATERIAL);
//select the current color according to color scheme
if (colorScheme == DARK) glColor3f(0.25f,0.25f,0.25f);
if (colorScheme == LIGHT) glColor3f(0.8f,0.8f,0.8f);
if (colorScheme == MIDDLE) glColor3f(0.4f,0.4f,0.4f);
//draw "terrain" object then put texture on it
start = FSIZE/8;
end = FSIZE*7/8;
cent = float(FSIZE)/2.0f;
glPushMatrix();
glTranslatef(-cent,-cent,-10.5);
for(i=start;i<end;++i){
glBegin(GL_QUAD_STRIP);
for(j=start;j<end;++j){
//set the normals for the surface rendered
glNormal3f(normsX[i][j],normsY[i][j],normsZ[i][j]);
//sets the current texture coordinates
glTexCoord2f(field[i][j]*b + a, field[i][j]*b + a);
//vertex to be rendered
glVertex3f(float(i),float(j),field[i][j]);
//repeat
glNormal3f(normsX[i+1][j],normsY[i+1][j],normsZ[i+1][j]);
glTexCoord2f(field[i+1][j]*b + a, field[i+1][j]*b + a);
glVertex3f(float(i+1),float(j),field[i+1][j]);
}
glEnd();
}
glDisable(GL_TEXTURE_2D);
This all works fine! My problem is that when I try to change the RGB values for the texture so the glColor3f that I use can be
glColor3f(1.0f,1.0f,1.0f);
I loose the specular highlighting. Can you, or anyone explain why? And how can I get the highlighting back if I want to keep the glColor3f values all 1.0? -I assumed that the glColor values would just be a percentage of the texture color values, which would mean there should be a way for me to set the numbers up so I wouldn’t have to give a specific percentage value when calling glColor3f THANKS