Sign in to follow this  
John_23

glRasterPos2f- hopefully an easy question

Recommended Posts

John_23    200
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
anist    100
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
John_23    200
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

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