OpenGL - 2d text in 3d game

This is a discussion on OpenGL - 2d text in 3d game within the C++ Programming forums, part of the General Programming Boards category; hi, im using OpenGL with C++ to make basically a 3d pool game, but i need to get text on ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    1

    OpenGL - 2d text in 3d game

    hi, im using OpenGL with C++ to make basically a 3d pool game, but i need to get text on the screen and have no idea how, i read something about switching to glOrtho and then switching back after the text is printed, this way the text always stays in the same place on the game screen regardless of what camera angle the player is using. can anyone enlighten me. thanks very much

    -mike

  2. #2
    Registered User
    Join Date
    Jan 2006
    Location
    Sweden
    Posts
    92
    There's a library called glut which includes that function. For the following code to work you got to include gl/glut.h and link glut32.lib. If you don't have those, just google around a little bit

    Here's the code:
    Code:
    void writeString(char* string, int x, int y, void* font)
    {
    	glRasterPos2i(x, y);
    	int len = strlen(string);
    	for (int i=0; i < len; i++)
    	{
    		glutBitmapCharacter(font, string[i]);
    	}
    }
    void setOrthographicProjection() {
    
    	glMatrixMode(GL_PROJECTION);
    	glPushMatrix();
    	glLoadIdentity();
    	gluOrtho2D(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT);
    	glScalef(1, -1, 1);
    	glTranslatef(0, -SCREEN_HEIGHT, 0);
    	glMatrixMode(GL_MODELVIEW);
    }
    
    void resetPerspectiveProjection() {
    	glMatrixMode(GL_PROJECTION);
    	glPopMatrix();
    	glMatrixMode(GL_MODELVIEW);
    }
    I have not written all of this code though, most is taken from a tutorial but I cant remember where :-/ . If you want to use other ways; try Nehe: http://nehe.gamedev.net hes got a lot of great tutorials.

    Good luck

    Daniel

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Text adventure game GUI
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 11-07-2007, 05:34 PM
  2. first opengl game, problems.
    By n3v in forum Game Programming
    Replies: 1
    Last Post: 07-11-2006, 08:22 PM
  3. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 02:17 PM
  4. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 03:49 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 06:35 PM

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