PDA

View Full Version : Text color-changing problems



eestolano
05-05-2005, 09:00 PM
I'm drawing text to the screen as follows:
(a) I have a 2D array of chars, initially containing all periods (so I can see what's going on).
(b) I've made a set of display lists for a stroke font using wglUseFontBitmaps.
(c) I also have an array of color values (structs of 3 GLfloats) of the same size as the character array (i.e. each character has its own color). I originally initialize this array to all white.

I throw each row into the following code to draw it (modified NeHe code), shift down, repeat, and so on to draw the entire array:

glPushAttrib(GL_LIST_BIT);
glListBase(font_base - 32);

for (int i = 0; i < width; ++i)
{
glColor3f(color[i].r, color[i].g, color[i].b); // sets the color
glCallLists(1, GL_UNSIGNED_BYTE, (text+i)); // Draws The Display List Text

}

glPopAttrib();The correct characters are showing up in the right positions. The problem is that the colors aren't showing up accurately: whatever color I set all the characters to in the beginning persists - changing the color of a particular character doesn't make a difference. Note that I don't call glColor3f or any other OpenGL color-changing function anywhere outside this snippet of code - all other "color changes" are merely changes to the aforementioned 2D array. I've used a debugger to make sure that glColor3f does, in fact, get called with the correct RGB values right before glCallLists is called with the corresponding character.
Any suggestions would be quite helpful.

ete
05-06-2005, 02:23 AM
Are u using the GL_SMOOTH or GL_FLAT glShadeModel ?
If u're using the flat model, try using GL_SMOOTH...( just a "could be" answer )

Relic
05-06-2005, 03:24 AM
If you're using wglUseFontBitmaps, which store the glyphs in glBitmaps, the glBitmap color is taken from the current glRasterPos.
No glColor call will have an effect if there isn't a glRasterPos call after it picking it up for the next glBitmap!
You must add glRasterPos calls after the glColor call which also means you need to calculate the next character position yourself.
One color per character isn't mainstream usage.