OpenGl Fonts - performance issue?
Hello, just a quick question here about performance issues with fonts.
A friend of mine said that displaying fonts in an opengl window can seriously affect performance (framerate) because everytime text is drawn to the screen, buffers have to be cleared or something, didnt quite understand him
I believe Games such as Quake, Half-life etc. use textures to display text such as health and ammo and such things. I have read some of NeHe''s tutorials on using fonts, and I was wondering if NeHe''s way can slow down the opengl game (no offence)? Would this performance issue only come about when using the method described in NeHe''s lesson 15 - Texture Mapped Fonts, and not so much when using plain old Bitmap fonts (lesson 15 - BitMap Fonts)? The reason I ask is that I simply want to be able to print basic straight forward text to the screen...nothing fancy, just quick and easy.
As you can see I don''t have a very good understanding when it comes to what will affect an OpenGL application''s performance.
I would really appreciate it if anybody could clear this up with me, or at least tell me what a complete ignoramus I am
First, outline fonts are slower than bitmap fonts because a bitmap font letter only needs four vertices to be sent to the card while an outline font letter needs dozens or potentially even hundreds, depending on the detail level you''re looking for. You can try it yourself: write a paragraph (a number of long lines) of text using lesson 13/lesson 15, calculate the framerate at the end, and observe the difference.
Then, wgl routines are slow anyway compared to a vertex array font engine you can build yourself. They create a display list for every letter, so if you want to display 100 characters, you have to call 100 displaylists. While the rendering of one textured quad is pretty fast, much more work is needed to first set up and then restore the renderstates that every letter requires. Basically, if you draw 100 characters you output 400 vertices and issue 200 state changes, which is not good. The performance hit on state changes is less noticeable with outline fonts, because each letter requires more processing.
Since wgl routines print text letter-by-letter, they (besides being slow) can''t support line breaks or text formatting, by design.
The most efficient way is to create your own font engine, that can draw text in strings instead of in characters, meaning you set up the required states, draw 400 quads, and restore the states. Only two state changes are required this way. See the difference? Plus, since you are handling strings of text, you can format them (left/right/center alignment), obtain the width of text, do rotations (not sure if wgl can do them) and so on. Line breaks are implemented trivially. There''s also room for even more performance increases, and more formatting options.
Two ways of creating your font engine are by using a pre-made bitmap or by creating a texture at runtime from the currently installed fonts. You can implement the rendering using displaylists or vertex arrays. Lesson 17 illustrates pre-made bitmaps with displaylists. Vertex arrays should be faster than display lists for this type of application. You can potentially use VAR/VAOs, but I didn''t see a font engine using them. I implemented a runtime-generated vertex array-based font engine, which is a port of D3DFont class from DirectX SDK samples. I think my font class is pretty cool .
Which font engine should you use? It depends on what performance you need and what amounts of text you want to render. Simple methods will most likely provide adequate performance for an FPS counter, but will be poor for a load of scrolling text. More advanced methods take longer to implement and require a debugger, but they pay off with high framerates at high loads.
Then, wgl routines are slow anyway compared to a vertex array font engine you can build yourself. They create a display list for every letter, so if you want to display 100 characters, you have to call 100 displaylists. While the rendering of one textured quad is pretty fast, much more work is needed to first set up and then restore the renderstates that every letter requires. Basically, if you draw 100 characters you output 400 vertices and issue 200 state changes, which is not good. The performance hit on state changes is less noticeable with outline fonts, because each letter requires more processing.
Since wgl routines print text letter-by-letter, they (besides being slow) can''t support line breaks or text formatting, by design.
The most efficient way is to create your own font engine, that can draw text in strings instead of in characters, meaning you set up the required states, draw 400 quads, and restore the states. Only two state changes are required this way. See the difference? Plus, since you are handling strings of text, you can format them (left/right/center alignment), obtain the width of text, do rotations (not sure if wgl can do them) and so on. Line breaks are implemented trivially. There''s also room for even more performance increases, and more formatting options.
Two ways of creating your font engine are by using a pre-made bitmap or by creating a texture at runtime from the currently installed fonts. You can implement the rendering using displaylists or vertex arrays. Lesson 17 illustrates pre-made bitmaps with displaylists. Vertex arrays should be faster than display lists for this type of application. You can potentially use VAR/VAOs, but I didn''t see a font engine using them. I implemented a runtime-generated vertex array-based font engine, which is a port of D3DFont class from DirectX SDK samples. I think my font class is pretty cool .
Which font engine should you use? It depends on what performance you need and what amounts of text you want to render. Simple methods will most likely provide adequate performance for an FPS counter, but will be poor for a load of scrolling text. More advanced methods take longer to implement and require a debugger, but they pay off with high framerates at high loads.
---visit #directxdev on afternet <- not just for directx, despite the name
Looks like I ignored your post, sorry.
Fast font engine will give you high framerates, and a slow one will give you low framerates. You can write a very fast font engine; text rendering isn''t inherently slow. It''s only slow if you use slow methods (see my previous post).
I''d say that is so.
NeHe''s way, especially wgl way, is quite slow as soon as you start drawing more than a few words.
Outline fonts are slower than bitmap fonts, but wgl are slower than what you potentially can write yourself.
See the last paragraph in my previous post. Framerate is the function of the time and effort you put into your engine.
quote: Original post by Dark_Streak
A friend of mine said that displaying fonts in an opengl window can seriously affect performance (framerate) because everytime text is drawn to the screen, buffers have to be cleared or something, didnt quite understand him
Fast font engine will give you high framerates, and a slow one will give you low framerates. You can write a very fast font engine; text rendering isn''t inherently slow. It''s only slow if you use slow methods (see my previous post).
quote:
I believe Games such as Quake, Half-life etc. use textures to display text such as health and ammo and such things.
I''d say that is so.
quote:
I have read some of NeHe''s tutorials on using fonts, and I was wondering if NeHe''s way can slow down the opengl game (no offence)?
NeHe''s way, especially wgl way, is quite slow as soon as you start drawing more than a few words.
quote:
Would this performance issue only come about when using the method described in NeHe''s lesson 15 - Texture Mapped Fonts, and not so much when using plain old Bitmap fonts (lesson 15 - BitMap Fonts)?
Outline fonts are slower than bitmap fonts, but wgl are slower than what you potentially can write yourself.
quote:
The reason I ask is that I simply want to be able to print basic straight forward text to the screen...nothing fancy, just quick and easy.
See the last paragraph in my previous post. Framerate is the function of the time and effort you put into your engine.
---visit #directxdev on afternet <- not just for directx, despite the name
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement