RenderViewPortRaw() vs. GUI

Hi guys,

for my game I need to render a grid on the terrain but I do still need to see the gui over it. I don’t really know how to achieve this since the grid needs to be rendered raw (or it won’t be visible) but I still want the gui to be over it.

code:

@Override
    public void postRender(){
        if(app.getNifty() != null && app.getNifty().getCurrentScreen().getScreenId().equals("hud_build") && app.getNifty().getCurrentScreen().findElementById("buildLayerAction").isVisible()){
            app.getRenderManager().setForcedMaterial(wireframeMat);
            app.getRenderManager().renderViewPortRaw(app.getClientMap().getWireframeViewPort());
            app.getRenderManager().setForcedMaterial(null);
        }           
    }

Screenshot (the nifty panel is in the upper left corner, I will add more content when I solved this problem)

Imgur

Thank you in advance :slight_smile:

Perhaps put the whole Nifty GUI in another transparent viewport layered on top of the main one? Viewports seems to be an answer to any question today it seems.

1 Like

One question… why render the grid on the terrain in a separate viewport instead of the man one?

One question… why render the grid on the terrain in a separate viewport instead of the man one?

The grid is only visible if you enter the building mode (to place buildings and stuff^^). So I created a material for the grid that is laid over the normal terrain material. Somewhere in the forum I read that a thread about someone trying to do the same and he was recommended to do it that way.

You could add the grid to the main scene, too… depending on how you are doing the grid.

I have the wireframeViewPort that has only the terrain attached and is disabled by default. When the player enters build mode the code you can see above is executed, the viewport is not enabled anywhere else. If I would add it to the main scene, wouldn’t it be hard to specify when it should be rendered and when not? I wouldn’t really know how to do it at least without enabling and disabling it over and over again.

I thought the problem might be renderViewPortRaw() since it is not notifying the scene processor. But there must be a way, actually the default jme stats are blocking the grid from being rendered under them… Them exactly what I want to achieve.

It depends on what you mean by “when”. “When” as in only when you want it enabled? Only attach it when you want it renderred. “When” as in a what point during the frame? Put it in the translucent bucket so that it’s rendered last in the frame. Or setup a custom comparator.

As to the other, I don’t know how nifty sets up its viewport… whether its a main viewport or a post viewport. Might be you have to make sure your viewport is added first. Might be nfity is not using a viewport and uses some other hack.

The source code is available. I don’t paid enough to look at nifty integration anymore. :slight_smile:

Okay, I found a solution, may not be the nicest one but it does not have any impact on the performance and I did not need to rebuild everything :wink:

@Override
    public void postRender(){
        if(app.getNifty() != null && app.getNifty().getCurrentScreen().getScreenId().equals("hud_build") && app.getNifty().getCurrentScreen().findElementById("buildLayerAction").isVisible()){
            app.getRenderManager().setForcedMaterial(wireframeMat);
            app.getRenderManager().renderViewPortRaw(app.getClientMap().getWireframeViewPort());           
            app.getRenderManager().setForcedMaterial(null);

            for(SceneProcessor proc : app.getGuiViewPort().getProcessors())
                if(proc instanceof NiftyJmeDisplay){
                    proc.postQueue(null);
                }
        }  
    }

Works like a charm <3 Thanks guys :slight_smile:

1 Like