Can't get ShaderEffectItem to work, any suggestions?



  • Hello -

    I am trying to use the ShaderEffectItem. I downloaded, built and installed the shader plug in, however when I attempt to run it I get the following error:

    ShaderEffectItem::paint - OpenGL not available

    My QML is as follows:

    @
    import QtQuick 1.0
    import QMLImage 1.0
    import Qt.labs.shaders 1.0

    Rectangle {
    width: 300
    height: 300
    color: "black"

    Text {
    id: textLabel
    text: "Hello World"
    anchors.centerIn: parent
    font.pixelSize: 32
    color: "white"

    }

    ShaderEffectItem {
    property variant source: ShaderEffectSource { sourceItem: textLabel; hideSource: true }
    property real wiggleAmount: 0.005
    anchors.fill: textLabel

    fragmentShader: "
    varying highp vec2 qt_TexCoord0;
    uniform sampler2D source;
    uniform highp float wiggleAmount;
    void main(void)
    {
    highp vec2 wiggledTexCoord = qt_TexCoord0;
    wiggledTexCoord.s += sin(4.0 * 3.141592653589 * wiggledTexCoord.t) * wiggleAmount;
    gl_FragColor = texture2D(source, wiggledTexCoord.st);
    }
    "
    }
    }
    @

    I am including the reference to opengl in my qmlapplicationviewer.pri file like so:

    QT += opengl

    I also include:

    #include <QtOpenGL>

    in my header file.

    Is there something else I have to do to get this to work?

    Looking forward to your response.



  • Found the answer myself, it turns out that in my main, I did not set the viewer viewport equal to a QGLWidget. The code below fixed by problem:
    @
    QGLFormat format = QGLFormat::defaultFormat();
    format.setSampleBuffers(false);
    format.setSwapInterval(1);
    QGLWidget* glWidget = new QGLWidget(format);
    glWidget->setAutoFillBackground(false);
    viewer.setViewport(glWidget);
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.