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. Using two QGLShaderProgram for objects in a same 3D scene [SOLVED]

Using two QGLShaderProgram for objects in a same 3D scene [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
29 Posts 4 Posters 9.4k 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.
  • B Offline
    B Offline
    billouparis
    wrote on last edited by
    #1

    Hello,

    i have this very weird behaviour happening here. I have two different QGLShaderProgram objects in my application, a 3D scene containing 2 objects is drawn in the paintGL method. I'm using program1 to draw object1, qnd program2 to draw object2 like this:
    @
    paintGL()
    {

    program1->bind();
    drawObject1();

    program2->bind()
    drawObject2();

    }
    @
    Then object1 is correctly drawn, but nothing is drawn for object2.
    If I invert the programs but not the object drawing order like this:

    @
    paintGL()
    {

    program2->bind();
    drawObject1();

    program1->bind()
    drawObject2();

    }
    @

    then object1 is drawn with program 2, but object2 is still not drawn at all.

    If I simply want to draw object2 only, using either program1 or program2, then object2 is perfectly drawn.

    Anybody has an idea of what my problem could be?
    And yes i tried to debug the code, but when pressing F11 on the bind line, then no source code shows up, I have recompiled Qt twice with -debug option, but nothing will do.

    Thank you for your help,
    Bill

    Edit: please use @ tags for code sections; Andre

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      Does the drawObject1() function leave the the GL state in the state expected by drawObject2(). For example are you applying some transformation without pushing/popping the matrix stack correctly?

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • B Offline
        B Offline
        billouparis
        wrote on last edited by
        #3

        Hello ZapB,

        It actually does, so I think, because if I run this:
        @
        paintGL()
        {

        program1->bind();
        drawObject1();

        program2->bind()
        drawObject2();

        program1->bind()
        drawObject3();

        }
        @
        Then object 3, is drawn correctly! Driving me mad, for sure! :)

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          ZapB
          wrote on last edited by
          #4

          OK does this work?

          @
          paintGL()
          {
          program1->bind();
          drawObject1();

          program2->bind()
          drawObject3();
          

          }
          @

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

          1 Reply Last reply
          0
          • B Offline
            B Offline
            billouparis
            wrote on last edited by
            #5

            in this case I will see object1, but not object3, :)

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              ZapB
              wrote on last edited by
              #6

              Hmmm, OK then. Could you post a small compilable example that shows the problem please so that we can take a look on our own machines? The simpler the better.

              Nokia Certified Qt Specialist
              Interested in hearing about Qt related work

              1 Reply Last reply
              0
              • B Offline
                B Offline
                billouparis
                wrote on last edited by
                #7

                I wish I could, but my program is huge!
                I could try to make a simpler one though, but at least you seem to agree that my way of thinking is correct by calling the bind method twice in the same paintGL call to use different programs for different objects in my scene, right?

                now I tried to recompiled Qt (Windows XP) to be able to get the bind source code to show up when I press F11, but now I can't even recompile my entire code. The link is failing with this message:

                g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -mthreads -Wl -Wl,-subsystem,windows -o debug\ws2.exe object_script.ws2.Debug -L"d:_Personal\Progz\Qt\Qt472\lib" -lglu32 -lopengl32 -lgdi32 -luser32 -lmingw32 -lqtmaind -lQtOpenGLd4 -lQtGuid4 -lQtCored4
                mingw32-make[1]: Leaving directory D:/_Work/QTProjectsDir/WS2-build-desktop' mingw32-make: Leaving directory D:/_Work/QTProjectsDir/WS2-build-desktop'
                d:/_personal/progz/qt/qtcreator_21/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../../mingw32/bin/ld.exe: cannot find -lQtOpenGLd4
                collect2: ld returned 1 exit status
                mingw32-make[1]: *** [debug\ws2.exe] Error 1
                mingw32-make: *** [debug] Error 2
                The process "D:_Personal\Progz\Qt\qtcreator_21\mingw\bin\mingw32-make.exe" exited with code 2.
                Error while building project ws2 (target: Desktop)
                When executing build step 'Make'

                1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  ZapB
                  wrote on last edited by
                  #8

                  The reason I asked for a small example is that often the action of producing such an example actually allows you to find the bug yourself whilst going through the process.

                  Just make a simple class that inherits QGLWidget, provide a coule of very simply drawObjectN() functions and some simple shaders. See if that reproduces the problem. If it does then we can help, if not then the problem is elsewhere in your code but at least we'll know we need to dig deeper and see more of your code.

                  Wrt to your linker error, does QtOpenGLd4.lib exist on your system where the linker is looking for it?

                  Nokia Certified Qt Specialist
                  Interested in hearing about Qt related work

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    billouparis
                    wrote on last edited by
                    #9

                    Yes I agree with your statement and the small openGL program.

                    Concerning my new link issue:
                    I actually just recompile Qt several times :
                    first by calling configure -debug -opengl desktop -> but then the compilation of my application failed because it tried to open a GLES2 directory,
                    so I restart by calling
                    configure -debug -es2, but I got the same issue,
                    i called make distclean which partially failed,
                    and then recalled
                    configure -debug, and since then I have this link error.
                    I know I suck ;)

                    1 Reply Last reply
                    0
                    • Z Offline
                      Z Offline
                      ZapB
                      wrote on last edited by
                      #10

                      Before reconfiguring Qt, try doing:

                      @make confclean@

                      I'll keep an eye out for your example.

                      Nokia Certified Qt Specialist
                      Interested in hearing about Qt related work

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        billouparis
                        wrote on last edited by
                        #11

                        Thanks ZapB

                        1 Reply Last reply
                        0
                        • B Offline
                          B Offline
                          billouparis
                          wrote on last edited by
                          #12

                          Hey ZapB,
                          My first use-case was actually wrong, I spent a lot of time on this, and the use cases are as follow:
                          @
                          paintGL()
                          {

                          program1->bind();
                          drawObject1();

                          program2->bind()
                          drawObject2();

                          drawObject3();

                          }

                          then object 1 is drawn using program 1, and object 2 and object 3 are drawn using program 2. which is fine!
                          But now I have this other use case causing the issue:

                          paintGL()
                          {

                          program1->bind();
                          drawObject1();

                          program2->bind()
                          drawObject2();

                          program1->bind()
                          drawObject3();

                          }
                          @
                          then object 1 and object 3 are drawn using program1, whereas object 2 is not drawn at all.

                          It looks like the fact to return to another program (program1) before the end of paintGL function would sort of invalidate the drawing made by program2. Maybe I should add some method to force the rendering in program2, before swapping back to program1?

                          1 Reply Last reply
                          0
                          • B Offline
                            B Offline
                            billouparis
                            wrote on last edited by
                            #13

                            I tried to add some glFinish, and/or glEnd before swapping programs, but none of them helped in anyway to get my object 2 drawn.... Yes, I am Desperate!

                            1 Reply Last reply
                            0
                            • Z Offline
                              Z Offline
                              ZapB
                              wrote on last edited by
                              #14

                              Have you got anywehere with preparing the simple example yet?

                              Nokia Certified Qt Specialist
                              Interested in hearing about Qt related work

                              1 Reply Last reply
                              0
                              • B Offline
                                B Offline
                                billouparis
                                wrote on last edited by
                                #15

                                Yes i have a very simple source code to send for you this afternoon.
                                Bill

                                1 Reply Last reply
                                0
                                • B Offline
                                  B Offline
                                  billouparis
                                  wrote on last edited by
                                  #16

                                  Hello ZapB how do I send yo my source code? it's a zip file. is it possible to send it to you by mail or something?

                                  1 Reply Last reply
                                  0
                                  • B Offline
                                    B Offline
                                    billouparis
                                    wrote on last edited by
                                    #17

                                    error

                                    1 Reply Last reply
                                    0
                                    • B Offline
                                      B Offline
                                      billouparis
                                      wrote on last edited by
                                      #18

                                      In the meantime you can download it from here:
                                      http://www.mediafire.com/?bdejk5y93gr3wqv

                                      In the draw function, you will see there are four different UseCases, you can use the "define" preprocessor directive to activate each one, and see the problems occuring,

                                      Thank you,
                                      Bill

                                      1 Reply Last reply
                                      0
                                      • B Offline
                                        B Offline
                                        billouparis
                                        wrote on last edited by
                                        #19

                                        Hello ZapB, did you have time to test my source code?
                                        Thank you,
                                        Bill

                                        1 Reply Last reply
                                        0
                                        • Z Offline
                                          Z Offline
                                          ZapB
                                          wrote on last edited by
                                          #20

                                          I managed to get it built yesterday but when I ran it I got some error complaining about one of your shaders not defining some variable as a varying. I can't recall which it was at the moment. I am really busy today so I'll try to take a proper look tomorrow.

                                          Nokia Certified Qt Specialist
                                          Interested in hearing about Qt related work

                                          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