Why nifty always can be rendered in the top of the screen

TestNiftyGui test class, why nifty always can be rendered in the top of the screen,in debug nifty 、StatsView Always first is displayed.

I want to know the nifty, rootnode, guinode rendering order.

RenderManager.render(float tpf, boolean mainFrameBufferActive) {

if (renderer instanceof NullRenderer) {

return;

}



this.shader = renderer.getCaps().contains(Caps.GLSL100);



for (int i = 0; i < preViewPorts.size(); i++) {

ViewPort vp = preViewPorts.get(i);

if (vp.getOutputFrameBuffer() != null || mainFrameBufferActive){

renderViewPort(vp, tpf);

}

}

for (int i = 0; i < viewPorts.size(); i++) {

ViewPort vp = viewPorts.get(i);

if (vp.getOutputFrameBuffer() != null || mainFrameBufferActive){

renderViewPort(vp, tpf);

}

}

for (int i = 0; i < postViewPorts.size(); i++) {

ViewPort vp = postViewPorts.get(i);

if (vp.getOutputFrameBuffer() != null || mainFrameBufferActive){

renderViewPort(vp, tpf);

}

}

}

}

rootnode in viewport ,guinode and nifty in postviewport ,I think, in accordance with the above order, box which in rootnode should first be rendering. But, the result is shown below:

http://i.imgur.com/D6ISE.png

The box did not appear,Until the second rendering cycle

http://i.imgur.com/6jf9t.png



what happen in SceneProcessor.postQueue


>nifty.render
>currentScreen.renderLayers()
>renderQuad()
and display.update()

It looks like there is the

rootNode and then the guiNode rendered in that order from bassed off experience and what this page indicates:http://code.google.com/p/jmonkeyengine/source/browse/branches/jme3/src/core/com/jme3/app/SimpleApplication.java?r=5894



How ever I fail to find definitive proof of when the nodes are actually attached to the application window… or how…

Also http://hub.jmonkeyengine.org/groups/gui/forum/topic/how-to-add-a-3d-screen-in-nifty?topic_page=2&num=15#post-158606

You control the order by using viewports. The root node is attached to a main viewport while the guinode is attached to a post viewport. Nifty is added as a scene processor to the post viewport and it renders before the scene node is rendered for the viewport its attached to.