Rendering text over OpenGL ES 2.0 surface (QGLWidget)?
-
What would be the best (= most efficient) way to render text on top of a rendered opengl (es 2.0) scene? This would be needed for typical gaming stuff such as screen notifications, fps counter etc. I was thinking perhaps render the text onto a QImage / other RGBA canvas and then draw that using OpenGL's texture..?
-
Just render your text by yourself (this would be most efficient).
-
By meaning 'yourself' is to draw textured quads of with text glyphs. You can prebake big (relatively speaking) texture with 256 glyphs, just change tex coordinates to draw particular glyph.
-
Rather than prebaking an image atlas, I generate it dynamically using a QPainter to draw to a texture which is displayed with quads. I don't know how much less efficient it is to draw the characters to the image on demand rather than prebaking, but I need the flexibility to change the font to anything the system provides. You can see the code here:
http://gitorious.org/mifit/mifit/blobs/master/libs/opengl/Text.h
http://gitorious.org/mifit/mifit/blobs/master/libs/opengl/Text.cpp -
Thanks for the feedback! I've used the texture atlas approach with each character UV mapped with lookup table in the good 'ole software rendering times, shouldnt be too much of a hassle. Cheers, I'll see what I'll come up with. Cant use Quads for ogl es2 tho but nonetheless :p
-
[quote author="matti-" date="1317320125"]Cant use Quads for ogl es2 tho but nonetheless :p[/quote]
You can compose quad with two triangles. :)
-
Hey, I'm without my N8 for a week or so, but I've just finished writing openGL code for a game in the simulator, including using QGLWidget::renderText() for text rendering. But I read that it's not supported by OpenGL ES? Does that mean it won't show up on the phone or will cause other problems? Does anyone know if renderText() will/won't work?
-
[quote author="Reptile" date="1324699470"]Hey, I'm without my N8 for a week or so, but I've just finished writing openGL code for a game in the simulator, including using QGLWidget::renderText() for text rendering. But I read that it's not supported by OpenGL ES? Does that mean it won't show up on the phone or will cause other problems? Does anyone know if renderText() will/won't work?[/quote]
FYI: don't use QGLWidget::renderText(). you'll get this message:
[Qt Message] QGLWidget::renderText is not supported under OpenGL/ES