[Qt-interest] GLSL and two semi-transparent textures

Josiah Bryan jbryan at productiveconcepts.com
Tue Aug 10 23:16:44 CEST 2010


Hello, everyone!

Odd problem here - I'm using a QGLWidget and GLSL vertex shaders to draw 
live video captured via V4L2 into OpenGL textures. I've used the shaders 
from QPainterVideoSurface from the QtMultimedia module by bashing 
together code from QPainterVideoSurface and the 
qt/examples/opengl/textures example.

It works great! High FPS, low latency - very quick. (Less than 10ms 
latency from the moment we capture a frame till it's finished rendering 
in the paintGL() function. Not bad.)

Just one problem - When I draw two textures, one over top of the other 
(think a PiP), and the top (pip) has an alpha channel (say, the Qt cube 
logo from the pbuffers examples), the qglClearColor shows thru in the 
transparent areas of the top texture, NOT the bottom texture!

Screen shot of the problem here:
http://corp.productiveconcepts.com/dropbox/TextureSnapshot.jpg

(qglClearColor is Qt::green - the green you see surrounding the qt loog. 
The blue in the snapshot is the 'no signal' color from the video capture 
card at /dev/video0 - two different textures. The green background to 
the Qt logo *should* just show the same blue as the rest of the window.)

The drawing method begins here:
http://code.google.com/p/dviz/source/browse/trunk/src/glvidtex/glwidget.cpp#602

The shader being used to draw the overlay (PiP texture) is here:
http://code.google.com/p/dviz/source/browse/trunk/src/glvidtex/glwidget.cpp#63

And, yes, GL_BLEND is enabled - the qt cube logo does properly blend 
with the background - just the wrong background! It uses the clear 
color, not the underlying texture. See here for the glEnable call:
http://code.google.com/p/dviz/source/browse/trunk/src/glvidtex/glwidget.cpp#1045

I thought it might have something to do with depth testing, or the Z 
value of the textures, so I set that up properly, enabled GL_DEPTH_TEST, 
  set glDepthFunc, and added a Z component to the vertex buffers used in 
the paint method starting on line 602 - that didn't help at all. Same 
exact outcome.

Any suggestions on what I'm doing wrong or how I can get the overlay to 
blend with the texture behind it instead of the clear color?

Thanks!
-Josiah Bryan

-- 

-=-=-=-=-=-=-=-=-=-=-=-=-
Josiah Bryan
Productive Concepts, Inc.
jbryan at pciint.com
(765) 964-6009, ext. 224




More information about the Qt-interest-old mailing list