Skip to main content
GameDev.net gamedev.net
🔒 Locked

OpenGL Text

Started by rhollencamp May 3, 2004 at 10:39 PM 2 replies 750+ views
Original Post
rhollencamp
rhollencamp
I have some OpenGL code based on NeHe''s code for useing fonts in OpenGL. The program works on several computers except for my laptop and its old video drivers When the program is run it locks up at the point where it is displaying the font TitleFont (see code below). Using old drivers that I found it works but performance is terrible. Below is the code I used to initialize the fonts; please tell me I''m doing something wrong and its not that my laptop can''t handle fonts in OGL! HFONT font; // Windows Font ID HFONT oldfont; // Used For Good House Keeping TitleFont = glGenLists(96); font = CreateFont( -150, 0, 0, 0, FW_NORMAL, // Font Weight FALSE, // Italic FALSE, // Underline FALSE, // Strikeout ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "SolsticeOfSuffering"); oldfont = (HFONT)SelectObject(hDC, font); wglUseFontBitmaps(hDC, 32, 96, TitleFont); SelectObject(hDC, oldfont); DeleteObject(font); MenuFont = glGenLists(96); font = CreateFont( -72, 0, 0, 0, FW_NORMAL, // Font Weight FALSE, // Italic FALSE, // Underline FALSE, // Strikeout ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "SHLOP"); oldfont = (HFONT)SelectObject(hDC, font); wglUseFontBitmaps(hDC, 32, 96, MenuFont); SelectObject(hDC, oldfont); DeleteObject(font); NormalFont = glGenLists(96); font = CreateFont( -50, 0, 0, 0, FW_NORMAL, // Font Weight FALSE, // Italic FALSE, // Underline FALSE, // Strikeout ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, FF_DONTCARE|DEFAULT_PITCH, "Shlop"); oldfont = (HFONT)SelectObject(hDC, font); wglUseFontBitmaps(hDC, 32, 96, NormalFont); SelectObject(hDC, oldfont); DeleteObject(font); I use the following code to draw the fonts to the screen: void DrawString(int x, int y, unsigned int base, char *str, int displacement = 32) { glRasterPos2i(x, y); if ((base == 0) || (str == NULL)) return; glPushAttrib(GL_LIST_BIT); glListBase(base - displacement); glCallLists(strlen(str), GL_UNSIGNED_BYTE, str); glPopAttrib(); return; } Wizzard rhollencamp@zoominternet.net
schue
schue
Your code and your latop are ok, the performance hit comes from the way of text-output you use. wrapping every single letter into a display list that will have to setup all the states and bindings and blending for every single letter is about the worst idea of displaying text from a performance point of view.

It actually contradicts the concept of OpenGL in that way, that OpenGL is designed to be a state machine, where you set states and than do bulks of drawing. But instead of the display lists setup states for every letter just to draw one single Quad (or 2 triangles).

If you need to draw more Text than "Hello world", than display lists are not really a good choice here, unless you have tons of computing power to waste...
Venerable Vampire
Venerable Vampire
I can''t help you with your code since you are using the Windows OpenGL API but have you considered glut to get your feet wet on new topics? Glut supports a lot of things like fonts VERY easily. It also enables a very quick window setup and rendering context. Consider it for small projects like yours.

Life would be so much easier if we could just get the source code.
--------------------------------------------------------Life would be so much easier if we could just get the source code.
fooman
fooman
like mentioned in the first reply, its the fault of setting evry attribute befor draweing fonts. write yoruself an own font-rendering-routine, which is rendering all the font-stuff at one time. then just put the drawingstuff into the displaylists. befor drawing the fonts, restore the states you need to change with glPushAttrib() and at the end of the routine, restore them ( glPopAttrib()). Then just change em once in your font-rendering.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.