Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: glOrtho: How can I MOVE my text

  1. #11
    Intern Contributor
    Join Date
    Nov 2002
    Posts
    98

    Re: glOrtho: How can I MOVE my text

    Originally posted by T:
    What is it you are trying to do? Place text just using 2D pixel coordinates or place text within a 3D scene.

    Why do you rotate the camera 180degrees?
    To the first point: I simply want to place some text with 2D coords. Nothing fancy really (exept that it's the first time I try this).

    To the second point: I'm making my first game to learn things like reflections: pong3D (no comments please), and I chose for that setup in the first place. I chose that the camera should look down to the positive Z.

  2. #12
    Guest

    Re: glOrtho: How can I MOVE my text

    Here's how I do it to get the text overlayed on the scene.

    /2D OVERLAY STUFF
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0,1,0,1); //coordinates are 0,0 to 1,1 in 2D
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glColor3f(1.0f,1.0f,1.0f); //color for text
    glRasterPos2f(0.02f,0.95f); //text position ( top leftish )
    glPrint("vPosition.x=%7.2f);

    //3D STUFF
    glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
    glLoadIdentity(); // Reset The Projection Matrix
    gluPerspective(45.0f,(GLfloat)1024/(GLfloat)768,0.1f,100.0f);
    glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
    glLoadIdentity();
    draw blah blah
    rotate blah blah
    translate blah blah

  3. #13
    Intern Contributor
    Join Date
    Nov 2002
    Posts
    98

    Re: glOrtho: How can I MOVE my text

    You rock!
    Both of you

    It works now with the gluOrtho2D (and with glORtho too now) and I have a slight idea of what went wrong.

    What eXor did (I think) in his example code is reset the GL_PROJECTION and GL_MODELVIEW both to the origin (swith to the one, load origin, to other, load origin). I missed the part where I set the projection to the origin.

    But what's beyond me is whether the projection and modelview matrix are actually two seperate matrices? I thought there was one view matrix, and that it was overwritten if you switched.

    I have to note this down:
    1) switch to projection matrix
    2) reset to origin
    3) switch to modelview matrix
    4) reset to origin

    Am I correct in this?

  4. #14
    Intern Newbie
    Join Date
    Jan 2003
    Location
    UK
    Posts
    44

    Re: glOrtho: How can I MOVE my text

    The projection and modelview matrices are separate matrices.

    Its more like:
    1. switch to projection
    2. reset to identity
    3. load a projection matrix (ortho or perspective)
    4. switch to modelview
    5. reset to identity
    6. do stuff

  5. #15
    Intern Newbie
    Join Date
    Jan 2003
    Location
    UK
    Posts
    44

    Re: glOrtho: How can I MOVE my text

    Oh, and remember that any matrix command always operates on the matrix you last "activated" (i.e. used in glMatrixMode).

  6. #16
    Guest

    Re: glOrtho: How can I MOVE my text

    ortho mode is 2D There is no depth ( z axis ) that's why the text doesn't move.

    Well it looks like its moving because when you move forward it's still there.

    You can't outrun it

  7. #17
    Intern Contributor
    Join Date
    Nov 2002
    Posts
    98

    Re: glOrtho: How can I MOVE my text

    Thanks people, I'm finally beginning to understand this ortho stuff, though I still have a long way to go.

Posting Permissions

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