TextRenderer - my text won't show

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

TextRenderer - my text won't show

Lili
Hello. I am trying to learn jogl (with shaders) and so far I've been able to make everything I wanted work (from basic geometric shapes to 3D-scan data and animation). However now I am trying to render text and so far it's been mission impossible for me. I really need some help.
So I am trying to use the TextRenderer in jogamp.graph.curve.opengl. I initlialize the textrenderer in my init(GLAutoDrawable drawable) function as follows
gl = drawable.getGL().getGL3();
RenderState rs = RenderState.createRenderState(new ShaderState(), SVertex.factory());
tren = TextRenderer.create(rs,  0);
tren.init(gl);
tren.setAlpha(gl, 1.0f);
tren.setColorStatic(gl, 0.0f, 1.0f, 0.0f); // green
font = FontFactory.get(fontSet).getDefault();
where fontSet is FontFactory.UBUNTU and font is of type Font in jogamp.graph.font

And in my display(GLAutoDrawable drawable) I have
gl = drawable.getGL().getGL3();
gl.glClear(GL3.GL_COLOR_BUFFER_BIT | GL3.GL_DEPTH_BUFFER_BIT);
int[] size = {10, 10, 10};
float[] position = {0, 0, 0};
tren.reshapeOrtho(null,  drawable.getWidth(), drawable.getHeight(), 200f, 500.0f); tren.drawString3D(gl, font, "PLEASEEEE PRINT", position, 12, size);

When I run my code I see the window open but no text shows up. I don't have any runtime errors which means that for some reason it renderes not in the position where my camera is looking at  (which means I don't understand how to call my functions) or that it just doesn't render at all.

Thank you in advance for the help
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

Martijn
Hello,
 
you might need to add:
gl.glUseProgram(shaderState.shaderProgram().program());

to the display method before drawing drawString3D()

this way I managed to show text, however my screen gets cleared so I cant drawing anything else except the text :/ so this might not be the correct way to do it.

Regards
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

gouessej
Administrator
In reply to this post by Lili
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

Lili
In reply to this post by Martijn
Hello Martijn,

