Java – OpenGL – Unable to render colors other than white after texture mapping

java, jogl, opengl

I'm trying to render a colored cube after rendering other cubes that have textures. I have multiple "Drawer" objects that conform to the Drawer interface, and I pass each a reference to the GL object to the draw( final GL gl ) method of each individual implementing class. However, no matter what I do, I seem unable to render a colored cube.

Code sample:

gl.glDisable(GL.GL_TEXTURE_2D);gl.glColor3f( 1f, 0f, 0f );gl.glBegin(GL.GL_QUADS);// Front FacePoint3f point = player.getPosition();gl.glNormal3f(0.0f, 0.0f, 1.0f);//gl.glTexCoord2f(0.0f, 0.0f);gl.glVertex3f(-point.x - 1.0f, -1.0f, -point.z + 1.0f);//gl.glTexCoord2f(1.0f, 0.0f);gl.glVertex3f(-point.x + 1.0f, -1.0f, -point.z + 1.0f);//continue rendering rest of cube. ...gl.glEnd();gl.glEnable(GL.GL_TEXTURE_2D);

I've also tried throwing the glColor3f calls before each vertex call, but that still gives me a white cube. What's up?

Best Solution

There are a few things you need to make sure you do.

First off:

gl.glEnable(gl.GL_COLOR_MATERIAL);

This will let you apply colors to your vertices. (Do this before your calls to glColor3f.)

If this still does not resolve the problem, ensure that you are using blending properly (if you're using blending at all.)

For most applications, you'll probably want to use

gl.glEnable(gl.GL_BLEND);gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE_MINUS_SRC_ALPHA);

If neither of these things solve your problem, you might have to give us some more information about what you're doing/setting up prior to this section of your code.