PDA

View Full Version : 2D text in a 3D environment



Katun
11-07-2012, 12:51 PM
This may seem very simple, but I can't figure it out.
I'm using wglUseFontBitmaps to draw 2D text in a 2D overlay, kinda like a HUD in a 3D game.
Now I want to use the 2D text in the 3D environment. An object with a 3D coordinate should have a flat text with info about it straight above it.

Right now I use glRasterPos2f to position the text. I've messed with glRasterPos3f, gluPerspective, glOrtho, switched the matrix mode between GL_PROJECTION and GL_MODELVIEW, etc; either it shows nothing or it ignores the depth and just draws it like it does the HUD text.

Any ideas on how to tackle this?

tonyo_au
11-07-2012, 03:28 PM
Have a look at this
http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-11-2d-text/

Katun
11-09-2012, 05:33 AM
Sorry, that's not what I meant. That tutorial draws the text on top of the 3D environment, so the text itself is still in its 2D overlay environment. That's what I was doing already. I want to draw the text straight above an object in the 3D space. I basically just need the 2D screen coordinates (x, y) of the 3D object (not the (x, y) coordinates of the object in the 3D space).
How do I get those screen coordinates from a 3D space?

Katun
11-09-2012, 06:28 AM
Nvm, I found it:
http://msdn.microsoft.com/en-us/library/windows/desktop/dd368677(v=vs.85).aspx (http://msdn.microsoft.com/en-us/library/windows/desktop/dd368677(v=vs.85).aspx)

tonyo_au
11-09-2012, 06:44 PM
The samples on this site are for DirectX but a very easy to translate to OpenGL
http://www.angelcode.com/products/bmfont/