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 10 of 10

Thread: Displaying text - little problem

  1. #1
    Junior Member Regular Contributor
    Join Date
    Apr 2000
    Location
    Thunder Bay,ON,Canada
    Posts
    135

    Displaying text - little problem

    Hey all!

    Ok suppose I have this function:

    glDrawText(LPCTSTR Text)

    Now,in my main renedering loop I'd write

    glRasterPos(1.0f,1.0f);
    glDrawText("Hello");

    The text is drawn but it it sort of stays at the origin.I want the text to be drawn,say, at the top left corner of my screen and it STAYS there when I move the camera around in 3D space. Any suggestions? Or does anyone have any text functions they can give me instead? Mine is a bit messy Some simple function like glText(LPCTSTR MyText,int x,int y) sould be nice. I'm still trying to get this whole no-2D issue in OpenGL solved
    -------------------------
    "Bad bad programmer! No Mountain Dew for you!"

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Feb 2000
    Posts
    569

    Re: Displaying text - little problem

    change the raster pos coordinates.

    0,0 is the middle of your screen and the corner are the size of frustum boundaries(if this a word in english )

  3. #3
    Junior Member Regular Contributor
    Join Date
    Apr 2000
    Location
    Thunder Bay,ON,Canada
    Posts
    135

    Re: Displaying text - little problem

    Oh I have.That's not the problem because after you move the camera around in the 3D world the text sort of "stays" at that 3D point in the world.So when I rotate the camera to the left,the text moves to the right.Get what I mean?
    -------------------------
    "Bad bad programmer! No Mountain Dew for you!"

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    London
    Posts
    503

    Re: Displaying text - little problem

    Hi Gecko (we meet again...)

    Simple enough.

    1) Push an orthographic matrix onto the projection matrix stack.

    2) Push an identity matrix onto the modelview stack.

    3) Draw your text.

    4) Pop both matrices.

    I wouldn't recommend putting the matrix stuff inside the DrawText function; if you were drawing more than one string you'd get a lot of unnecessary duplication.

    Generally speaking, most 2D work in screen space can be done very easily with this combination of ortho projection and identity modelview. Plus, many drivers will detect that you're using an identity matrix and optimize away the transform step.

  5. #5
    Member Regular Contributor
    Join Date
    Feb 2000
    Location
    milano, italy
    Posts
    282

    Re: Displaying text - little problem

    i have written a text class wich is very simple to use: it uses textured fonts and it don't need nothing else.

    plus, you'll get a general image load/save class.

    do you want it?

    Dolo/\/\ightY
    Dolo/\/\ightY

  6. #6
    Junior Member Regular Contributor
    Join Date
    Apr 2000
    Location
    Thunder Bay,ON,Canada
    Posts
    135

    Re: Displaying text - little problem

    Thanx for the help MikeC.I'll try that today. And yes dmy,send me your code.I'd also like to take a look at that as well.

    Thanx for the help.
    -------------------------
    "Bad bad programmer! No Mountain Dew for you!"

  7. #7
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,345

    Re: Displaying text - little problem

    ... and if you would have problems with the other solutions given you may also want to try my Enter2d() and Exit2d() functions which simpifies things a little.

  8. #8
    Junior Member Regular Contributor
    Join Date
    Apr 2000
    Location
    Thunder Bay,ON,Canada
    Posts
    135

    Re: Displaying text - little problem

    Sure! Send that to me as well! The more 2D functions I get the less problems I have with OpenGL!
    -------------------------
    "Bad bad programmer! No Mountain Dew for you!"

  9. #9
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,345

    Re: Displaying text - little problem

    void Enter2dMode(){
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0,1,1,0,1,-1);
    }

    void Exit2dMode(){
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();
    }

    After calling Enter2d() your upper left corner is at (0,0) and the lower right corner is (1,1). So you can use the glVertex2f( ... ) function to specify 2d coords. After calling Exit2d() the previous state is set back again.


    [This message has been edited by Humus (edited 04-15-2000).]

  10. #10
    Junior Member Regular Contributor
    Join Date
    Apr 2000
    Location
    Thunder Bay,ON,Canada
    Posts
    135

    Re: Displaying text - little problem

    Kewl! That just about takes care of my fake 2D problems.

    Check out my OpenGl terrain engine at:
    www.fortunecity.com/skyscraper/epson/1181

    Tell me what you think.

    Thanx again for the help guys.
    -------------------------
    "Bad bad programmer! No Mountain Dew for you!"

Posting Permissions

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