Thread: Text in a 3d environment

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    35

    Text in a 3d environment

    Hello, I am designing a game in which I want text to be displayed over certain objects to indicate to the user what to do next.

    Sadly, when I was messing around a few weeks ago I got text to appear in the environment when I didnt want it to, now I forget what cause it.

    Here is my text drawing function, it works fine for my current menu which is done displaying messages on the users HUD.
    Code:
    ...
    void setOrthographicProjection() 
    {
         
         // switch to projection mode
    	 glMatrixMode(GL_PROJECTION);
    	 // save previous matrix which contains the 
    	 //settings for the perspective projection
    	 glPushMatrix();
    	 // reset matrix
    	 glLoadIdentity();
    	 // set a 2D orthographic projection
    	 gluOrtho2D(0, win_width, 0, win_height);
    	 // invert the y axis, down is positive
    	 glScalef(1, -1, 1);
    	 // mover the origin from the bottom left corner
    	 // to the upper left corner
    	 glTranslatef(0, -win_height, 0);
    	 glMatrixMode(GL_MODELVIEW);
    	 
    }
    
    void resetPerspectiveProjection() 
    {
         
         glMatrixMode(GL_PROJECTION);
    	 glPopMatrix();
    	 glMatrixMode(GL_MODELVIEW);
    	
    }
    
    
    void renderBitmapString(float x, float y, float z, void *font, char *string) {
         char *c;
         glRasterPos3f(x, y, z);
         for (c=string; *c != '\0'; c++) {
             glutBitmapCharacter(font, *c);
         }
    }
    
    glPushMatrix();
    setOrthographicProjection();
    glLoadIdentity();
    renderBitmapString(30,30,0,(void *)font,"Hello World ");
    resetPerspectiveProjection();
    glPopMatrix();
    This draws text on the screen which follows the camera, if I call
    Code:
    renderBitmapString(5,3,7,(void *)font,"Hello World ");
    at some random coordinate, it isnt displayed in my 3d world. I have a feeling i am missing some matrix multiplication, which I admit I am not quite sure what is needed here.

    As well I want this text to face the player, or in a particular direction...but one issue at a time.

    Any advice would be greatly appreciated.
    Last edited by Iconate; 03-02-2010 at 06:12 PM. Reason: Clarification

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You should not use a projection matrix unless you are trying to do world-based text - as in the case of displaying information next to an object in your world in world space. For HUDs you should be using ortho matrices.

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    35
    Quote Originally Posted by Bubba View Post
    You should not use a projection matrix unless you are trying to do world-based text - as in the case of displaying information next to an object in your world in world space. For HUDs you should be using ortho matrices.
    Are you saying I have to change glMatrixMode to GL_PROJECTION then before I try to put the text in the world?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help in Compiling errors
    By sick in forum C Programming
    Replies: 2
    Last Post: 01-21-2010, 03:26 AM
  2. OpenGL - 2d text in 3d game
    By mikeb1986 in forum C++ Programming
    Replies: 1
    Last Post: 03-22-2006, 01:24 PM
  3. 3D SDK for C++ programmers
    By chand in forum Game Programming
    Replies: 2
    Last Post: 05-20-2003, 07:38 AM
  4. Replies: 1
    Last Post: 07-13-2002, 05:45 PM
  5. 3d engines
    By Unregistered in forum Game Programming
    Replies: 7
    Last Post: 12-17-2001, 11:19 AM

Tags for this Thread