Advertisement

Problem with text output

Started by September 03, 2000 09:11 AM
1 comment, last by bdenboer 24 years, 2 months ago
Hello everybody, Is it possible to write text to an OpenGL window just like it works with the TextOut() or DrawText() functions? I know TextOut() won''t work with double buffering, so I''m aware that I can''t use that function. I''ve read NeHe tutorials about text, but I don''t want to place the text in a "3D location". I just want it "overlaid" on the screen given the 2D coordinates. My problem with the 3D positioning is that it rotates along with other objects even when I disable the rotation for the text. The cause of this is most likely perpective correction. So is it possible to write text on the screen in a fixed position, no matter what happens to the 3D scene? Thanks! Bram
Of course!

You have not to ''disable'' rotation matrix: you have to load the right matrix !

Simply draw your text using an orthogonal projection matrix...for example after you have rendered your scene:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, screen_width, 0, screen_height);
// but you can use other screen coordinate mapping
// like gluOrtho2D(-1,1,-1,1)

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// draw bitmap-characters as textured quads using
// 2D screen coordinates
...


A suggestion : try separately texture mapping and quad positioning and then merge them together! And then add special effects like alpha_test/blend and color sum for color selection.
IpSeDiXiT
Advertisement
That worked!

But my framerate has dropped significantly after this, from 120fps to 100fps. This is probably due to the fact that switching from one matrix mode to the other takes up quite a bit of cpu time.
Isn''t there a way around this? I mean, to draw just one line I have to switch from matrix mode twice and after the text has been drawn, I need to switch back again to draw the next frame.

But anyway, thanks for your solution.

Greetz
Bram

This topic is closed to new replies.

Advertisement