How to do OpenGL live text-rendering for a GUI?

后端 未结 7 2039
面向向阳花
面向向阳花 2020-12-04 08:12

I\'m implementing a GUI built on top of OpenGL. I came to the problem that each GUI will have -- text rendering. I know of several methods of rendering text in OpenGL, howev

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-04 08:30

    Try reading this: http://dmedia.dprogramming.com/?n=Tutorials.TextRendering1.

    The approach described is the typical method for text rendering with graphics APIs. One character per quad, and all of the image data for text in a single texture. If you can fit your entire character set into one texture (actually, depending on the size of the texture, you might be able to fit several) the rendering is extremely fast.

    The key is that texture binding is the operation you need to minimize. If you can render all of your text with a single texture, it won't matter how much text you need to put on the screen. Even if you have to switch textures a handful of times (different fonts, different font attributes [bold, underline, etc]) performance should still be good. Text performance might be more critical for a HUD, but it less important in the GUI.

提交回复
热议问题