I simplified my project in order to work on the performance and I found out that Bitmap Font is responsible for some of the performance issues.
So what I have is a standard cube and some text (you can check the image below to see what i mean).
When I render just cube everything responds fast (meaning translation and rotation of the cube), but once I add text it slows down depending from amount of text on screen (meaning if i have one or two its ok, but 15 or above performance drops a lot).
Here is the code from my project which is responsible for the text.
void GLFont::BuildBitmapFont(HDC &hdc)
{
baseBitmap = glGenLists(96); // Storage for 96 characters
fontSize = -MulDiv(fontSize, GetDeviceCaps(hdc, LOGPIXELSY), 72);
fontBitmap = CreateFont( -fontSize, // Height of font
0, // Width of font
0, // Angle of escapement
0, // Orientation angle
FW_NORMAL, // 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
oldfontBitmap = (HFONT)SelectObject(hdc, fontBitmap); // Selects the font we want
wglUseFontBitmaps(hdc, 32, 96, baseBitmap); // Builds 96 characters starting at character 32
SelectObject(hdc, oldfontBitmap); // Selects the font we want
DeleteObject(fontBitmap); // Delete the font
}
void GLFont::glBitmapPrint(const char *fmt, int i, double size, double _x, double _y, double _z)
{
float length=0; // Used To Find The Length Of The Text
float heigth=0; //Use To Find Heigth of the Text
glPushMatrix();
glColor3f(0.0f, 0.0f, 0.0f); // set Color 2 white
char text[256]; // Holds our string
va_list ap; // Pointer to list of arguments
if (fmt == NULL) // If there's no text
return; // Do nothing
glRasterPos3d(_x, _y, _z);
va_start(ap, fmt); // Parses the string for variables
vsprintf(text, fmt, ap); // And converts symbols to actual numbers
va_end(ap); // Results are stored in text
glPushAttrib(GL_LIST_BIT); // Pushes the display list bits
for (unsigned int loop=0;loop<(strlen(text));loop++) // Loop To Find Text Length
{
length+=gmfBitmap[text[loop]].gmfCellIncX; // Increase Length By Each Characters Width
heigth+=gmfBitmap[text[loop]].gmfCellIncY;
}
if (size < 0.1)
glTranslatef(-size/2,-0.01, 0.0); // Center Our Text On The Screen
else
glTranslatef(-length/20,-0.03, 0.0); // Center Our Text On The Screen
glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(baseBitmap - 32); // Sets the base character to 32
glScalef(size, size, 0.0);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws the display list text
glPopAttrib();
glPopMatrix();
}
So my question: Are theare any better way to render text on the scene without sacrificing performance? Or I am doing something wrong which causes performance drop?
Any comment would be appreciated.
Thanks in advance.






