Results 1 to 3 of 3

Thread: Setting color of bitmap text

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2009
    Location
    Copenhagen, Denmark
    Posts
    14

    Setting color of bitmap text

    I am rendering some text in the upper left corner of my window with the following code, using glutBitmapCharacter:

    Code :
    // color = white
    glColor3f(1,1,1);
     
    // set orthographic projection
    glMatrixMode( GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluOrtho2D(0.0, (GLfloat)win_width, 0.0, (GLfloat)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);
     
    // switch to model view and save current matrix
    glMatrixMode( GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();
     
    // render text
    string str = "some text";
    for (int i = 0; i < (int) str.length(); i++)
    {
        c = str[i];
        glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, c);
    }
     
    // go back to saved matrix in model view
    glPopMatrix();
     
    // go back to saved matrix in projection (perspective)
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
     
    // change to model view
    glMatrixMode(GL_MODELVIEW);

    The problem is that the text is not white, it's black! What am I doing wrong?

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Setting color of bitmap text

    Try disabling lighting :
    // color = white
    glColor3f(1,1,1);
    glDisable(GL_LIGHTING);

    ...

    // don't forget to enable it later when you need it
    glEnable(GL_LIGHTING);

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2009
    Location
    Copenhagen, Denmark
    Posts
    14

    Re: Setting color of bitmap text

    Quote Originally Posted by ZbuffeR
    Try disabling lighting :
    // color = white
    glColor3f(1,1,1);
    glDisable(GL_LIGHTING);

    ...

    // don't forget to enable it later when you need it
    glEnable(GL_LIGHTING);
    That solved it, thank you!

Similar Threads

  1. Selection of bitmap text
    By PollyPocket4eva in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-10-2009, 03:44 PM
  2. text as bitmap
    By Joemancha in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-31-2007, 04:34 PM
  3. Displaying text on a bitmap
    By sappy in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-21-2005, 11:20 AM
  4. Color of bitmap text being ignored
    By DalTXColtsFan in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-15-2003, 09:57 PM
  5. How To Write Text w/o Bitmap Files?
    By sjsearcher in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-18-2001, 11:42 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