Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: glutStrokeCharacter / gluPerspective

  1. #1
    Intern Newbie
    Join Date
    Apr 2001
    Posts
    36

    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

  2. #2
    Member Regular Contributor
    Join Date
    Oct 2001
    Location
    Princeton, NJ
    Posts
    391

    Re: glutStrokeCharacter / gluPerspective

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

  3. #3
    Intern Newbie
    Join Date
    Apr 2001
    Posts
    36

    Re: glutStrokeCharacter / gluPerspective

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

  4. #4
    Member Regular Contributor
    Join Date
    Oct 2001
    Location
    Princeton, NJ
    Posts
    391

    Re: glutStrokeCharacter / gluPerspective

    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

  5. #5
    Intern Newbie
    Join Date
    Apr 2001
    Posts
    36

    Re: glutStrokeCharacter / gluPerspective

    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

  6. #6
    Member Regular Contributor
    Join Date
    Oct 2001
    Location
    Princeton, NJ
    Posts
    391

    Re: glutStrokeCharacter / gluPerspective

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •