开发者

OpenGL: Set text color?

开发者 https://www.devze.com 2023-01-18 12:47 出处:网络
I\'m successfully displaying text in OpenGL: GLUT glut = new GLUT(); gl.glWindowPos2d(10, 20); glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, DISPLAYED_TEXT);

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 differ开发者_JAVA百科ent models, but I'm not sure what causes it to change.)

I'm using JOGL.

How do I specify the color I want?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号