How to draw 3d text

Started by
6 comments, last by superoptimo 14 years, 7 months ago
Hello all, I want to draw x, y and z axis labels in my surface plot. I can draw these labels using the glut library. But the problem is that when the plot is rotated the labels are not getting rotated. I know the reason that these labels are drawn in 2d. So that`s why I want to draw 3d text so that the labels can also be rotated along with the plot. Thanks for your help, Regards, Srinu
Advertisement
You could position your labels in 3D by specifying x,y,z coordinates (use your existing labels that you render in 2D). To make sure that they are facing in the correct direction so that they are readable, you want to billboard them: http://www.lighthouse3d.com/opengl/billboarding/

When you billboard an object you make sure that it is always facing the camera.
Hi mmakrzem,
Thanks for your reply. I tied billboarding but it did not come useful to my requirement.
Actually What my exact requirement is that - I have a 3d plot and 3 axes (x, y and z). The divisions on these axes are drawn using glut. But when the plot is rotated the text divisions are not. I think glut draws text in 2d format. If it is 3d text then the divisions are also get rotated. So, basically I need the divisions should also get rotated along with the plot.


~Srinu
You can obtain the 2D positions of the 3D objects, and draw the text at that position, using gluProject. Example:
GLdouble modelViewMatrix[16];GLdouble projMatrix[16];GLint viewport[4];GLdouble winx, winy, winz;glGetDoublev(GL_MODELVIEW_MATRIX, modelViewMatrix);glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);glGetIntegerv(GL_VIEWPORT, viewport);GLdouble winx, winy, winz;gluProject(	x3d,	y3d,	z3d,	modelViewMatrix,	projMatrix,	viewport,	&winx,	&winy,	&winz);drawTextAt(winx, winy);


EDIT: Not sure what you want exactly, do you want the text _position_ to be rotated to correctly align with the 3D point, or do you want the actual text to be rotated, so that the text is a 3D object that you can move around and see from different directions?
Hi Erik,
Thanks for the reply.
I am able to draw the text using the method you said. The text drawn in this way can be rotated? But I am not able to rotate the text.

TO all,
I am explaining my requirement once again with the image. Please look at the image at the following location.
http://upload.wikimedia.org/wikipedia/commons/archive/6/69/20070804225815!2D_Wavefunction_%282,2%29_Surface_Plot.png

I drawn the plot and axes same as in the above image. In this image the divisions or markings on the axes (0.0, 0.1, 0.2, 0.3, 0.4, etc....) can be rotated. Whereas in my image these can not be.
Simply, my requirement is that How to draw text which can be rotated? That is the actual text to be rotated, so that the text is a 3D object that we can move around and see from different directions.


Thanks,
Srinu

[Edited by - srinivaz111 on August 24, 2009 4:16:42 AM]
Can anyone please tell me a solution to do this

~Srinu
The easiest is probably to have your numbers in a texture, and draw them as textured quads along the axis.
There is also 3D fonts, check the following tutorial: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=14.
But Nehe is only Windows !!

There is an easy to use library for rendering 3D text in OpenGL, FTGL:
http://sourceforge.net/projects/ftgl/

It supports texture fonts, vector fonts and 3D polygonal fonts. MIT license.
Requires FreeType.

This topic is closed to new replies.

Advertisement