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. Qt3D sort policy (C++)

Qt3D sort policy (C++)

Scheduled Pinned Locked Moved Unsolved Game Development
5 Posts 2 Posters 2.0k 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
    DeadParrot
    wrote on last edited by
    #1

    Hi,

    I'm just getting started with Qt3D in C++ so bear with me. I can't figure out how to get my objects to display in proper z order (including as the camera moves). I think I want QSortPolicy::SortType::BackToFront but I can't find or guess the right code to make it work. A simple working C++ example that shows how to do this would be great.

    I'm using Qt 5.11.1 on Windows with VC++ 2017.

    The context is evaluating Qt3D as a possible replacement for OpenSceneGraph in a simulation application. So far it looks very promising but the dearth of C++ tutorials/examples is an obstacle.

    Thanks!

    1 Reply Last reply
    0
    • H Offline
      H Offline
      HappyFeet
      wrote on last edited by
      #2

      What do you mean by proper z order? The sorting becomes relevant when you have transparent objects for example. If your problem is that objects in the back are drawn over objects in the front you should enable depth tests. I think when you use the Qt3DWindow this should be enabled by default. Otherwise attach it to your framegraph using a QRenderStateSet.

      D 1 Reply Last reply
      0
      • D Offline
        D Offline
        DeadParrot
        wrote on last edited by
        #3

        Thanks for the response. By proper z order I meant that (non-transparent) objects that should be behind others appear in front as I move the camera around. I would also have assumed that depth testing would be enabled automatically but it isn't happening for my code. I'll try adding it via a QRenderStateSet as you suggest.

        If anyone knows why this isn't happening by default or has a "best practice" boilerplate example of setting up a Qt3D scene with 5.11 that would be great.

        Thanks!

        1 Reply Last reply
        0
        • H HappyFeet

          What do you mean by proper z order? The sorting becomes relevant when you have transparent objects for example. If your problem is that objects in the back are drawn over objects in the front you should enable depth tests. I think when you use the Qt3DWindow this should be enabled by default. Otherwise attach it to your framegraph using a QRenderStateSet.

          D Offline
          D Offline
          DeadParrot
          wrote on last edited by
          #4

          @HappyFeet So I found one part of the problem. I was doing setAlphaBlendingEnabled on every shape, not just those with transparency. That seems to disable the default depth testing. Using setAlphaBlendingEnabled only on shapes with alpha < 1 is better but to get correct results when transparent objects are in front of opaque objects it seems like I'm still going to need the BackToFront sort policy, but my attempts to apply that aren't working.

          Does that sound right? If so, anyone have an example of setting the sort policy in C++?

          Thanks!

          1 Reply Last reply
          0
          • H Offline
            H Offline
            HappyFeet
            wrote on last edited by
            #5

            Oops, look like my suggestion to use a render state set was not correct, sorry! I thought QSortPolicy was a render state.

            But I found this repo some time ago and it uses the sorting policy in OffscreenLayer.qml. Maybe this helps, because it implements transparency :)

            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