Newbie problem with lighting

Hello All,

this will be simple for somebody who knows what their doing
I’ve got a scene with a torus in it drawn like this

private void buildScene(GL gl){
int i, j, k;
double s, t, x, y, z, twopi;
int numc = 18;
int numt = 18;

theTorus = gl.glGenLists (1);
gl.glNewList(theTorus, GL.GL_COMPILE);

gl.glColor3f(1.0f,0.5f,0.0f);
twopi = 2 * (double)M_PI;
for (i = 0; i < numc; i++) {
gl.glBegin(GL.GL_QUAD_STRIP);
for (j = 0; j <= numt; j++) {
for (k = 1; k >= 0; k–) {
s = (i + k) % numc + 0.5;
t = j % numt;

        x = (1+.1 * java.lang.Math.cos(s * twopi / numc)) * java.lang.Math.cos(t * twopi / numt);
        y = (1+.1*java.lang.Math.cos(s * twopi/numc)) * java.lang.Math.sin(t * twopi / numt);
        z = .1 * java.lang.Math.sin(s * twopi / numc);
        gl.glVertex3f((float)x, (float)y, (float)z);
     }
  }
  gl.glEnd();

}
gl.glEndList();
}
}

that draws an orange torus
if I try to use lighting like this

private void addLighting(GL gl){
float pos[] = { 0.0f, 0.0f, 10.0f, 1.0f };
float LightAmbient[]= { 1.0f, 0.0f, 0.0f, 1.0f };
float LightDiffuse[]= { 0.0f, 1.0f, 0.0f, 1.0f };
gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, pos);
gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, LightDiffuse);
gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION,LightAmbient);
gl.glEnable(GL.GL_CULL_FACE);
gl.glEnable(GL.GL_LIGHTING);
gl.glEnable(GL.GL_LIGHT0);
gl.glEnable(GL.GL_DEPTH_TEST);
}

the torus is drawn in whatever color the light is
for example a white light makes it white
shouldn’t white make it be orange??
what am I missing here??

Thanx
Dave

Hi,

I think, the OpenGL Lighting uses material-colors instead of vertex-colors. So you might want to take a look at glMaterial(…) or, if you want to keep using glColor to specify vertex-colors, try glColorMaterial that sets the material to track the vertex-color for diffuse(probably what you want) or specular or ambient.

Jan

yep, that’s it
thanx