PDA

View Full Version : renderPixmap() fails to load glsl shaders



jscurlee
17th September 2010, 22:12
Hello,

I am having some trouble getting QGLWidget::renderPixmap() to render images that use a pixel shader.

In my application I have a loadShaders() function that is called from within initializeGL() in a custom class the inherits QGLWidget(). I use renderPixmap() to perform an offline animation export where we dump several .png files to disk and build up an animation sequence. When calling renderPixmap() the new QGLContext that is created makes a call to initializeGL() which then try's to load the pixel shaders. In loadShaders() the call to glCreateShader() fails and returns 0. This causes the rendered image to have no pixel shaders applied and the image is not as expected. I'm not sure why this fails and there are no errors in the GL error log.

On linux and unix I have successfully gotten around this be passing useContext = true to the renderPixmap() function, which then uses the current glContext that is built up with QGLWidget when rendering the images. This seems to work great and gives the desired images using the pixel shaders; however, this is not supported on Windows. I am looking for a solution that will work on both linux, unix, and windows.

I have also recreated this behavior with the 'grabber' example found in <Path_to_Qt>/examples/opengl/grabber. I have modified the glwidget class to use a very simple pixel shader (refer to attached files for source code changes). I've tested this example on linux using gcc 4.4.3. After running qmake I also had to add -DGL_GLEXT_PROTOTYPES to my DEFINES, and add -I/usr/include to my INCPATH in my Makefile to get that example to compile and link correctly. Depending on where GL/glx.h is on your system you may have to tweak the include path.

In this simple example my shader just returns the color red for all pixels. When running this modified example the left-hand graphics widget shows all the gears red with no lighting meaning the shader was loaded successfully and is being used. When calling render to pixmap from the options the image that is rendered shows the red/green/blue gears which is the fall back rendering when the shaders fail to load. Calling the grab frame buffer option works as expected showing all the gears red. Tweaking the call to renderPixmap() to set useContext = true corrects the problem and shows the expected behavior when calling the render to pixmap option.

Since useContext flag is not supported under windows, is there any other work around to use the renderPixmap() function with pixel shaders? Or is there a way to setup my shader program so renderPixmap() will correctly create the gl shader when initializing the new QGLContext?

Or is there another approach I can take to get images that are rendered offline and show the pixel shaders? I have tried replacing renderPixmap() with grabFrameBuffer() but since this is an offlline rendering the results are not as expected. Not sure why this is, assuming it has to do with the rendering being done offline (i.e. there is no graphics window rendered to the screen). For this same reason using QPixmap::grabWindow() or QPixmap::grabWidget() doesn't work either.

Any support that can be provided would be greatly appreciated.
Thanks,
John