GL_BACK material properties.

Hi,

Thanks for helping me figure out the previous question about lighting.

I’m still having trouble giving the back side of polygons a color different from the front side. The same sphere (with fixed lighting!) with half the triangles missing so you can see through can be found.

http://www.geocities.com/bura3no/index.htm

The relevant code is here:

  gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, Color.GREEN.getComponents(null) );
  gl.glMaterialfv(GL.GL_BACK, GL.GL_AMBIENT_AND_DIFFUSE, Color.RED.getComponents(null) );

  gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_EMISSION, Color.BLACK.getComponents(null));

  gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, Color.WHITE.getComponents(null) );
  gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL);

  gl.glBegin(GL.GL_TRIANGLES);
  for (int t = 0; t < myMesh.pGetNumberOfElements()/2; t++) {
    Element elem = myMesh.pGetElement(t);
    for (int v = 0; v < elem.pGetNumberOfNodes(); v++) {
      VDouble x = myMesh.pGetX(elem.pGetNode(v));
      VDouble n = normals[elem.pGetNode(v)];
      gl.glNormal3d(n.pGet(0), n.pGet(1), n.pGet(2));
      gl.glVertex3d(x.pGet(0), x.pGet(1), x.pGet(2));
    }
  }
  gl.glEnd();

}

gl.glEndList();

At a first glance that render loop looks fine, so make sure you’re not culling the back-facing polygons and enable two-sided lighting:

GL.glDisable(GL.GL_CULL_FACE) ;
GL.glLightModeli(GL.GL_LIGHT_MODEL_TWO_SIDE, GL.GL_TRUE) ;

Thanks for response.

Your suggestion helped with lighting of the back side (something I did need), but not with the coloring. It’s still green rather than some other color.

Well, the code you’ve posted looks fine, as long as Color.RED really contains a red colour. How are the lights set up?

Not sure what to suggest… anyone else got any ideas?

Need more code.

Hi,

I would very much like to post more code, but I’m not quite sure what part of my program to quote. If I have

  gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, Color.GREEN.getComponents(null) ); 

and

  gl.glMaterialfv(GL.GL_BACK, GL.GL_AMBIENT_AND_DIFFUSE, Color.RED.getComponents(null) ); 

right next to each other and green works but red doesn’t, can you give me an idea of I might be doing wrong?

Thanks!

Pavel

Try removing gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, Color.GREEN.getComponents(null) ); and see what happens. Your code looks fine but obviously something is wrong.

EVERYTHING goes black.

Try reversing your colors, front red, back green. If everything turns red then we know it isn’t your color methods. What kind of graphics card do you have?

Yes, it all turns red.

I have a Mobility Fire GL 9000.
Chip type: Mobility Radeon 9000 (LF).

And here’s an interesting thing: When I switch to

  gl.glPolygonMode(GL.GL_FRONT, GL.GL_LINE);
  gl.glPolygonMode(GL.GL_BACK, GL.GL_FILL);

the program crashes with the following error message:

http://www.geocities.com/bura3no/error.txt

Try making a little c app that does the same type of lighting and see if you get the same results. If it is the same you might have found a driver bug.