QPainter & OpenGL GLSL painting problem



  • I'm using QPainter to display a background and overlay a 3D model using an OpenGL shader. When the shader is simple (i.e. no lighting) this works fine, but as soon as I try and add lighting the background disappears and the OpenGL part only is drawn. Can anyone suggest a fix please?

    @ QPainter painter;
    painter.begin(this);
    painter.fillRect(0, 0, this->width(), this->height(), Qt::black);
    painter.drawImage(QRect((this->width()-myWidth)/2, (this->height()-myHeight)/2,
    myWidth, myHeight),
    backgroundImage);
    painter.beginNativePainting();
    ...
    [MY OPENGL CODE HERE]
    ...
    painter.endNativePainting();
    @

    This shader works but has no lighting:

    @
    attribute vec3 ourcolor;
    attribute float alpha;
    attribute float myLight;
    attribute vec3 normal;
    uniform mat4 mvp_matrix;
    attribute vec4 a_position;
    varying vec4 color;

    void main()
    {
    color = vec4(ourcolor, alpha);
    gl_Position = mvp_matrix * a_position;
    }
    @

    whereas this one doesn't show the QPainter image or clear the background:

    @
    attribute vec3 ourcolor;
    attribute float alpha;
    attribute float myLight;
    attribute vec3 normal;
    uniform mat4 mvp_matrix;
    attribute vec4 a_position;
    varying vec4 color;

    void main()
    {
    vec4 toLight = normalize(vec4(0.0f, 0.0f, -1.0f,0.0f));
    vec4 myNormal = normalize(mvp_matrix * vec4(normal,0.0));
    float angle = abs(dot(normalize(myNormal), toLight));
    color = vec4(ourcolor * angle, alpha);
    //color = vec4(ourcolor, alpha);
    gl_Position = mvp_matrix * a_position;
    }
    @


Log in to reply
 

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