views:

42

answers:

2

I'm successfully displaying text in OpenGL:

    GLUT glut = new GLUT();
    gl.glWindowPos2d(10, 20);
    glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, DISPLAYED_TEXT);

However, I'm not sure how to set the color. (I can see the color changing as I move the camera around, looking at different models, but I'm not sure what causes it to change.)

I'm using JOGL.

How do I specify the color I want?

A: 

Do you have any lighting setup? That can cause the colour to change.

Steven
+1  A: 

To set the color, use a glColor call (for example, glColor3f(1.0, 1.0, 0.0) to set the color to yellow) One thing to watch out for is that glutBitmapString uses raster graphics to render text, which has a few quirks. In particular, you need to set the color before you set the position - i.e.:

gl.glColor3f(1,0,0) # RED
gl.glWindowPos2d(10, 20);
gl.glColor3f(0,0,1) # BLUE
glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, DISPLAYED_TEXT);

will render the text in red, even though it looks like it should be rendered in blue.

Lighting will also affect the color, as Steven pointed out. If you are using lighting, it is best to turn it off temporarily while you draw text.

Matthew Hall