Thank you for the suggestion but it doesn't seem to work for me. I still don't see any text show up :(
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

Lili
In reply to this post by gouessej
Yes I have looked at existing examples. I ran this one
https://projectsforge.org/projects/bundles/browser/trunk/jogl-2.0-rc3/tests/src/test/java/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java
and it worked. They're a little different from what I am trying to do. For example I am using GL3 and a GLCanvas instead of GL2ES2 and GLWindow. A was actually able to change the GLWindow to a GLCanvas in the example that I ran and it still worked. I just don't even have an idea where to look for the problem in my code.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

gouessej
Administrator
Please rather use the official updated source code:
https://github.com/sgothel/jogl/blob/master/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextNewtDemo01.java

The repository you quoted is just an obsolete copy of the RC3 whereas we're at the RC11.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

Lili
Thank you. I will try the newer version. Do you have any examples that use GL3 instead of GL2ES2?
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

Martijn
Hello,

I also really can't figure out what I am doing wrong, I try to make a 2D game but as soon as I call the drawString3D methods my background stops drawing as well as my particle systems.... does it conflict with VBO's or something? but it still renders all of the other objects in my scene :/ it seems so random.

Regards
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

gouessej
Administrator
It uses some VBOs and shaders. Maybe use the "legacy" text renderer if you don't succeed in using the shader based text renderer. Several middle and high level APIs have their own library to draw text in 3D, for example LibGDX, Ardor3D and JMonkeyEngine. They have several backends based on JOGL 2.0.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

Lili
In reply to this post by Martijn
Martijn, are you using GL3 ?
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

Lili
In reply to this post by gouessej
I was finally able to make the text show up. I had a scene with 2 spheres, 1 cube and 3 lines (to show the x, y, z axis). Now I added a label to the scene but that made the cube disappear (only the cube). I don't understand why. Also for some reason it gives me a runtime error when I call textRenderer.scale and translate from inside the display() method. Right now I'm calling them from the init(). Does anyone have an idea why that may be.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

Lili
I needed to add
gl.glBindVertexArray(0);
gl.glUseProgram(0);

at the end of my init() method. Now all the objects and the text are displayed. Unfortunately I don't understand everything that's going on so I will probably run into more problems soon :(
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

gouessej
Administrator
Which runtime error did you have?

You probably had forgotten to disable your shader and to unbind your VAO in your init() method.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

Xerxes Rånby
This post was updated on .
In reply to this post by Lili
Lili wrote
I needed to add
gl.glBindVertexArray(0);
gl.glUseProgram(0);

at the end of my init() method. Now all the objects and the text are displayed. Unfortunately I don't understand everything that's going on so I will probably run into more problems soon :(
Try enable the JOGL DebugGL and TraceGL composable pipelines..
DebugGL adds a glGetError check after each opengl call.
TraceGL show in which order your code and the JOGL helper util classes issued the opengl calls.

You can enable the composable pipelines by passing two debug variables to your application:
java -Djogl.debug.DebugGL -Djogl.debug.TraceGL

I believe this will give you a better understanding what is going on.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

Lili
Thanks for the idea I have the Debug. I'll add the Trace as well.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

chakie
In reply to this post by Lili
I've also been trying to render text, but with no luck so far. The docs I've followed are from:

http://jogamp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/opengl/util/awt/TextRenderer.html

However, these docs don't mention any TextRenderer.create(rs,  0) method as used in the first post in this thread. Also my TextRenderer implementation doesn't have such a method. Perhaps I'm using an obsolete version of JOGL? When I run code using the above docs as a base I get:

Exception in thread "main-FPSAWTAnimator-Timer0" java.lang.RuntimeException: javax.media.opengl.GLException: Not a GL2 implementation
Caused by: javax.media.opengl.GLException: Not a GL2 implementation
        at javax.media.opengl.DebugGL3.getGL2(DebugGL3.java:86)
        at com.jogamp.opengl.util.awt.TextRenderer.beginRendering(TextRenderer.java:650)
        at com.jogamp.opengl.util.awt.TextRenderer.beginRendering(TextRenderer.java:405)
        at com.jogamp.opengl.util.awt.TextRenderer.beginRendering(TextRenderer.java:384)

I use GL3. The GL3bc profile is apparently not available either, and I'd prefer to stick to modernish features. Same error when using begin3DRendering() and end3DRendering().

I've also found posts like this:

http://forum.jogamp.org/curve-TextRenderer-GL3-couldn-t-link-program-td4028852.html

that also use this new API. The JOGL version I use is 2.0.2-rc12 as picked up through Maven and some repository mirror (not under my control).

Looking at a unit test I just found:

https://github.com/sgothel/jogl/blob/master/src/test/com/jogamp/opengl/test/junit/graph/demos/GPUTextRendererListenerBase01.java

I see that the TextRenderer is in fact coming from com.jogamp.graph.curve.opengl.TextRenderer. I do have that class though, so I assume that I'm looking at way obsolete docs here. Perhaps this question then boils down to: are there any recent docs online anywhere?



Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

gouessej
Administrator
This post was updated on .
chakie, you make a confusion between the legacy text renderer and the new one. The legacy renderer doesn't support GL3, I have to check that...

Edit.: This pull request would fix your bug:
https://github.com/sgothel/jogl/pull/47
It hasn't been merged yet, it might need some more work.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

chakie
Yeah, it became clear that there is a new and an old one. I can't seem to find any docs for the new one anywhere. The best I've seen so far is this example used as a test case:

http://forum.jogamp.org/file/n4029530/TestTextRendering.java

The demos in

https://github.com/sgothel/jogl/tree/master/src/test/com/jogamp/opengl/test/junit/graph/demos

also seem to use the new class, but these unit tests are exceptionally hard to follow and they also don't document the parameters. I'd rather avoid doing too much trial and error.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

chakie
Randomly using the test code from the example above and I get this:

Exception in thread "main-FPSAWTAnimator-Timer0" java.lang.RuntimeException: javax.media.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glUniform(<javax.media.opengl.GLUniformData> GLUniformData[name gcu_ColorStatic, location 1, size 1x3, count 1, data HeapFloatBuffer[pos 0, lim 3, cap 3, remaining 3; array true, direct false, r/w true: 0.0, 0.0, 1.0]]): GL_INVALID_OPERATION ( 1282 0x502),
Caused by: javax.media.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glUniform(<javax.media.opengl.GLUniformData> GLUniformData[name gcu_ColorStatic, location 1, size 1x3, count 1, data HeapFloatBuffer[pos 0, lim 3, cap 3, remaining 3; array true, direct false, r/w true: 0.0, 0.0, 1.0]]): GL_INVALID_OPERATION ( 1282 0x502),
        at javax.media.opengl.DebugGL3.checkGLGetError(DebugGL3.java:9753)
        at javax.media.opengl.DebugGL3.glUniform(DebugGL3.java:5174)
        at com.jogamp.opengl.util.glsl.ShaderState.uniform(ShaderState.java:952)
        at com.jogamp.graph.curve.opengl.Renderer.setColorStatic(Renderer.java:213)

At that point all I do is:

        renderer.init( gl );
        renderer.setAlpha( gl, color.alpha );
        renderer.setColorStatic( gl, color.red, color.green, color.blue );

where red, green and blue are [0.0f .. 1.0f].
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

gouessej
Administrator
This post was updated on .
In reply to this post by chakie
You can use the legacy text renderer with GL3bc.

Edit.: I created a bug report for this problem:
https://jogamp.org/bugzilla/show_bug.cgi?id=811
Julien Gouesse | Personal blog | Website
1234