Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPainter & OpenGL GLSL painting problem
Forum Updated to NodeBB v4.3 + New Features

QPainter & OpenGL GLSL painting problem

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yalnte
    wrote on last edited by
    #1

    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;
    }
    @

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved