Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. QOpenGLWindow renders in order of draw calls instead of depth(z coordinate).

QOpenGLWindow renders in order of draw calls instead of depth(z coordinate).

Scheduled Pinned Locked Moved Solved Game Development
3 Posts 2 Posters 486 Views
  • 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.
  • D Offline
    D Offline
    DaShubWubDub
    wrote on last edited by
    #1

    Hello Everyone,
    I am starting a project Design for logic based animation, and this was how far I got until the OpenGL render order continues to favor the order of draw calls instead of z position.

    Here is my source code is open source for auditing and suggestions although currently still considered proprietary.
    https://github.com/DahliaEnterprise/DahliaAnimation/blob/main/source/openglwindows.cpp

    When I swap the order of triangle and triangle two, the depth of the triangles are changed. The triangles have different z positions.

    One solution found online said they had the exact problem and they needed to create a QOpenGLContext in order for depth to register; However I attempted to use their coding solution and it make the render blank(no two triangles AND clear color was not setting the background).
    So I’m asking for a solution or how to properly create and attach a qopenglcontext that actually allows rendering.

    
    triangle_two_ogl_vao_quad.bind();
        glDrawArrays(GL_TRIANGLES, 0, 3);
    		triangle_two_ogl_vao_quad.release();
    		
        triangle_ogl_vao_quad.bind();
        glDrawArrays(GL_TRIANGLES, 0, 3);
    		triangle_ogl_vao_quad.release();
    		
    
    
    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      The problem is not with context. Well, not entirely at least.

      Although your vertex data has a x,y,z components you only take the first two in your shader and ignore the third (z): "layout(location = 0) in vec2 position;\n"
      Your shader then always writes a 0.0 depth value: "gl_Position = vec4(position, 0.0, 1.0);\n".
      You also have a depth func set to less glDepthFunc(GL_LESS);, so since everything has the same value of 0.0 whatever was drawn first will stay there, because the next 0 is no less than the previous one.

      You need to take the whole vec3 position and write the proper depth information to gl_Position.

      But yes, for all of that to work your context needs to have a valid depth buffer format in the first place. The example shows how to set it up for QOpenGLWIdget using setFormat. It's the same for QOpenGLWindow.

      D 1 Reply Last reply
      1
      • Chris KawaC Chris Kawa

        The problem is not with context. Well, not entirely at least.

        Although your vertex data has a x,y,z components you only take the first two in your shader and ignore the third (z): "layout(location = 0) in vec2 position;\n"
        Your shader then always writes a 0.0 depth value: "gl_Position = vec4(position, 0.0, 1.0);\n".
        You also have a depth func set to less glDepthFunc(GL_LESS);, so since everything has the same value of 0.0 whatever was drawn first will stay there, because the next 0 is no less than the previous one.

        You need to take the whole vec3 position and write the proper depth information to gl_Position.

        But yes, for all of that to work your context needs to have a valid depth buffer format in the first place. The example shows how to set it up for QOpenGLWIdget using setFormat. It's the same for QOpenGLWindow.

        D Offline
        D Offline
        DaShubWubDub
        wrote on last edited by
        #3

        @Chris-Kawa wow I can’t believe I missed that.
        I’m sure that is the issue, I will try this solution right away.

        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