Render 2d and 3d objects

Hello everyone, I have a doubt and i do not know how to solve it.

I have a basicgamestatenode with a background, and attached to this state 4 other more. All this states must have this background. The problem is, basicgamesatenode has renderquemode set to ortho, but one of the states attached to it has the opaque mode, because it has a 3d object. The problem is, i have understood that the "ortho objects" are rendered after 3d ojects ("opaque objects"), so the 3d object is never viewed. How i could do to render all without problems?.



PD: i have been thinking and the easiest solution would be to transfer the background to every child, and remove the queue mode from basicgamestatenode, but i would like to learn if there would be any other "cool" solution.



Thanks to all.

 

Hi.



This is the hardcoded solution that I use many times and works fast. For it to work keep everything in the RenderQueues they are already in.



public void render() {
  orthoBackgroundNode.draw(DisplaySystem.getDisplaySystem.getRenderer());
  DisplaySystem.getDisplaySystem.getRenderer().renderQueue();

  DisplaySystem.getDisplaySystem.getRenderer().clearZBuffer(); // I don't know if this is needed, try without first.

  object3dNode.draw(DisplaySystem.getDisplaySystem.getRenderer());
  DisplaySystem.getDisplaySystem.getRenderer().renderQueue();
}


I did it but it did not work. This is the code:


MenuState parentGameState = (MenuState) this.getParent();
      parentGameState.getRootNode().getChild("bckgNode").draw(DisplaySystem.getDisplaySystem().getRenderer());//.render(tpf);
(bckgNode contains a Quad with the background image)
DisplaySystem.getDisplaySystem().getRenderer().renderQueue();

DisplaySystem.getDisplaySystem().getRenderer().clearZBuffer(); // I don't know if this is needed, try without first.

compasBox.draw(DisplaySystem.getDisplaySystem().getRenderer()); (compasBox is the 3d object)
DisplaySystem.getDisplaySystem().getRenderer().renderQueue();



Once i compile this code, the only thing i see is the background not the 3d object.

I tried with renderpasses and it works but only if the background is loaded once again at this node, if i take the parent background node, it does not work.


pManager = new BasicPassManager();
         RenderPass compasBoxPass = new RenderPass();
         RenderPass bgPass = new RenderPass();

         // first add the Background Pass to the PassManager
         pManager.add(bgPass);
         bgPass.add(bckg);
         
         // then add the main Pass to the PassManager
         pManager.add(compasBoxPass);
         compasBoxPass.add(compasBox);
               
         // update renderstates of our Nodes
         bckg.updateRenderState();      
         compasBox.updateRenderState();



In this case bckg is a quad loaded at this node. But if i change bckg for the parent node that contains the bg it does not work and render at first place the 3d object and later the bg.

Could be possible as solution to render first the child node and then the parent node? Or that is not possible to do with jme?



I solved it! The solution i have thought is, if i bring the background to child node and then i use the renderpass, it works fine (i also have to detach the background from the parent node). But i don't know if this is a good solution or it looks wrong. The code i use is this:



MenuState parentGameState = (MenuState) this.getParent();
bckg = (Quad) parentGameState.getRootNode().getChild("bckgQuad"); //bckgQuad is the bckg in the parent node
parentGameState.getRootNode().detachChildNamed("bckgQuad");

pManager = new BasicPassManager();
RenderPass compasBoxPass = new RenderPass();
RenderPass bgPass = new RenderPass();

// first add the Background Pass to the PassManager
pManager.add(bgPass);
bgPass.add(bckg);
         
// then add the main Pass to the PassManager
pManager.add(compasBoxPass);
compasBoxPass.add(compasBox); //compasBox is the 3d object
               
// update renderstates of our Nodes
bckg.updateRenderState();      
compasBox.updateRenderState();