PDA

View Full Version : drawing text in 2d in a 3d scene



BennUK
02-28-2004, 07:10 AM
Hi people, please help if you can.

I am working on a demo and have almost completed it, I just want to draw some 2d text to the screen and am not sure which order to do it in. My game starts, the camera transformations are made and then the world objects rendered. I have a function working which draws text to the screen (outputString) but it only works if I take all texturing and drawing out (possibly to do with the camera).

Any advice would be appreciated on how to tackle this problem.

Cheers

BennUK

nexusone
02-28-2004, 07:46 AM
You can turn off the texturing and lighting only for the text and draw it last.

example:

Draw_scene();
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glLoadIdentity(); // Just draw text without any camera transforms.
Draw_text();


[This message has been edited by nexusone (edited 02-28-2004).]

dvm
03-01-2004, 04:00 AM
Just to complement the previous post, I think you should include the above code in a glPushAttrib() - glPopAttrib() block, to make sure that the state of lighting etc. is saved. I'm not 100% sure but you might loose your modifications if you disable lighting and then reenable it (it would load again with default values). So include it in a push - pop block.

BennUK
03-01-2004, 04:51 AM
I have addded the folllowing code to the end of the program but all I get is a white screen - it seems that disabling the 2d textures does this but when I remove it, I still can't draw to the screen, aargh! There are 2 layers of textures being drawn and I need to draw the text on top of this (for the hud). Is it an order problem though I can't seem to write at the start or end of the program http://www.opengl.org/discussion_boards/ubb/frown.gif

glPushMatrix();
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glLoadIdentity();
text.drawTitle();
glPopMatrix();

Cheers

BennUK

[This message has been edited by BennUK (edited 03-01-2004).]

Nychold
03-01-2004, 06:49 AM
Are you re-enabling GL_TEXTURE_2D after you draw the text? ie:

glPushMatrix();
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glLoadIdentity();
text.drawTitle();
glPopMatrix();
//...
glEnable(GL_TEXTURE_2D);

In all honesty, I think moucard is right:

glPushMatrix();
glPushAttrib();
glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
glLoadIdentity();
text.drawTitle();
glPopAttrib();
glPopMatrix();

This seems the easiest solution to attempt. ^^