PDA

View Full Version : Setting color of bitmap text



Esben
11-27-2009, 03:24 AM
I am rendering some text in the upper left corner of my window with the following code, using glutBitmapCharacter:



// 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?

ZbuffeR
11-27-2009, 07:04 AM
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);

Esben
11-29-2009, 06:02 AM
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! :)