Display Region Sorting

I am trying to render a weapon model as part of my HUD, using a new display region with a new camera. Here’s my code:

self.m_HudDR = base.win.makeDisplayRegion()

cam=base.makeCamera(base.win)
self.m_HudCamera = NodePath(cam)
self.m_HudCamera.node().setLens(base.camLens)

self.m_HudScene = NodePath('HUD Scene')
self.m_HudCamera.reparentTo(self.m_HudScene)

self.m_HudDR.setCamera(self.m_HudCamera)

My weapon model gets reparented to self.m_HudScene. This is where I TRY to change the region sorting, but I get the most confusing results.

base.win.getDisplayRegion(1).setSort(0)
self.m_HudDR.setSort(5)
base.win.getDisplayRegion(2).setSort(10)

Region 1 seems to be the main camera.
Region 2 seems to be the 2d render area.
Region 2’s sort won’t go higher than 10. Only if I set the hud region to 10 does it get rendered over region 1, but then it also renders over my GUI.
I say ‘seems to be’ because I’ve found that there’s about 7 regions, including my hud region, with getNumDisplayRegions().

Anyone have any ideas or a different approach? I’ve tried camera masks and bins with no luck.

I’m betting your problem is the depth buffer. If you don’t clear the depth buffer on your new display region, then everything you draw there won’t be visible if it appears to be “behind” the stuff in the main display region.

Try:

self.m_HudDR.setClearDepthActive(True)

Incidentally, you should certainly be able to change the sort order of render2d. You can check which DisplayRegion you’re looking at by calling dr.getCamera().

David

Hmmm, I did read about setClearDepthActive in the manual, should have tried it, but it could have been explained better. The manual says clearDepthActive.

Anyway, it worked, thanks.