Slow Text-Output

Started by
0 comments, last by _Tobias_ 22 years, 1 month ago
Hi... I''m writing a small flightsim... Everything works fine, but my text-output ist very slow. Normally I have around 170fps. If I print a few strings, the framerate drops from 170fps to 130fps... Is there a better way to print strings to the screen? This is my code: static GLubyte s_rasters[][13] = { {0x00, 0x00, ........... 0x00} }; static float s_rows = 0.0f; static float s_cols = 0.0f; static GLuint s_fontOffset; static bool s_UseDisplayList = false; //------------------------------------------------------ // BuildDisplayList() //------------------------------------------------------ void BuildTextDisplayLists () { GLuint i; s_fontOffset = glGenLists (128); for (i = 32; i < 127; i++) { glNewList(i + s_fontOffset, GL_COMPILE); glBitmap(8, 13, 0.0, 2.0, 9.0, 0.0, s_rasters[i-32]); glEndList(); } s_UseDisplayList = true; } //--------------------------------------------------- // SetRatioForText() //--------------------------------------------------- void SetRatioForText (const int width, const int height) { s_rows = (float) height / 14.0f; s_cols = (float) width / 10.0f; } //------------------------------------------------- // SpitLetters() //------------------------------------------------- static void SpitLetters (LPCTSTR string) { if (s_UseDisplayList) { glPushAttrib(GL_LIST_BIT); glListBase(s_fontOffset); glCallLists(strlen(string), GL_UNSIGNED_BYTE, (GLubyte *) string); glPopAttrib(); } else { for (unsigned int i = 0; i < strlen(string); i++) { glBitmap(8, 13, 0.0, 2.0, 9.0, 0.0, s_rasters[string-32]); } } } //-------------------------------------------------- // PrintString() //-------------------------------------------------- void PrintString (LPCTSTR string, const int x, const int y) { glLoadIdentity(); glDisable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho (0.0, 1.0, 0.0, 1.0, -1.0, 1.0); glRasterPos2f((float) x / s_cols, (float) (s_rows - 1 - y) / s_rows); SpitLetters(string); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glEnable(GL_DEPTH_TEST); }
Advertisement
Use texture mapped text. Google & OpenGL FAQ will give you more information.

-Lev

This topic is closed to new replies.

Advertisement