Sign in to follow this  

glRasterPos2f- hopefully an easy question

This topic is 4023 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites

This topic is 4023 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this