Results 1 to 3 of 3

Thread: 2D text

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2006
    Posts
    2

    2D text

    So, i'm trying to display some text by switching to orthographioc view and using display lists to show bitmap characters. But nothing shows up. I don't even know how to debug this since nothing happens.
    Here's the code i use:

    Code :
    Text::Text(void *font)
    {
        //generate list ids for alla ASCII characters
        base = glGenLists(256);
        //create lists
        for (int i=0; i<256; i++)
        {
            glNewList(base+i, GL_COMPILE);
            glColor3f(1.0f,1.0f,0.0f);
            glutBitmapCharacter(font, i);
            glEndList();
        }
    }
     
    void Text::write(int x, int y, const char* str)
    {
         //set list base to access teh correct list by character ascii code
         glListBase(base);
     
         //switch to orthographics projection
         setOrtho();
         //save matrix
         glPushMatrix();
         //clear matrix
         glLoadIdentity();
         //set raster position
         glRasterPos2f(x, y);
         //draw text
         glCallLists((GLint) strlen(str), GL_UNSIGNED_BYTE, str);
         //load matrix
         glPopMatrix();
         //switch to perspective projection
         resetPerspective();
    }
     
     
    void Text::setOrtho()
    {
        //get screen dimensions
        int w = glutGet((GLenum)GLUT_WINDOW_WIDTH);
        int h = glutGet((GLenum)GLUT_WINDOW_HEIGHT);
     
    	//switch to projection mode
    	glMatrixMode(GL_PROJECTION);
    	//save matrix 
    	glPushMatrix();
    	//clear matrix
    	glLoadIdentity();
    	//set a 2D orthographic projection
    	gluOrtho2D(0, w, 0, h);
    	// invert the y axis, down is positive
    	glScalef(1, -1, 1);
    	// move the origin from the bottom left corner
    	// to the upper left corner
    	glTranslatef(0, -h, 0);
    	//switch to modelview mode
    	glMatrixMode(GL_MODELVIEW);
    }
     
    void Text::resetPerspective()
    {
        //set projection mode
    	glMatrixMode(GL_PROJECTION);
    	//load saved matrix
    	glPopMatrix();
    	//switch to modelview mode
    	glMatrixMode(GL_MODELVIEW);
    }
    Anyone have any clues?

    Thanx a lot

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Aug 2004
    Location
    munich, germany
    Posts
    659

    Re: 2D text

    1. you are using glRasterPos2f with two integer variables, x and y. this probably doesn't cause the problem, but you should fix it.

    2. glTranslate, glScale, glRotate should be used on the modelview matrix, not on the projection matrix.

    3. if you use glScale before glTranslate, this means that the translation is performed first. maybe exchanging them helps.

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2006
    Posts
    2

    Re: 2D text

    Well, I tried doing textured fonts and got that to work insted =)
    Thanx for taking the time to answer!

Similar Threads

  1. Text rendering class does not draw text
    By th0masr0ss in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-23-2015, 09:10 PM
  2. Text for a text field
    By GrinderFX in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 12-30-2003, 11:44 AM
  3. Replies: 0
    Last Post: 11-15-2002, 02:58 AM
  4. GUI Text
    By imported_miguel in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-29-2000, 07:11 AM
  5. 2D text in 3D
    By waynekt in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-02-2000, 05:44 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