Thread: OpenGL - 2d text in 3d game

  1. #1
    Registered User
    Join Date
    Mar 2006

    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


  2. #2
    Registered User
    Join Date
    Jan 2006
    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:
    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() {
    	gluOrtho2D(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT);
    	glScalef(1, -1, 1);
    	glTranslatef(0, -SCREEN_HEIGHT, 0);
    void resetPerspectiveProjection() {
    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: hes got a lot of great tutorials.

    Good luck


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, 06: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, 03:17 PM
  4. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM