[TextRenderer] Using depth test in 2D mode

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

[TextRenderer] Using depth test in 2D mode

Djak
Hi,
is there any way to use depth test to draw text in 2D orthographic projection with TextRenderer ? I think my question may be silly :)
Actually, I use the 2D mode to draw texts associated to spheres and having the same font size, independantly of the z of the spheres or the cameras (and to get some kind of billboard).
But texts are drawn in front of all the spheres, ie :



in this shot, the sphere "choix" is the nearest sphere, so it appears bigger due of perspective.
____________



If I span camera, I can see "urgence" is drawn in front of the "choix" sphere.

I know all the matrix are affected by the beginRendering() method but do you think I must use the 3D mode of TextRender and adjust the font size from the z of the sphere and the camera ? or anyone knows a way to do that with the 2d mode of TextRender ?

Thanks in advance for any help :)
Reply | Threaded
Open this post in threaded view
|

Re: [TextRenderer] Using depth test in 2D mode

Demoscene Passivist
Administrator
When u use the default "beginRendering(int width, int height)" depth-test is implicitly disabled by TextRenderer. If u want to control depth-testing u have to use "beginRendering(int width, int height, boolean disableDepthTest)" and enable depth-testing explicitly.

edit: ... and btw when using the 2D mode of TextRenderer the text billboards all lie at 0.0 z. If u want to change the z value of ur text billboard u have to use draw3D().
Reply | Threaded
Open this post in threaded view
|

Re: [TextRenderer] Using depth test in 2D mode

Djak
Hi,
thank you :)
I tried to enable depth-test in beginRendering() but result is the same.
Here is what I'm doing :
- drawing spheres in a loop
- beginRendering(xxx, xxx, true)
- drawing text in a loop
- endRendering()

and I need depth-test to be done between spheres and texts.
Anyone knows if it's possible with 2d mode of TextRenderer ?

Thanks in advance :)
Reply | Threaded
Open this post in threaded view
|

Re: [TextRenderer] Using depth test in 2D mode

Demoscene Passivist
Administrator
>I tried to enable depth-test in beginRendering() but result is the same.

Sure, the result is the same. Its as I stated before u have to use draw3D to give ur text a Z position. Otherwise all text rendering is handled on the same z plane resulting in the observed "overlay-ish" behavior.

>and I need depth-test to be done between spheres and texts.
>Anyone knows if it's possible with 2d mode of TextRenderer ?

I guess u misunderstand the 2D/3D mode of TextRenderer. Actually the 2D "draw(CharSequence str, int x, int y)" rendering is using "draw3D(str, x, y, 0, 1);" internally. The only difference is that 2D draw() is setting the Z coordinate of the text billboard always to 0.

So theres no real "2D mode" of TextRenderer. U can safely intermix 2D/3D text rendering methods. To get what u want u have to do the following:

setup ur normal 3d matrix stuff
draw n spheres with radius r at x,y,z
beginRendering(screenwidth, screenheight, false)
z = (individual sphere z) + r + (some fixed offset_bias)
draw3D(str, x, y, z, 1)
endRendering()

Hope that pseudo code helped a little bit to clear things up ...
Reply | Threaded
Open this post in threaded view
|

Re: [TextRenderer] Using depth test in 2D mode

Djak
Ok, thank you.
I didn't understand the importance of your words "the text billboards all lie at 0.0 z." in the depth-test process :)
If I understand well, in your solution, I need to manually compute the font size/scaling if I want the same font size for all texts ?
But it permits to draw text with screencoords instead of world coords, that's right ?
Reply | Threaded
Open this post in threaded view
|

Re: [TextRenderer] Using depth test in 2D mode

Demoscene Passivist
Administrator
>If I understand well, in your solution, I need to manually compute the font
>size/scaling if I want the same font size for all texts ?

No u don't have to do anything to get equally sized text, as u are using orthographic projection when u call beginRendering().

>But it permits to draw text with screencoords instead of world coords, that's right ?

Yep, exactly.
Reply | Threaded
Open this post in threaded view
|

Re: [TextRenderer] Using depth test in 2D mode

Djak
Ok,
I tried tke mixed solution but it doesn't work.
Some texts aren't drawn. In my exemple only texts with a z of 0.8 are drawn, I really don't know why ^_^




And depth test is not done between spheres and texts :



after span, text appears front in the nearest "big" sphere :



I may gonna stay in 3D mode and compute the scaling by myself.
Reply | Threaded
Open this post in threaded view
|

Re: [TextRenderer] Using depth test in 2D mode

Demoscene Passivist
Administrator
Hmm, strange. I guess to further investigate the issue u should submit some code here, or at least snippets.
Reply | Threaded
Open this post in threaded view
|

Re: [TextRenderer] Using depth test in 2D mode

Djak
After some tests, it seems texts are only drawn if their z is between -1, 1.
And depth test seems to not be made.
Anyone got suggestions for what I'm trying to do ?
Here :

code wrote
        gl.glPushMatrix();
        gl.glTranslatef(0, 0, 10);
        gl.glColor3f(0.5f, 0.5f, 0.5f);
       
        // Rectangle
        gl.glBegin(GL.GL_POLYGON);
        gl.glVertex3f(-0.5f, -0.5f, 0);
        gl.glVertex3f(0.5f, -0.5f, 0);
        gl.glVertex3f(0.5f, 0.5f, 0);
        gl.glVertex3f(-0.5f, 0.5f, 0);
        gl.glEnd();  
        gl.glPopMatrix();
               
        this.textRender.beginRendering(640, 480, false);
        this.textRender.draw3D("text", 50, 50, 0.5f, 1);
        this.textRender.endRendering();
text should be behind the rectangle cause it have a lower z and should'nt be drawn, but it is.
Tnahks in advance:)

The environment initialization is something like that :

code wrote
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glViewport(0, 0, 640, 480);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45, aspect, 0.1f, 10000.0f);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
...
this.textRender = new TextRenderer(new Font("Arial", Font.PLAIN, 12), true, true);
this.textRender.setColor(1, 0, 0, 1);
Reply | Threaded
Open this post in threaded view
|

Re: [TextRenderer] Using depth test in 2D mode

Demoscene Passivist
Administrator
>After some tests, it seems texts are only drawn if their z is between -1, 1.
>And depth test seems to not be made.

Just fiddled a litte bit around with ur code snipped and it seems u are right. Depth test is always ignored whatever u do. I can't really make sense to this TextRenderer behaviour.

Maybe gouessej can shed some light on these issues coz as far as I can remember he fixed some issues with the TextRenderer class a while ago.
Reply | Threaded
Open this post in threaded view
|

Re: [TextRenderer] Using depth test in 2D mode

Djak
Ok, thanks for all :)
I'll try the "full 3D mode".
Reply | Threaded
Open this post in threaded view
|

Re: [TextRenderer] Using depth test in 2D mode

Djak
I forgot to say I use JOGL 1.1.1 but same effects with JOGL2 :)