PDA

View Full Version : glutStrokeCharacter / gluPerspective



Erakis
12-12-2001, 06:04 AM
The problem :
I want to put some text on my scene. If I choose a projection Ortho I can draw text well in my window even if it's resolution are 320x400 or 1024x768. But when I use a perspective projection, the position of the text change cause the perspective change...
I just want to ajust the text coord depend the size of the my windows. Is it possible to get the perspective dimension of my scene, depend the size of my windows, and also compute the righ position to draw the my text message ?

Ex :
_____________________________________________
I must get a proportionnal coord to draw the text at the correct position depend the size of the windows.
...
glTranslatef(-4.5, 3.6, -10.0);
glScalef(0.0015, 0.0015, 0.0015);
glColor4f( 0.0, 0.0, 1.0, 1.0 );
...
glutStrokeCharacter(GLUT_STROKE_ROMAN),
Text );
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ

A BIG BIG thanks http://www.opengl.org/discussion_boards/ubb/wink.gif
Martin

chowe6685
12-12-2001, 07:22 AM
why not just push the projection matrix, load an ortho view draw your text, then pop the matrix?

Erakis
12-12-2001, 08:04 AM
It's will not affect the view/proportion of scene to swap between Perspective and Ortho ?

chowe6685
12-12-2001, 10:45 AM
changing a matrix will only change primitives draw after the change, if you draw your scene with perspective, and then want to add text via ortho, you can just switch to an ortho projection and it will work fine

Erakis
12-13-2001, 05:44 AM
I've tried your tips but I'm not sure if I'm do it well ?
So I have to :
Activate the Projection matrix
Push it (so save it..)
Load a different type of projection (glOrtho)
Activate the Modelview matrix (To draw the text)
Move/Scale and draw my text
Reactivate the Projection matrix
Give it the old projection type (gluPerspective)
Pop the matrix (Reload this old one)
Activate the Modelview matrix to draw the rest of my scene....
__________________________________________________ ___________________________________
glMatrixMode( GL_PROJECTION );
glPushMatrix();
glOrtho( -5.0, 5.0, -5.0, 5.0, 0.1, 500.0 );

glMatrixMode( GL_MODELVIEW );
glTranslatef(-4.5, 3.6, -10.0);
glScalef(0.0015, 0.0015, 0.0015);
glColor4f( 1.0, 1.0, 1.0, 1.0 );

.....DRAW_THE_TEXT........

glMatrixMode( GL_PROJECTION );
gluPerspective( 45, ClientWidth / ClientHeight, 0.1, 500.0 );
glPopMatrix();

glMatrixMode( GL_MODELVIEW );
ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
Thanks in advance.
Martin http://www.opengl.org/discussion_boards/ubb/smile.gif

chowe6685
12-13-2001, 08:29 AM
//Make sure you have loaded the perspective matrix at this point
glMatrixMode( GL_PROJECTION );
glPushMatrix();
glOrtho( -5.0, 5.0, -5.0, 5.0, 0.1, 500.0 );

glMatrixMode( GL_MODELVIEW );
glTranslatef(-4.5, 3.6, -10.0);
glScalef(0.0015, 0.0015, 0.0015);
glColor4f( 1.0, 1.0, 1.0, 1.0 );

.....DRAW_THE_TEXT........
glMatrixMode( GL_PROJECTION );
gluPerspective( 45, ClientWidth / ClientHeight, 0.1, 500.0 ); //if you have already loaded the perspective matrix above this is unnecessary, just pop the matrix and it will return to a perspective projection
glPopMatrix();

glMatrixMode( GL_MODELVIEW );

what you have is correct, just look at my comments, you can probably eliminate the gluPerspective call, also, you may want to push the modelview matrix before transforming, then pop it later, otherwise the transformations you applied to the text will be applied to the rest of your scene