View Full Version : How to draw text that faces the viewer?

Kevin Killion
02-18-2011, 12:24 PM
I use the excellent TChart package for making presentation graphics in my app. For certain charts I want to do, using TChart's options for OpenGL are just beautifully superb.

BUT I mystified about how to draw text that faces the viewer, even if the chart itself is oblique or rotated or whatever. Here is an example of what I'm drawing:


I'd like to have the labels above the boxes (shown as "Hello" in this sample) face the viewer. As a possible workaround, I tried using TextOut and TextOut3D as well, drawing some sample text (also shown in this sample) in an "onAfterDraw" event. In all cases, the text "faces" whatever was "frontward" in the original coords, not towards the viewer.

This can't be this hard, can it? How do I draw text that faces the viewer?


02-18-2011, 12:53 PM
This is a TChart question, not an OpenGL question.

Kevin Killion
02-18-2011, 01:07 PM
Well, how would you do it in OpenGL?

02-18-2011, 02:11 PM
glrotated or glrotatef perhaps?

Perhaps calculating the angle between the direction the camera is pointing and the direction the text is pointing via dot product then do glrotated/f on the text?

In this case, the z doesn't even matter~

Rosario Leonardi
02-18-2011, 03:04 PM
2d way:
Compute the projection of the point in window coordinate and draw in 2d. Better quality, no filtering issues, better control of the size of the text, but the text will not be immersed in the scene will overwrite everything.

3d way:
The direction of the quad for the text should be exactly the opposite of the camera direction. You can compute the vertex point manually with a little of math, another way is to setup the model matrix of the object in a way that the rotation part of the model matrix must be the inverse of the rotation part of the camera matrix.