[Interest] QOpenGLWidget and text

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Wed Apr 1 16:28:04 CEST 2015


Il 01/04/2015 15:42, Matthew Woehlke ha scritto:
> If I go the route of pre-rendering the text into a QImage, what is the
> easiest way, using only the modern QOpenGL classes (since there is no
> longer bindTexture either), to get that into an OpenGL texture?

A rough game plan is this:

* Create a QImage of a suitable size (depending on your needs)
* Fill it with color or trasparency
* Use QPainter to draw on it (using a font of a suitable size)
* Create/upload it into a QOpenGLTexture
* Create a suitable set of VBOs using QOpenGLBuffer containing vertex 
coordinates as well as texture coordinates for a rectangle (you'll need 
to triangulate it!)
* Optionally create an IBO using QOpenGLBuffer containing indexes for 
your vertexes
* Create a suitable shader program by combining a vertex shader (which 
may optionally do the billboarding, unless you generated vertex 
coordinates in the right positions) and a fragment shader (which samples 
from the texture using the interpolated texture coordinates which are 
emitted by the vertex shader) and bind it
* Create a QOpenGLVertexArrayObject and bind it
* Enable and configure the attribute arrays on your shader program by 
binding the VBOs and specifying their format
* Optionally bind the IBO into the VAO

(setup complete)

To draw:

* Bind the VAO
* Bind (use) the shader program
* Get the texture into the program, f.i. by binding the texture + 
setting the texture unit index as a uniform value on the right uniform 
sampler2D object in your program
* Draw the quad via glDrawArrays / glDrawElements (depending if you used 
an IBO or not)

Depending on your needs you may need alpha blending enabled, 
alpha-discard in your fragment shader, as well as alpha-to-coverage to 
smooth antialiased edges.

Isn't Modern OpenGL lovely? ;)

Cheers,

-- 
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Software Engineer
KDAB (UK) Ltd., a KDAB Group company | Tel: UK +44-1625-809908
KDAB - The Qt Experts

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4048 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150401/8666ed1f/attachment.bin>


More information about the Interest mailing list