Hey everyone,
I am trying to impliment a simple font for my engines demo (For ingame
testing). This code is demo code, not engine code (Hence, its a little ugly)
It is using OpenGL, and WGL for building the font. The problem is when I
am trying to set the fonts color. Changing the fonts color not only changes
the font, but the entire viewport to!
Heres my code that creates and sets up the font..
class Font {
uint32_t _uiFontBase;
void Destroy () {
glDeleteLists (_uiFontBase,96);
}
public:
virtual ~Font() {
Destroy ();
}
void Build (HWND hwnd) {
HFONT hFont, hOldFont;
if (!win)
return;
// generate character lists (up to 96 characters)
_uiFontBase = glGenLists (96);
// Create our font
hFont = CreateFont( 16, // Height Of Font
0, // Width Of Font
0, // Angle Of Escapement
0, // Orientation Angle
300, // Font Weight
FALSE, // Italic
FALSE, // Underline
FALSE, // Strikeout
ANSI_CHARSET, // Character Set Identifier
OUT_TT_PRECIS, // Output Precision
CLIP_DEFAULT_PRECIS, // Clipping Precision
ANTIALIASED_QUALITY, // Output Quality
FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch
"Courier New"); // Font Name
HDC hDC=GetDC(hwnd);
hOldFont = (HFONT)SelectObject(hDC, hFont);
wglUseFontBitmaps(hDC, 32, 96, _uiFontBase); // Builds 96 Characters Starting At Character 32
SelectObject(hDC, hOldFont); // Selects The Font We Want
DeleteObject(hFont); // Delete The Font
}
void Print (std::string str) {
glPushAttrib (GL_LIST_BIT);
glListBase (_uiFontBase-32);
glCallLists (str.length(), GL_UNSIGNED_BYTE, str.c_str());
glPopAttrib ();
}
};
Font _font;
Here is the code that displays the font..
glDisable (GL_TEXTURE_2D);
glColor3f (0.0f,0.0f,1.0f);
glRasterPos2f(-0.5f, -0.3f);
_font.Print ("E v o l u t i o n E n g i n e");
glRasterPos2f(-0.5f, -0.33f);
char buf[255];
sprintf_s (buf,"FPS: %i", uiFPS);
_font.Print (buf);
glEnable (GL_TEXTURE_2D);
(Ugly, I know--I have to clean up the demo)
The text does display. Its the text color (glColor3f()) that seems to be causing
the issue. Not only is the fonts color changed, but the entire viewport is
as well:
What could cause this? The text is supposed to be blue, and only the text.
I know its probably something simple, I just cant find an answer..
Thanks!