Rendering ontop of jme

Well I have a small programmpart, that renders some stuff I want to display above the scene jme renders.

it works perfectly when I just use


bla.render();
Display.update();



However trying to archive a rendering ontop of jme kinda leads me to problems, as I usually get the complete lwjgl/driver to crash or somethin similar, atleast windows comes up with a this application has crashed blabla stuff, without ANY further information, then the obvious, that it crashed.

My guess in jme2 would be to save the current state of states(better formulation anyone ?)
apply a default one,
render my stuff,
reapply the stored state of states

at the end of the render function.
However jme3 no longer works directly with states so where can I start here?
I think it is possible, since nifty does more or less the same as far as I understood, however I don't really get how the nifty binding works internally :/

Any help would be appreciated

How exactly are you rendering your stuff?

There's a very limited amount of things that could cause such a serious crash…

Well honestly I have no Idea, how it is rendering internally, however I was able to trace all the jme code over the rendermanager through the renderque, materials, ect down to the lwjglrenderer,



if I comment out:

drawTriangleList(indices, mesh, count);

in the method renderMeshDefault(Mesh mesh, int lod, int count)

it is not crashing anymore (however it only renders a black square)



if I comment

renderMultipassLighting(shader, geom, r); in

Material.java

it is rendering one frame, however crashes after this because of false indixes in array


java.lang.ArrayIndexOutOfBoundsException: 16
   at com.jme3.renderer.IDList.moveToNew(IDList.java:26)
   at com.jme3.renderer.lwjgl.LwjglRenderer.setTexture(LwjglRenderer.java:1395)
   at com.jme3.material.Material.render(Material.java:472)
   at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:250)
   at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:100)
   at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:142)
   at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:362)
   at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:490)
   at com.jme3.renderer.RenderManager.render(RenderManager.java:504)
   at com.jme3.app.SimpleApplication.update(SimpleApplication.java:165)
   at de.TWL.update(TWL.java:46)
   at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:112)
   at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:162)
   at java.lang.Thread.run(Unknown Source)




I will now try to do the same for the stuff  want to render, maybe then my descriptions will help you helping me :)

Ok, found it, it is calling:
GL11.glCallList(id);
wich causes the crashsome how.

id is given a value in the constructor of the element with:
this.id = GL11.glGenLists(1);

the returned id is != 0, so it appears to be succesfulll according to google.

I also get at no point glgetErrors other than 0, it just crashes instantly when the error seems to occur.

Ok, I found the solution, buggy graficcard driver … just had to update and now it gives no crashes at all.



Stays the question how to render stuff ontop of jme the right way? I guess jsut calling gl functions and draw stuff directly is not the way it is supposed to do (also it is invisible as long as jme calls the Display.update())



I guess I have something like Nifty to do with using a SceneProcessor, however I have serious problems to understand the general concept. It would be great if anyone could hint me in a  direction here?



Thanks to anyone spending time to read all my stuff :slight_smile:

NiftyGui uses jME3 as back-end, not OpenGL. Since the code you run is using OpenGL, it changes the state, and that might cause rendering issues.

Why do you need to do this?

WEll basically when I understand jme3 basics more I want to write a TWL-Gui/JME3 binding, as Nifty being cool in not limiting designers to coder stuff, is not entirely what i need, since I need a gui that is widget based, because I don't know how all stuff is designed before I have some user input.



JME3 seems to have no problems with me using opengl commands (elephant looks fine) , however the gui has problems with jme3 controlling the whole render system(it is invisible as long as jme is controlling the rendering . Basically I probably just need the right direction to plug it in, kinda like just before Display.update() is called.



What I thought of as a solution might be to use a FBO to render the GUI onto, wich then in JME3 can be used as a textured quad, as then I have as least as possible interaction points between jme and twl.



http://twl.l33tlabs.org/

The best solution here is, to write a TWL renderer that uses jME3, in the same way that the NiftyGui renderer is made.

If thats not possible, you might have to reset some OpenGL state before rendering TWL. For example, disabling shaders would be a start.

I would say it is already doing that nearly I only have to set all attributes for a default glstate before.

One question here is will jme have problems with this or is it setting anything to the needed values anyway?



/**
     * Setup GL to start rendering the GUI. It assumes default GL state.
     */
    public void startRenderering() {
        hasScissor = false;
        tintStack = tintStateRoot;
       
        GL11.glPushAttrib(GL11.GL_ENABLE_BIT|GL11.GL_TRANSFORM_BIT|GL11.GL_HINT_BIT|
                GL11.GL_COLOR_BUFFER_BIT|GL11.GL_SCISSOR_BIT|GL11.GL_LINE_BIT|GL11.GL_TEXTURE_BIT);
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPushMatrix();
        GL11.glLoadIdentity();
        GL11.glOrtho(0, width, height, 0, -1.0, 1.0);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glPushMatrix();
        GL11.glLoadIdentity();
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_LINE_SMOOTH);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
    }

Empire Phoenix said:

I would say it is already doing that nearly I only have to set all attributes for a default glstate before.
One question here is will jme have problems with this or is it setting anything to the needed values anyway?


/**
     * Setup GL to start rendering the GUI. It assumes default GL state.
     */
    public void startRenderering() {
        hasScissor = false;
        tintStack = tintStateRoot;
       
        GL11.glPushAttrib(GL11.GL_ENABLE_BIT|GL11.GL_TRANSFORM_BIT|GL11.GL_HINT_BIT|
                GL11.GL_COLOR_BUFFER_BIT|GL11.GL_SCISSOR_BIT|GL11.GL_LINE_BIT|GL11.GL_TEXTURE_BIT);
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPushMatrix();
        GL11.glLoadIdentity();
        GL11.glOrtho(0, width, height, 0, -1.0, 1.0);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glPushMatrix();
        GL11.glLoadIdentity();
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glEnable(GL11.GL_LINE_SMOOTH);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glDisable(GL11.GL_LIGHTING);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
        GL11.glHint(GL11.GL_LINE_SMOOTH_HINT, GL11.GL_NICEST);
    }



Generally speaking, it is bad for the engine if some other GL code runs along it. jME relies on the GL state to remain constant, if you change it outside of jME3, you're going to invalidate jME3 representation of it. Both the engine and the 2nd GL library running will have issues.
By the way, one thing you're not doing in that method is disabling shaders, which is possible through
glUseProgram(0). You should also disable vertex buffers, if I recall glBindBuffer(GL_VERTEX_BUFFER, 0) or similar.