Text Depth question

I am drawing a cursor with TriMesh in my game, it has real world coords, i don't use AbsoluteMouse.

i do the following :


float x =  MouseInput.getAbsoluteX / display.getWidth();
mouse.setLocalTranslation(new Vector3f(x,y,0.0f));


Then i draw some Textured Text, and this text is shown above my cursor. I have tryed to translate the cursor before the text ( from  camera's aspect ) and it doesn't work obviously. Is there some kind of option to set for my cursor, so that it's drawn last in depth buffer ?
Or any other solution that would work...

Spatial.setZOrder()

to what should i set it. i have tried both 0 and 1000, and it doesn't work in both cases. can you give an example ?

Try setting the ZOrder for both elements.

have tried 1 and 0 and 0 and 1 and still doesn't work…

Hm, I just noticed you're not using the ortho queue  :expressionless: In that case ZOrder doesn't do anything…



Try using ZBufferState to make it always pass the depth test

ZBufferState zbuf = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
zbuf.setFunction(ZBufferState.CF_ALWAYS);

thanks for all your help, but it still doesn't work.

i have tryed all the CF states and i have attached the ZBufferState to my cursor which is a Pyramid.



with CF_ALWAYS, the back sides of pyramid are drawn in front of front ones. and the bitmaped font iz still in front of everything…

You need to draw the cursor after the text, there's no other way to do it. If you're using a PassManager to draw your scene, make sure the cursor is created in its own pass and attached last, also you need to make sure it always passes the Z test.

i'm not using PassManager, but i'll look it up, i can't do it tonight 'cause i'm just about to go to sleep.

thanks for all the help though.

You need to get the cursor drawn last, the way to do it changes depending on what type of application framework you’re using. For BaseGame you call cursor.draw(renderer) at the end of the render method, for SimpleGame you call it at simpleRender, for SimplePassGame you use a seperate pass, and for StandardGame you render it in a GameState. Now this is another thing I dislike which I pointed out in my list of issues thread- no unified support for passes.

i did everything you told me :



here's the render method of my Game class which extends BaseGame


    protected final void render(float interpolation) {
        display.getRenderer().clearStatistics();
        display.getRenderer().clearBuffers();
        display.getRenderer().draw(rootNode);
        display.getRenderer().draw(fpsNode);
        if(showBounds) {
            Debugger.drawBounds(rootNode, display.getRenderer());
        }
        simpleRenderer();
    }



As you can see the simpleRendrer is called last. And here's my simple renderer :


    void simpleRenderer() {
        audio.render();
        display.getRenderer().draw(mouse);
    }


as you can see i draw the mouse last.

Here's how i initialize mouse in simpleInitGame


        mouse = new Pyramid("mis", 0.5f, 1.0f);
       
        MaterialState mState = display.getRenderer().createMaterialState();
        mState.setAmbient(ColorRGBA.orange);
        mouse.setRenderState(mState);
       
        ZBufferState zState = display.getRenderer().createZBufferState();
        zState.setEnabled(true);
        zState.setFunction(ZBufferState.CF_ALWAYS);
        mouse.setRenderState(zState);



i doubt i am doing something wrong, has anyone else sucseeded in drawing something over Text ?

O yeah and here's how i initialize my TextNode :


public class TekstTex {
    private static Texture          texture;
    private static TextureState     tState;
    private static AlphaState       aState;
    //private static ZBufferState     zState;
   
    static {
        texture = TextureManager.loadTexture(Game.class.getClassLoader().getResource("data/font.png"),
                Texture.MM_LINEAR, Texture.FM_LINEAR);
        tState = DisplaySystem.getDisplaySystem().getRenderer().createTextureState();
        tState.setTexture(texture);
        tState.setEnabled(true);
       
        aState = DisplaySystem.getDisplaySystem().getRenderer().createAlphaState();
        aState.setBlendEnabled(true);
        aState.setSrcFunction(AlphaState.SB_SRC_ALPHA);
        aState.setDstFunction(AlphaState.DB_ONE_MINUS_SRC_ALPHA);
        aState.setTestEnabled(true);
        aState.setTestFunction(AlphaState.TF_GREATER);
        aState.setEnabled(true);
        /*
        zState = DisplaySystem.getDisplaySystem().getRenderer().createZBufferState();
        zState.setFunction(ZBufferState.CF_EQUAL);
        zState.setEnabled(true);*/
    }
   
    public static Node createTextNode() {
        Node textNode = new Node("textNode");

        textNode.setRenderState(tState);
        textNode.setRenderState(aState);
        //textNode.setRenderState(zState);
        textNode.setLightCombineMode(LightState.OFF);
        return textNode;
    }
}

Well I definetly know it's possible because in my game the terrain draws over the text for some odd reason and I don't know how to fix it. ://

To accomplish what you are trying to do, try this:


    void simpleRenderer() {
        audio.render();
        display.renderQueue(); // <-- force queue to process, meaning the text should be drawn to the back buffer first.
        display.clearZBuffer(); // <-- clear your zbuffer, so your cursor will never fail a ztest
        display.getRenderer().draw(mouse);
    }



You may need to roll back some zbuffer state changes if you've been playing around with those.

Ah I didn't knew there was such method. This is very useful, thanks.

renanse said:

To accomplish what you are trying to do, try this:

    void simpleRenderer() {
        audio.render();
        display.renderQueue(); // <-- force queue to process, meaning the text should be drawn to the back buffer first.
        display.clearZBuffer(); // <-- clear your zbuffer, so your cursor will never fail a ztest
        display.getRenderer().draw(mouse);
    }



You may need to roll back some zbuffer state changes if you've been playing around with those.

it works now. thanks so much.
i still don't understand why is renderQueue needed when the text is drawn in root Node. before the draw(mouse).
could you explain it a bit more ?  :|

Because of how the render queue system works…  Calling draw does not mean it is immediately drawn.  Instead it is placed in a queue. The queue is normally iterated through at the end of the loop when the backbuffer is about to be shown.  Items are drawn in logically order, not necessarily in the order that draw() was called.  You can always use QUEUE_SKIP if you want to ignore the queue completely.

So if QUEUE_SKIP is used, it is drawn right away when draw() is called?

Yes.

cool, now i get it. thanks.