PDA

View Full Version : how to change color



jyoung77
03-17-2003, 05:43 PM
Hi,

I insert the following piece code into a big program. The triangle is always black on one face (it's ok to me that the other face is invisible). If I enable the lighting, the triangle is grey and won't change color no matter how I adjust the color setting below. Do you know why? I want to be able to change its color. Thanks.

Tony

glDisable (GL_LIGHTING);
glBegin(GL_POLYGON);
glColor3d(.0, .0, .0);
glVertex3f(.0, 0., 0.);
glColor3d(1., .5, .0);
glVertex3f(1., 1., 1.);
glColor3d(.0, 1., .3);
glVertex3f(-1., -1., 1.);
glEnd();

nexusone
03-17-2003, 06:46 PM
When you use lighting you have to also include normals with your vertex.

Go to nehe.gamedev.net and look at the tutor on how to do normals.



Originally posted by jyoung77:
Hi,

I insert the following piece code into a big program. The triangle is always black on one face (it's ok to me that the other face is invisible). If I enable the lighting, the triangle is grey and won't change color no matter how I adjust the color setting below. Do you know why? I want to be able to change its color. Thanks.

Tony

glDisable (GL_LIGHTING);
glBegin(GL_POLYGON);
glColor3d(.0, .0, .0);
glVertex3f(.0, 0., 0.);
glColor3d(1., .5, .0);
glVertex3f(1., 1., 1.);
glColor3d(.0, 1., .3);
glVertex3f(-1., -1., 1.);
glEnd();

cbwan
03-18-2003, 04:06 AM
try adding this in your init :

glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);

cb