View Full Version : Displaying text - little problem
04-14-2000, 11:18 AM
Ok suppose I have this function:
Now,in my main renedering loop I'd write
The text is drawn but it it sort of stays at the origin.I want the text to be drawn,say, at the top left corner of my screen and it STAYS there when I move the camera around in 3D space. Any suggestions? Or does anyone have any text functions they can give me instead? Mine is a bit messy http://www.opengl.org/discussion_boards/ubb/smile.gif Some simple function like glText(LPCTSTR MyText,int x,int y) sould be nice. I'm still trying to get this whole no-2D issue in OpenGL solved http://www.opengl.org/discussion_boards/ubb/frown.gif
change the raster pos coordinates.
0,0 is the middle of your screen and the corner are the size of frustum boundaries(if this a word in english http://www.opengl.org/discussion_boards/ubb/smile.gif)
04-14-2000, 12:10 PM
Oh I have.That's not the problem because after you move the camera around in the 3D world the text sort of "stays" at that 3D point in the world.So when I rotate the camera to the left,the text moves to the right.Get what I mean?
04-14-2000, 12:57 PM
Hi Gecko (we meet again...)
1) Push an orthographic matrix onto the projection matrix stack.
2) Push an identity matrix onto the modelview stack.
3) Draw your text.
4) Pop both matrices.
I wouldn't recommend putting the matrix stuff inside the DrawText function; if you were drawing more than one string you'd get a lot of unnecessary duplication.
Generally speaking, most 2D work in screen space can be done very easily with this combination of ortho projection and identity modelview. Plus, many drivers will detect that you're using an identity matrix and optimize away the transform step.
i have written a text class wich is very simple to use: it uses textured fonts and it don't need nothing else.
plus, you'll get a general image load/save class.
do you want it?
04-14-2000, 03:12 PM
Thanx for the help MikeC.I'll try that today. And yes dmy,send me your code.I'd also like to take a look at that as well.
Thanx for the help.
04-15-2000, 12:22 PM
... and if you would have problems with the other solutions given you may also want to try my Enter2d() and Exit2d() functions which simpifies things a little.
04-15-2000, 01:15 PM
Sure! Send that to me as well! The more 2D functions I get the less problems I have with OpenGL! http://www.opengl.org/discussion_boards/ubb/smile.gif
04-15-2000, 02:44 PM
After calling Enter2d() your upper left corner is at (0,0) and the lower right corner is (1,1). So you can use the glVertex2f( ... ) function to specify 2d coords. After calling Exit2d() the previous state is set back again.
[This message has been edited by Humus (edited 04-15-2000).]
04-15-2000, 05:05 PM
Kewl! That just about takes care of my fake 2D problems.
Check out my OpenGl terrain engine at:
Tell me what you think.
Thanx again for the help guys.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.