September 29, 2011

matti- matti-
Lab Rat
113 posts

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..?

 Signature 

Author of MMark13

9 replies

September 29, 2011

minimoog77 minimoog77
Lab Rat
130 posts

Just render your text by yourself (this would be most efficient).

September 29, 2011

matti- matti-
Lab Rat
113 posts

By myself meaning what exactly? :) You mean write a text renderer, draw to a buffer and use that as a texture to display it onscreen?

I tried QPainter with and without beginNativePainting() but that messes stuff up.

 Signature 

Author of MMark13

September 29, 2011

minimoog77 minimoog77
Lab Rat
130 posts

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.

September 29, 2011

Bradley Bradley
Lab Rat
314 posts

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

 Signature 

Nokia Certified Qt Specialist.

September 29, 2011

matti- matti-
Lab Rat
113 posts

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

 Signature 

Author of MMark13

September 30, 2011

minimoog77 minimoog77
Lab Rat
130 posts
matti- wrote:
Cant use Quads for ogl es2 tho but nonetheless :p

You can compose quad with two triangles. :)

December 24, 2011

Reptile Reptile
Lab Rat
28 posts

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?

December 24, 2011

matti- matti-
Lab Rat
113 posts

The method described above works sweetly and is portable. However filling with Qt::transparent bugged on Android, so better just render the text atlas using GIMP or similar instead of creating it from code.

 Signature 

Author of MMark13

December 26, 2011

Reptile Reptile
Lab Rat
28 posts
Reptile wrote:
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?

FYI: don’t use QGLWidget::renderText(). you’ll get this message:

[Qt Message] QGLWidget::renderText is not supported under OpenGL/ES

 
  ‹‹ Qt and DirectX for games      Experiences using Physics Engines with Qt 3D programs? ››

You must log in to post a reply. Not a member yet? Register here!