3d Text & world vs. object coordinates

I’m working on a font engine and I’m having problems adjusting the text in the window using gluProject / gluUnProject and GetTextExtent().

For instance I want to center the text so I get the length of the text using GetTextExtent, get the size of the window with GetWindowRect and then use gluUnProject before adjusting the X offset of the text. I can’t seem to get it to work for all font sizes properly.

Any suggestions?

I am still having problems getting the text centered in the Window properly. Any help would be appreciated.

Pardon my ignorance, but why are you using Project/UnProject to render text? I’m not sure that I understand your question.

Tip: When a question goes unanswered for an extended period it almost invariably means that people don’t understand the question, and don’t feel like asking for a clarification. This is especially true in the advanced forum. :slight_smile:

wouldnt you just use an othographic view for text and then just set it up that 0 0 is middle of screen ?
then move the rectangle by half of its width along x and it should be centered.

Thanks for the response Portal. Actually what I really was using glUnProject for was to determine the width of the window in object coordinates to fully scroll the text off the screen. Is there a better way to do this? I’ve found a method for centering the text…

If you want text as overlay, you want to use glOrtho projection for the text. Note that it’s very common to switch projection several times during the drawing of a single frame, for this and other, similar, reasons.

Originally posted by GW:
Actually what I really was using glUnProject for was to determine the width of the window in object coordinates to fully scroll the text off the screen.
If by this you mean finding the most efficient way to cull 3D text poitioned in world space, then we might be getting somewhere. If this is the case, then I’m sure everyone will have a say. But I don’t want to proceed on a false assumption.

“If by this you mean finding the most efficient way to cull 3D text poitioned in world space”

This is exactly what I need. Sorry I have been out of OpenGL development for some time now and I have forgotten some of the terminology I needed to be more specific.

FYI I’m using font outlines, not overlay text. I used glyph metrics to center the text which seems to work nicely.

Portal or anyone else I would appreciate any input you could give me for proper culling of text in world space.

Okay, you might try using bounding spheres for the glyphs. Depending on the layout of your text, you may also want to take advantage of string groupings with an AABB or OBB. In any case, a quick test against the transformed view frustum should do the trick, or at least get you started.