Text in a 3d environment

This is a discussion on Text in a 3d environment within the Game Programming forums, part of the General Programming Boards category; Hello, I am designing a game in which I want text to be displayed over certain objects to indicate to ...

  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 05:12 PM. Reason: Clarification

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,586
    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, 02:26 AM
  2. OpenGL - 2d text in 3d game
    By mikeb1986 in forum C++ Programming
    Replies: 1
    Last Post: 03-22-2006, 12: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, 10:19 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21