🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Help understanding the transformations (lesson 43)

Started by
3 comments, last by Caste 16 years, 7 months ago
I followed lesson 43 to implement text in my opengl window but I am having some problems understand what the transformations are. More specifically, I don't always want the text to be in screen cords. I want to be able to render text at the 3d object... so if i draw a cube with its transformations, then render the text, i'd like to text to be moved to where the cube is. The tricky parts seems to be in how it pushes and pops attributes and I am not quite sure how this works. I would like to set it to ortho mode manually if i want to give it pixel cords, and have it use the existing projection mode otherwise. Is this possible? I had it working just with WGL fonts before and it was super simple... but with the complexity of whats going on here I am not quite sure how to approach this. Thanks for any info.
Advertisement
Do you want the text to resize when its further away or shall it stay the same size butjust move over the screen? Because these two options need different approaches.

The first one can be accomplished using Billboards(Quads always facing towards the camera), the second via gluUnproject (so you get the screen x and y coords of the cube and render the text at this position).

More information after you decided for one of those [smile]
I don't need to scale the text, i want to move the text to the position of the 3d objects.

The problem, is I only have the current matrix... ... take for example a solar system... i'd want to be able to label the planets and have the text there with each planet except in this case the text would always face the screen... ideas?

Thank you,
Aaron
If you want to have (always readable) text moving with objects, you want screen space coordinates of your 3D objects and draw screen space text near this position.
Have a look at Article 13 at NeHe...

Your problem is the other way round. Thats what gluProject is there for. It takes the position of your planet and the current Modelview and Projection matrix and returns the screen coordinates. You can use these to position your text.

GLint viewport[4];GLdouble modelview[16];GLdouble projection[16];GLfloat winX, winY, winZ;GLdouble posX, posY, posZ;glGetDoublev( GL_MODELVIEW_MATRIX, modelview );glGetDoublev( GL_PROJECTION_MATRIX, projection );glGetIntegerv( GL_VIEWPORT, viewport );//pos is the position of your modelgluProject(  posX, posY, posZ, modelview, projection, viewport, &winX, &winY, &winZ);


That should work for you

This topic is closed to new replies.

Advertisement