keep text on the screen stationary
Ok I'm feeling really stupid. I think I must be missing out on some general opengl concepts b/c I can't figure this out.
I'm trying to create a HUD of sorts and am drawing text to the screen with glutBitmapCharacter. But when I rotate the camera the text is moving..arr!
This is what I have:
draw_text( x, y, text )
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, height, 0, width, near, far );
glRasterPos2f(x,y);
for(...)
{
glutBitMapCharacter( font, text);
}
glPopMatrix();
}
When I zoom in/out the text stays put, but if I rotate the camera or slide left/right the text moves.
The process is called billboarding:
http://www.lighthouse3d.com/opengl/billboarding/index.php3?billCheat
Cheers,
- llvllatrix
http://www.lighthouse3d.com/opengl/billboarding/index.php3?billCheat
Cheers,
- llvllatrix
Well your on the right track, but your missing the modelview matrix, the matrix that does all the rotation of the models.
you have
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, height, 0, width, near, far );
The function i use is as follows
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho( 0, x , y , 0, -1, 1 );
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
take a guess on how to use it.
and then to go back you do this
glMatrixMode( GL_PROJECTION );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );
glPopMatrix();
And no llvllatrix, this is not a billboarding problem.
you have
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, height, 0, width, near, far );
The function i use is as follows
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho( 0, x , y , 0, -1, 1 );
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
take a guess on how to use it.
and then to go back you do this
glMatrixMode( GL_PROJECTION );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );
glPopMatrix();
And no llvllatrix, this is not a billboarding problem.
www.flashbang.se | www.thegeekstate.com | nehe.gamedev.net | glAux fix for lesson 6 | [twitter]thegeekstate[/twitter]
Woot! Thankou lc_overlord.
Although to be honest I don't understand why it works. Is there a reason why PROJECTION is done before setting glOrtho, and then MODELVIEW is done next?
Although to be honest I don't understand why it works. Is there a reason why PROJECTION is done before setting glOrtho, and then MODELVIEW is done next?
I don't know.
The most important thing would be to clear the GL_PROJECTION matrix with glLoadIdentity before calling glOrtho (and not the other way around), since otherwise that action would be cleared by glLoadIdentity.
other than that im uncertain, it works this way and im not about to mess with it, you could try and switch places with them if you want (allso switch places in the return function as well).
The most important thing would be to clear the GL_PROJECTION matrix with glLoadIdentity before calling glOrtho (and not the other way around), since otherwise that action would be cleared by glLoadIdentity.
other than that im uncertain, it works this way and im not about to mess with it, you could try and switch places with them if you want (allso switch places in the return function as well).
www.flashbang.se | www.thegeekstate.com | nehe.gamedev.net | glAux fix for lesson 6 | [twitter]thegeekstate[/twitter]
Quote:
And no llvllatrix, this is not a billboarding problem.
lol, sry. I read camera and rotation and immediately thought billboarding. If you want text to move in 3space while still being orientated towards the camera, then you use billboarding.
Quote:
Is there a reason why PROJECTION is done before setting glOrtho, and then MODELVIEW is done next?
OpenGL uses two sets of matrices to calculate the final position of a graphic on the screen. Whatever you draw is first multiplied by the MODELVIEW matrix. This orients your object within the virtual space of your environment. For example, if you had a virtual city and said one square unit is a city block, then you could place a building within a block by translating it accoring to this virtual length (since the block is 1.0 x 1.0 units then your translation would be less than 1.0 units to position the building within the block).
What you have drawn then gets multiplied by the PROJECTION matrix. The PROJECTION matrix maps the virtual units of the environment to the screen units of the monitor. This is why the Ortho command accepts height and width as parameters. It is important to note that both height and width are also "virtual". That is, their values are not the actual dimentions of the monitor (ie 1024 x 768). Instead, they are the virtual representations of the width and height of the monitor. For example, using our city anology, if we used the command
glOrtho(0, 1.0, 0, 1.0, 0.0, 1.0 ); Then we are telling OpenGL to make the virtual width and height of our monitor the size of one city block. The result; we will have to zoom into our city before we begin to see people.
Hope this helps,
- llvllatrix
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement