Results 1 to 4 of 4

Thread: How to Display 2D text on Screen, while being in 3D mode ???????????

  1. #1
    Member Contributor
    Join Date
    Apr 2002
    Location
    brooklyn, ny
    Posts
    65

    How to Display 2D text on Screen, while being in 3D mode ???????????

    I want to display 2D text ( ex shows FPS etc ) while running in 3D mode ...

    First I thought right before I go to display 2D text, I will save Current Projection matrix, and then Switch from gluPerspective() to glOrtho(), and I will be able to DIsplay the Text as If in the 2D mode, so while I move my Camera in 3D my Text will be displayed always in the same 2D position ...

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();

    glOrtho(0,800,0,600,-1,1);
    glMatrixMode(GL_MODELVIEW);

    glTranslatef(400.0f, 300.0f, 0.0f);
    glColor3f(1.0f, 1.0f, 1.0f);
    PrintString(listBase, "TEST");

    glFlush();
    SwapBuffers(g_HDC);

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

    In Other functions I setup The Font, Its type, Size, Delete etc ....

    This is my Print String Function

    void PrintString(unsigned int base, char *str)
    {
    if ((base == 0) | | (str == NULL))
    return;

    glPushAttrib(GL_LIST_BIT);
    glListBase(base - 32);
    glCallLists(strlen(str), GL_UNSIGNED_BYTE, str);
    glPopAttrib();
    }

  2. #2
    Senior Member Regular Contributor
    Join Date
    Apr 2002
    Location
    St. Louis, MO USA
    Posts
    177

    Re: How to Display 2D text on Screen, while being in 3D mode ???????????

    Your code looks okay to me, except that you might need to push the modelview matrix also, and then load the identity matrix before calling glTranslate. If you are using bitmap fonts, you also need to be aware of the raster position.

    By the way, you should try drawing some lines with your orthographic projection. It's possible that your text doesnt work at all.

    [This message has been edited by ioquan (edited 06-13-2002).]

  3. #3
    Senior Member Regular Contributor
    Join Date
    Jan 2002
    Posts
    292

    Re: How to Display 2D text on Screen, while being in 3D mode ???????????

    Try disabling GL_DEPTH_TEST


  4. #4
    Member Contributor
    Join Date
    Apr 2002
    Location
    brooklyn, ny
    Posts
    65

    Re: How to Display 2D text on Screen, while being in 3D mode ???????????

    Ok It worked .. I tried drawing a Polygon instead of Text in 2D, while movin my Cam in 3D..

    My problem was this:

    glClear();

    gluLookAt( cam values );

    glPushMatrix();
    drawStuff();
    collision=determineCollision();
    glPopMatrix();

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho();
    glMatrixMode(GL_MODELVIEW)

    draw2DstuffHERE();

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glFlush();

    The problem with this CODE was that gluLookAt( 3D cam values ), corrupted my 2D display.. Whenever I would Move in 3D, my 2D display would Appear, and Disapper whenever I would change my 3D cam coordinates.. However when I put gluLookAt() withing Push/Pop Matrix with drawing the 3D object , 2D display started to work Correctly !!!!!!

    Now I will try to display some text.

    I have a Question !! Right before I want to draw 2D, I call upon glMatrixMode(GL_PROJECTION).. After that I save it with glPushMatrix(), and then I reset the global ( not saved ) GL_PROJECTION matrix, for CLEAN 2D display ??!? Right ?? Im trying to understand what is going on here LOL ....

Similar Threads

  1. Render Text in perspective Mode?
    By 11&2 in forum OpenGL ES
    Replies: 1
    Last Post: 04-23-2011, 04:19 AM
  2. Full Screen Mode
    By moxx in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 01-16-2002, 12:29 AM
  3. What display mode can be used?
    By giggioland in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 06-20-2001, 01:41 PM
  4. full-screen mode
    By MichaelK in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 01-16-2001, 08:11 AM
  5. Console mode text???
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-01-2000, 06:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean