glutStrokeCharacter / gluPerspective

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
Martin

why not just push the projection matrix, load an ortho view draw your text, then pop the matrix?

It’s will not affect the view/proportion of scene to swap between Perspective and Ortho ?

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

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

//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