glRasterPos2f- hopefully an easy question

Started by
2 comments, last by Eitsch 17 years, 4 months ago
Hey all. This should be an easy question? glRasterPos2f(0.0f, 0.0f); glPrint("Hi Everyone"); Now at the moment the text starts being printed at 0.0f, whereas I want the text centered. Anyone know how to do that? Sorry to ask that question, for some reason never used bit-mapped fonts before :~/ Thanks [smile], John
Advertisement
the easy answer is magic number it over to where it is centered. the hard and robust answer: OpenGL does not support this and you have to make GDI calls (under Windows) to calculate your texts rectangle, then map that rectangle to your 2d projection coordinates in OpenGL.

the GDI function is DrawText, with a DT_CALC_RECT passed in IIRC
and the OpenGL function i typically use is gluOrtho2D (with the window size in pixels to map to pixelspace).
As your leader, I encourage you from time to time, and always in a respectful manner, to question my logic. If you're unconvinced that a particular plan of action I've decided is the wisest, tell me so, but allow me to convince you and I promise you right here and now, no subject will ever be taboo. Except, of course, the subject that was just under discussion. The price you pay for bringing up either my Chinese or American heritage as a negative is - I collect your f***ing head.
I was pondering over it today and an answer hit me and I felt a bit stupid afterwards. Just position the text at 0 - ((length of string) / 2). That should do it I think :)
if your text is not monospaced your idea won`t be accurate i think

This topic is closed to new replies.

Advertisement