TextRenderer - my text won't show

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

Re: TextRenderer - my text won't show

Deedee
Were you able to solve the problem.
I am having the same issue. My text just won't show. I originally wrote the code on Linux and it works just fine there but when I tried to run it on a mac the text disappeared. My initialization looks exactly like your btw.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

chakie
No. I upgraded to 2.0.2 and that took care of the issue that DebugGL had. Still no text though. I haven't tested too much more, I guess I have to come up with some own solution at some point to fix it.

But the same code works for you on Linux, but not on OSX? Perhaps the font loading is somehow brokenish on OSX? OTOH, the webstart text rendering demo worked for me, it's only in my own code that it doesn't. One other thing could be that the text renderer assumes some state that it sets somewhere (such as GL_BLEND) but which is not normally enabled.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

Deedee
I'm out of ideas. And since it doesn't give me an error I don't even know where to look anymore. Maybe I should try running it on windows and see how it behaves there.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

chakie
If you do, please let me know if it works. I'm also quite out of ideas. Fortunately I have other bigger issues to try to solve. :)
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

Deedee
I'll let you know. Hopefully I'll have something good to report soon :)
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

Deedee
In reply to this post by chakie
So the text is a part of a bigger program (of course) where I use several shader programs using several different shaders that I provide. Now I decided to write the smallest possible code (that I could think of) to render text without using any of my other stuff. I am providing the code below using Jogl 2 and OSX 10.8.4 and it works. I don't know yet why the text renderer doesn't agree with the rest of my code and I don't know why the problem doesn't occur under Linux. I haven't tried it on Windows yet. I am in the process of finding a Windows machine that supports OpenGL 3.0 or higher. I hope this code helps you and if you find out how to fix your code, please, let me know. It may solve my problem as well.

import com.jogamp.opengl.util.Animator;

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.DebugGL3;
import javax.media.opengl.GL3;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;

// for text rendering
import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.graph.curve.opengl.TextRenderer;
import com.jogamp.graph.geom.opengl.SVertex;
import com.jogamp.opengl.util.glsl.ShaderState;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;

public class MVis_TextOnly implements GLEventListener
{
        private TextRenderer tren;
        private ShaderState shaderState;
        private int fontSet = FontFactory.JAVA;
    private Font font;
       
        private GLCanvas canvas;
        private static GL3 gl;
       
        public static void main(String[] args)
        {
    new MVis_TextOnly();
        }

        public MVis_TextOnly()
        {
                Frame frame = new Frame("TextOnly");
                GLCapabilities capabilities = new GLCapabilities(GLProfile.get(GLProfile.GL3));
                canvas = new GLCanvas(capabilities);
                canvas.addGLEventListener(this);
                frame.add(canvas);
                final Animator animator = new Animator(canvas);
                frame.addWindowListener(new WindowAdapter()
                                                                {
                                                                        @Override
                                                                        public void windowClosing(WindowEvent e) {
                                                                                new Thread(new Runnable() {
                                                                                        public void run() {
                                                                                                animator.stop();
                                                                                                System.exit(0);
                                                                                        }
                                                                                }).start();
                                                                        }
                                                                });
                frame.setSize(1400, 700);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
                animator.start();
        }
       
        public void init(GLAutoDrawable drawable)
        {
                try
                {
                        drawable.setGL(new DebugGL3(drawable.getGL().getGL3()));
                        gl = drawable.getGL().getGL3();
                           
                        System.out.println("INIT GL3 IS: " + gl.getClass().getName());
                        gl.setSwapInterval(1);
                        gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
                        gl.glEnable(GL3.GL_DEPTH_TEST);
                       
                        /* -------------------- TEXTRENDERER---------------------------------------- */
                        shaderState = new ShaderState();
                        RenderState rs = RenderState.createRenderState(shaderState, SVertex.factory());
                        tren = TextRenderer.create(rs,  0);
                        tren.init(gl);
                        tren.setAlpha(gl, 1.0f);
                        tren.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
                        font = FontFactory.get(fontSet).getDefault();
                        /* --------------- END OF TEXTRENDERER -------------------------------*/
                }
                catch (Exception e)
                {
                  e.printStackTrace();
                }
        }

        public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
        {
                gl = drawable.getGL().getGL3();
                gl.glViewport(0, 0, width, height);
        }

        public void display(GLAutoDrawable drawable)
        {
                gl = drawable.getGL().getGL3();
            gl.glClear(GL3.GL_COLOR_BUFFER_BIT | GL3.GL_DEPTH_BUFFER_BIT);
           
            gl.glUseProgram(shaderState.shaderProgram().program());
            int[] size = {1, 1, 1};
            float[] position = {-10, 0, 0};
            tren.scale(gl, 0.05f*1, (0.05f*2)*1, 0.05f*1);
            tren.translate(gl, -5f+0f, 0f+0f, 0f+0f);
            tren.drawString3D(gl, font, "My Text Goes Here", position, 1, size);
            tren.resetModelview(gl);
           
                gl.glUseProgram(0);
        }
       
        public void dispose(GLAutoDrawable drawable)
        {
                gl = drawable.getGL().getGL3();
        }
}
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

chakie
I tried your test app and it works fine for me on OSX. Well, the "M" in your default text looks like crap, but I guess that's something related to the font. Great work!

I'll try to figure out what I do differently in my own app that causes the text to not work...

Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

chakie
Hm, no. My code doesn't differ much from your code, so I adapted mine to use what you have and DebugGL3 throws me this:

Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glActiveTexture(<int> 0x84C0): GL_INVALID_VALUE ( 1281 0x501),
        at javax.media.opengl.DebugGL4bc.checkGLGetError(DebugGL4bc.java:28003)
        at javax.media.opengl.DebugGL4bc.glActiveTexture(DebugGL4bc.java:11451)
        at jogamp.opengl.GLFBODrawableImpl.swapFBOImpl(GLFBODrawableImpl.java:417)
        at jogamp.opengl.GLFBODrawableImpl.swapBuffersImpl(GLFBODrawableImpl.java:369)
        at jogamp.opengl.GLDrawableImpl.swapBuffers(GLDrawableImpl.java:91)
        at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1036)
        at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:909)
        at javax.media.opengl.awt.GLCanvas$8.run(GLCanvas.java:1065)
        at javax.media.opengl.Threading.invoke(Threading.java:193)
        at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:483)
        at javax.media.opengl.awt.GLCanvas.paint(GLCanvas.java:537)
        at sun.awt.RepaintArea.paintComponent(RepaintArea.java:264)
        at sun.lwawt.LWRepaintArea.paintComponent(LWRepaintArea.java:54)
        at sun.awt.RepaintArea.paint(RepaintArea.java:240)
        at sun.lwawt.LWComponentPeer.handleJavaPaintEvent(LWComponentPeer.java:1277)
        at sun.lwawt.LWComponentPeer.handleEvent(LWComponentPeer.java:1165)
        at java.awt.Component.dispatchEventImpl(Component.java:4937)
        at java.awt.Component.dispatchEvent(Component.java:4687)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
        at java.awt.EventQueue.access$200(EventQueue.java:103)
        at java.awt.EventQueue$3.run(EventQueue.java:688)
        at java.awt.EventQueue$3.run(EventQueue.java:686)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
        at java.awt.EventQueue$4.run(EventQueue.java:702)
        at java.awt.EventQueue$4.run(EventQueue.java:700)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

The main difference really was that I did not have in my code:

         gl.glUseProgram( shaderState.shaderProgram().program() );
and
         gl.glUseProgram( 0 );

I assumed those were executed by the text renderer. Leaving them out has no effect on the error I see. As soon as I leave out the single test instance of my Text node that I use for testing this the error disappears. My other code doesn't even call glActiveTexture(), so I assume that something internal to TextRenderer pukes all over itself.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

Deedee
I am now trying to extract some ideas from this thread http://forum.jogamp.org/TextRenderer-and-VAOs-td4029530.html
I managed to make my text appear with the rest of my objects but it's not quite right yet. Some of the other objects look like they don't accept their color correctly (or the normal vector) because they show as being black. I tried to use NewtCanvasAWT instead of GLCanvas which didn't really help.
My code uses one program for 2D objects, one for 3D objects and one for texture objects. Each program has a pair of vertex and fragment shaders that it uses. I feel like the problem is switching back and forth between the different programs. I am not sure if simply calling gl.glUseProgram(x) or gl.glUseProgram(Y) is enough. Maybe I need also bind/unbind something.
I'll keep trying to change little things here and there to see if I can understand why it behaves the way it does but I think I'm done with this project for now. I'll resume work on Monday.

PS: Yeah the font is pretty ugly. I now use FontFactory.UBUNTU instead of FontFactory.JAVA and it looks much better.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

chakie
The text renderer seems to leave GL_BLEND enabled. I had weird rendering too for my own stuff that did not expect it. Try disabling it after rendering the text?
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

Deedee
It doesn't change anything for me :( I still wish it would generate an error or exception or that it will behave consistently when run under Linux. I can't really move on with my project until I fix that. Good luck to you and hopefully we'll have a solution next week.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

chakie
Yeah, but you made good progress with the test app. I'm digging a bit into the private classes in jogamp/graph/curve/opengl/, looking for that glActiveTexture() that seems to cause problems. It's a bit rocket science and highly abstracted so it's really hard to try to follow the code online using GitHub's primitive code browsing tools.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

Deedee
Here's what's been going on. On my Linux machine I had older versions of the .jar files (since January-ish). When I installed jogl on the Mac I got the newer versions (since July).
So now I tested the code on linux + newer versions and it broke. It does the same as the Mac, i.e. the code runs with no complaints at all but the text doesn't appear.
I also tested the mac with the older versions and I get the following error.

Shader status invalid: ERROR: 0:3: '' : version '110' is not supported
ERROR: 0:4: '' : #version required and missing
ERROR: 0:34: 'attribute' : syntax error syntax error

javax.media.opengl.GLException: TextRendererImpl01: Counldn't link program: ShaderProgram[id=1, linked=false, inUse=false, program: 1,
ShaderCode[id=1, type=VERTEX_SHADER, valid=false, shader: 2, source]
ShaderCode[id=1, type=FRAGMENT_SHADER, valid=false, shader: 2, source]]

and it's complaining about lines
tren.init(gl);
and
gl.glUseProgram(shaderState.shaderProgram().program());

I am not using any of my own shaders so the problem must be with the ones that the program from shaderState is using.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

LordSmoke
In reply to this post by Lili
Hello, Folks! I wanted to check in and say "Thanks" to all who have been helping LiLi and Deedee. Due to an earlier login mistake, these are, in fact, the same person. She is my graduate student who was tasked with developing a jogl shader-based library on which to build future graphic enhancements to our lab software.

That software was originally developed with Java3D and ported to the 2.0 version of that library developed here. I have been able to check in sporadically as my tight university schedule allowed only occassionally work on the port. That was pretty much completed about 18 months ago, and with additional computational coding, the program is now being used around the world. Thanks for all the help with that, too.

I am pleased to say that Lili/Deedee is now one of the experts in jogl shader-based programming in our group. But, this also means there are a limited (=0, including myself) people who can help her locally. I have been working with her on general debugging strategies, and I think we have a small example (~300 lines) that illustrates the problem with text rendering (the only known problem at this time).

I will post the code later, but the basic problem seems to be that rendering all sorts of things - lines, textures, meshes, works well. However, when the text renderer is added, it appears the last component added to the scene is not rendered. In the example I will post, if lines are rendered, then text, the text doesn't show. If text is rendered, then lines, the lines do not show. Again, without text everything we've tried displays.

That's the simple version of the problem. Lili/Deedee is currently looking at the exact location of the non-rendering when text rendering is embedded in the middle of a complex scene. Tests thus far have involved adding the text as the first or last element.

Again, thanks for everyone's help. Will post code later (after classes).

Oh, current tests all involve the latest libraries, which seem to have solved some earlier problems.

-LS
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

chakie
Sounds to me like the text renderer messes up state somehow. For me too everything more or less works (not working is due to my own lacking skills) but I have yet to see text in my own application.

If you have something that shows the problem I'm quite sure it's much easier for someone to fix, as all the small test apps that only render text seem work fine (such as the JOGL demos and unit tests).
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

LordSmoke
In reply to this post by LordSmoke
Below is the code Lili/Deedee sent me. Three files: .frag, .vert, and .java. It should render text and draw three lines. The text does not appear. I believe that if you reverse the order of rendering the text appears, but not the lines. This code worked on Linux and the older libraries, but fails in the same manner on Linux and Mac with the newer libraries. Below is also the output from an exception it occassionally (but not always) throws. I suppose it is either something really simple we are not getting or it reveals an underlying bug in the textrenderer. Either way, I am hopeful the community will spot something we haven't. -LS

======= color2D.frag

#version 150 core

in vec3 Color;

out vec4 fragmentColor;
void main(void)
{  
        fragmentColor =  vec4(Color, 1.0);
}



======= color2D.vert

#version 150 core

uniform mat4 MVP;

in vec3 position;
in vec3 color;

out vec3 Color;

void main(void)
{
        Color = color;

  gl_Position = MVP * vec4(position, 1.0) ;
}



======= MVis_Text_Axis.java

import com.jogamp.opengl.util.Animator;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.DebugGL3;
import javax.media.opengl.GL3;

import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;

// for text rendering
import com.jogamp.common.nio.Buffers;
import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.graph.curve.opengl.TextRenderer;
import com.jogamp.graph.geom.opengl.SVertex;
import com.jogamp.opengl.util.glsl.ShaderState;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;

public class MVis_Text_Axis implements GLEventListener
{
        private TextRenderer tren;
        private ShaderState shaderState;
        private int fontSet = FontFactory.UBUNTU;
    private Font font;
       
        private GLCanvas canvas;
        private static GL3 gl;
        //private static GL4bcImpl gl;
       
        private float[] vertexArray = new float[]{
                -150f, 0f, 0f,
                150f, 0f, 0f,
               
                0f, -150f, 0f,
                0f, 150f, 0f,
               
                0f, 0f, -150f,
                0f, 0f, 150f};
               
        private float[] colorArray = new float[]{
                1f, 0f, 1f,
                1f, 0f, 1f,
               
                1f, 0f, 1f,
                1f, 0f, 1f,
               
                1f, 0f, 1f,
                1f, 0f, 1f};
               
        private int iVertex2D;
        private int iFragment2D;
        private int iProgram2D;
       
        private int iPosition_2D;
        private int iColor_2D;
       
        private int iMVP_2D;
       
        private static FloatBuffer dataVertexBuffer;
        private static FloatBuffer dataColorBuffer;
       
        private static float[] MVP = new float[]{
                200f, 0f, 0f, 0f,
                0f, 200f, 0f, 0f,
                0f, 0f, -2.333333f, 149.99994f,
                0f, 0f, -1f, 350f};
       
        private static IntBuffer intBuffer;
        private static IntBuffer intVAOBuffer;
       
        private static int iVao;
       
        public static void main(String[] args)
        {
    new MVis_Text_Axis();
        }

        public MVis_Text_Axis()
        {
                Frame frame = new Frame("Text + Axis");
                GLCapabilities capabilities = new GLCapabilities(GLProfile.get(GLProfile.GL3));
                canvas = new GLCanvas(capabilities);
                canvas.addGLEventListener(this);
                frame.add(canvas);
                final Animator animator = new Animator(canvas);
                frame.addWindowListener(new WindowAdapter()
                                        {
                                                @Override
                                                public void windowClosing(WindowEvent e) {
                                                        new Thread(new Runnable() {
                                                                public void run() {
                                                                        animator.stop();
                                                                        System.exit(0);
                                                                }
                                                        }).start();
                                                }
                                        });
                frame.setSize(800, 800);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
                animator.start();
        }
       
        public void init(GLAutoDrawable drawable)
        {
                try
                {
                        drawable.setGL(new DebugGL3(drawable.getGL().getGL3()));
                        gl = drawable.getGL().getGL3();
                        //gl = (GL4bcImpl) drawable.getGL().getGL4bc();
                        System.out.println("INIT GL3 IS: " + gl.getClass().getName());
                        gl.setSwapInterval(1);
                        gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
                        gl.glEnable(GL3.GL_DEPTH_TEST);
                       
                        /* -------------------- TEXTRENDERER---------------------------------------- */
                        shaderState = new ShaderState();
                        RenderState rs = RenderState.createRenderState(shaderState, SVertex.factory());
                        tren = TextRenderer.create(rs,  0);
                        tren.init(gl);
                        tren.setAlpha(gl, 1.0f);
                        tren.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
                        font = FontFactory.get(fontSet).getDefault();
                        /* ------------------ END OF TEXTRENDERER -------------------------------*/
                       
                        iVertex2D = initVertexShader(gl, loadShaderFile("color2D.vert"));
                        iFragment2D = initFragmentShader(gl, loadShaderFile("color2D.frag"));
                        iProgram2D = initShaderProgram(gl, iVertex2D, iFragment2D);
                       
                        iMVP_2D = gl.glGetUniformLocation(iProgram2D, "MVP");
                        iPosition_2D = gl.glGetAttribLocation(iProgram2D, "position");
                        iColor_2D = gl.glGetAttribLocation(iProgram2D, "color");
                       
                        intVAOBuffer = Buffers.newDirectIntBuffer(1);
                        gl.glGenVertexArrays(1, intVAOBuffer);
                       
                        dataVertexBuffer = Buffers.newDirectFloatBuffer(18);
                        dataColorBuffer = Buffers.newDirectFloatBuffer(18);
                       
                        for (int i = 0; i < 18; i++)
                        {
                                dataVertexBuffer.put((float)vertexArray[i]);
                                dataColorBuffer.put((float)colorArray[i]);
                        }
                        dataVertexBuffer.rewind();
                        dataColorBuffer.rewind();
                       
                        iVao = intVAOBuffer.get(0);
                        gl.glBindVertexArray(iVao);
                       
                        intBuffer = Buffers.newDirectIntBuffer(2);
                        gl.glGenBuffers(2, intBuffer);

                        gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, intBuffer.get(0));
                        gl.glBufferData(GL3.GL_ARRAY_BUFFER, dataVertexBuffer.capacity() * 4, dataVertexBuffer, GL3.GL_STATIC_DRAW);
                        gl.glEnableVertexAttribArray(iPosition_2D);
                        gl.glVertexAttribPointer(iPosition_2D, 3, GL3.GL_FLOAT, false, 0, 0);
                        gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);
                       
                        gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, intBuffer.get(1));
                        gl.glBufferData(GL3.GL_ARRAY_BUFFER, dataColorBuffer.capacity() * 4, dataColorBuffer, GL3.GL_STATIC_DRAW);
                        gl.glEnableVertexAttribArray(iColor_2D);
                        gl.glVertexAttribPointer(iColor_2D, 3, GL3.GL_FLOAT, false, 0, 0);
                        gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);
                }
                catch (Exception e)
                {
                  e.printStackTrace();
                }
        }

        public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
        {
                gl = drawable.getGL().getGL3();
                gl.glViewport(0, 0, width, height);
        }

        public void display(GLAutoDrawable drawable)
        {
            gl.glClear(GL3.GL_COLOR_BUFFER_BIT | GL3.GL_DEPTH_BUFFER_BIT);
           
                gl.glUseProgram(iProgram2D);
                gl.glUniformMatrix4fv(iMVP_2D, 1, false, MVP, 0);
            gl.glBindVertexArray(iVao);
            gl.glDrawArrays(GL3.GL_LINES, 0, 6);
           
            gl.glBindVertexArray(0);
           
            gl.glUseProgram(shaderState.shaderProgram().program());
            int[] size = {1, 1, 1};
            float[] position = {-10, 0, 0};
            tren.scale(gl, 0.1f, 0.1f, 0.1f);
            tren.translate(gl, -5f+0f, 0f+0f, 0f+0f);
            tren.drawString3D(gl, font, "Text Rendering Problems", position, 1, size);
            tren.resetModelview(gl);
        }
       
        public void dispose(GLAutoDrawable drawable)
        {
                gl.glDeleteProgram(iProgram2D);
                gl.glDeleteShader(iVertex2D);
                gl.glDeleteShader(iFragment2D);
        }

        private int initVertexShader(GL3 gl, String[] vp)
        {
            int vo = gl.glCreateShader(GL3.GL_VERTEX_SHADER);
            gl.glShaderSource(vo, 1, vp, null);
            gl.glCompileShader(vo);
            printShaderlog(gl, vo);
            return vo;
        }

        private int initFragmentShader(GL3 gl, String[] fp)
        {
            int fo = gl.glCreateShader(GL3.GL_FRAGMENT_SHADER);
            gl.glShaderSource(fo, 1, fp, null);
            gl.glCompileShader(fo);
            printShaderlog(gl, fo);
            return fo;
        }

        private int initShaderProgram(GL3 gl, int vo, int fo)
        {
                int po = gl.glCreateProgram();
                if (vo > 0)
                {
                        gl.glAttachShader(po, vo);
                }
                if (fo > 0)
                {
                        gl.glAttachShader(po, fo);
                }
                gl.glBindFragDataLocation(po, 0, "fragmentColor");
                gl.glLinkProgram(po);
                gl.glValidateProgram(po);
                printProgramlog(gl, po);
                return po;
        }

        private void printShaderlog(GL3 gl, int shader)
        {
                IntBuffer intBuffer = Buffers.newDirectIntBuffer(1);
            gl.glGetShaderiv(shader, GL3.GL_INFO_LOG_LENGTH, intBuffer);
            int infoLength = intBuffer.get(0);
            if (infoLength > 1)
            {
            ByteBuffer byteBuffer = Buffers.newDirectByteBuffer(infoLength);
            gl.glGetShaderInfoLog(shader, infoLength, intBuffer, byteBuffer);
            byteBuffer.rewind();
            byte dst[] = new byte[byteBuffer.capacity()];
            byteBuffer.get(dst, 0, byteBuffer.capacity());
            String message = new String(dst);
            gl.glDeleteShader(shader);
            System.out.println(message);
            throw new IllegalStateException(message);
            }
        }

        private void printProgramlog(GL3 gl, int program)
        {
                IntBuffer intBuffer = Buffers.newDirectIntBuffer(1);
                gl.glGetProgramiv(program, GL3.GL_INFO_LOG_LENGTH, intBuffer);
                int infoLength = intBuffer.get(0);
                if (infoLength > 1)
                {
                        ByteBuffer byteBuffer = Buffers.newDirectByteBuffer(infoLength);
                        gl.glGetProgramInfoLog(program, infoLength, intBuffer, byteBuffer);
                        byteBuffer.rewind();
                        byte dst[] = new byte[byteBuffer.capacity()];
                        byteBuffer.get(dst, 0, byteBuffer.capacity());
                        String message = new String(dst);
                        gl.glDeleteProgram(program);
                        System.out.println(message);
                        throw new IllegalStateException(message);
                }
        }

        public String[] loadShaderFile(String fileName) throws IOException
        {
                String path = "/" + fileName;
                InputStream inputStream = path.getClass().getResourceAsStream(path);
                if (inputStream == null)
                {
                        throw new IllegalStateException("Can not load shader file: " + path);
                }
                StringBuffer stringBuffer = new StringBuffer();
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                for(String str = bufferedReader.readLine(); str != null; str = bufferedReader.readLine())
                {
                        stringBuffer.append(str).append('\n');
                }
                String[] result = { stringBuffer.toString() };
                inputStream.close();
                bufferedReader.close();
                return result;
        }
}


======= Exception
Exception in thread "main-AWTAnimator" java.lang.RuntimeException: javax.media.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glViewport(<int> 0x0, <int> 0x0, <int> 0x318, <int> 0x304): GL_INVALID_OPERATION ( 1282 0x502),
    at com.jogamp.common.util.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)
    at jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:100)
    at jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:205)
    at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)
    at javax.media.opengl.Threading.invoke(Threading.java:191)
    at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:483)
    at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:74)
    at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:440)
    at com.jogamp.opengl.util.Animator$MainLoop.run(Animator.java:197)
    at java.lang.Thread.run(Thread.java:662)
Caused by: javax.media.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glViewport(<int> 0x0, <int> 0x0, <int> 0x318, <int> 0x304): GL_INVALID_OPERATION ( 1282 0x502),
    at javax.media.opengl.DebugGL4bc.checkGLGetError(DebugGL4bc.java:28003)
    at javax.media.opengl.DebugGL4bc.glViewport(DebugGL4bc.java:26731)
    at jogamp.opengl.GLDrawableHelper.reshape(GLDrawableHelper.java:605)
    at jogamp.opengl.GLDrawableHelper.reshape(GLDrawableHelper.java:613)
    at javax.media.opengl.awt.GLCanvas$7.run(GLCanvas.java:1050)
    at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1034)
    at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:909)
    at javax.media.opengl.awt.GLCanvas$8.run(GLCanvas.java:1065)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:199)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:672)
    at java.awt.EventQueue.access$400(EventQueue.java:81)
    at java.awt.EventQueue$2.run(EventQueue.java:633)
    at java.awt.EventQueue$2.run(EventQueue.java:631)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:642)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

Deedee
Thank you for the posts, Professor LordSmoke. I believe I finally solved the problem using the new libraries (as of July).  
chakie, I added a VAO for the text. I bind it before the textrenderer initialization and then again before rendering the text similarly to the way I do it for the other objects. So basically I added
gl.glBindVertexArray(textVAO);
before initialization and before rendering.
Let me know if it helps you. I can also post an update of the example.
This whole time I assumed that this is taken care of since I don't specify any information for the text vertices.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

chakie
That sounds like a very strange omission? Could you please post the full working example, as I'm not really sure what the VAO is supposed to contain.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

Deedee
Here is the code. This is the same example that LordSmoke posted - axis and text.

import com.jogamp.opengl.util.Animator;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;

import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.DebugGL3;
import javax.media.opengl.GL3;

import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLProfile;
import javax.media.opengl.awt.GLCanvas;

// for text rendering
import com.jogamp.common.nio.Buffers;
import com.jogamp.graph.curve.opengl.RenderState;
import com.jogamp.graph.curve.opengl.TextRenderer;
import com.jogamp.graph.geom.opengl.SVertex;
import com.jogamp.opengl.util.glsl.ShaderState;
import com.jogamp.graph.font.Font;
import com.jogamp.graph.font.FontFactory;

public class MVis_Text_Axis implements GLEventListener
{
        private TextRenderer tren;
        private ShaderState shaderState;
        private int fontSet = FontFactory.UBUNTU;
    private Font font;
       
        private GLCanvas canvas;
        private static GL3 gl;
       
        private float[] vertexArray = new float[]{
                -150f, 0f, 0f,
                150f, 0f, 0f,
               
                0f, -150f, 0f,
                0f, 150f, 0f,
               
                0f, 0f, -150f,
                0f, 0f, 150f};
               
        private float[] colorArray = new float[]{
                1f, 0f, 1f,
                1f, 0f, 1f,
               
                1f, 0f, 1f,
                1f, 0f, 1f,
               
                1f, 0f, 1f,
                1f, 0f, 1f};
               
        private int iVertex2D;
        private int iFragment2D;
        private int iProgram2D;
       
        private int iPosition_2D;
        private int iColor_2D;
       
        private int iMVP_2D;
       
        private static FloatBuffer dataVertexBuffer;
        private static FloatBuffer dataColorBuffer;
       
        private static float[] MVP = new float[]{
                200f, 0f, 0f, 0f,
                0f, 200f, 0f, 0f,
                0f, 0f, -2.333333f, 149.99994f,
                0f, 0f, -1f, 350f};
       
        private static IntBuffer intBuffer;
        private static IntBuffer intVAOBuffer;
       
        private static int[] iVao = new int[2];
       
        public static void main(String[] args)
        {
    new MVis_Text_Axis();
        }

        public MVis_Text_Axis()
        {
                Frame frame = new Frame("Text + Axis");
                GLCapabilities capabilities = new GLCapabilities(GLProfile.get(GLProfile.GL3));
                canvas = new GLCanvas(capabilities);
                canvas.addGLEventListener(this);
                frame.add(canvas);
                final Animator animator = new Animator(canvas);
                frame.addWindowListener(new WindowAdapter()
                                        {
                                                @Override
                                                public void windowClosing(WindowEvent e) {
                                                        new Thread(new Runnable() {
                                                                public void run() {
                                                                        animator.stop();
                                                                        System.exit(0);
                                                                }
                                                        }).start();
                                                }
                                        });
                frame.setSize(800, 800);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
                animator.start();
        }
       
        public void init(GLAutoDrawable drawable)
        {
                try
                {
                        drawable.setGL(new DebugGL3(drawable.getGL().getGL3()));
                        gl = drawable.getGL().getGL3();
                        System.out.println("INIT GL3 IS: " + gl.getClass().getName());
                        gl.setSwapInterval(1);
                        gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
                        gl.glEnable(GL3.GL_DEPTH_TEST);
                       
                        intVAOBuffer = Buffers.newDirectIntBuffer(2);
                        gl.glGenVertexArrays(2, intVAOBuffer);
                       
                        iVao[0] = intVAOBuffer.get(0);
                        gl.glBindVertexArray(iVao[0]);
                       
                        /* -------------------- TEXTRENDERER---------------------------------------- */
                        shaderState = new ShaderState();
                        RenderState rs = RenderState.createRenderState(shaderState, SVertex.factory());
                        tren = TextRenderer.create(rs,  0);
                        tren.init(gl);
                        tren.setAlpha(gl, 1.0f);
                        tren.setColorStatic(gl, 0.0f, 0.0f, 0.0f);
                        font = FontFactory.get(fontSet).getDefault();
                        /* ------------------ END OF TEXTRENDERER -------------------------------*/
                       
                        gl.glBindVertexArray(0);
                       
                        iVertex2D = initVertexShader(gl, loadShaderFile("color2D.vert"));
                        iFragment2D = initFragmentShader(gl, loadShaderFile("color2D.frag"));
                        iProgram2D = initShaderProgram(gl, iVertex2D, iFragment2D);
                       
                        iMVP_2D = gl.glGetUniformLocation(iProgram2D, "MVP");
                        iPosition_2D = gl.glGetAttribLocation(iProgram2D, "position");
                        iColor_2D = gl.glGetAttribLocation(iProgram2D, "color");
                       
                        dataVertexBuffer = Buffers.newDirectFloatBuffer(18);
                        dataColorBuffer = Buffers.newDirectFloatBuffer(18);
                       
                        for (int i = 0; i < 18; i++)
                        {
                                dataVertexBuffer.put((float)vertexArray[i]);
                                dataColorBuffer.put((float)colorArray[i]);
                        }
                        dataVertexBuffer.rewind();
                        dataColorBuffer.rewind();
                       
                        iVao[1] = intVAOBuffer.get(1);
                        gl.glBindVertexArray(iVao[1]);
                       
                        intBuffer = Buffers.newDirectIntBuffer(2);
                        gl.glGenBuffers(2, intBuffer);

                        gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, intBuffer.get(0));
                        gl.glBufferData(GL3.GL_ARRAY_BUFFER, dataVertexBuffer.capacity() * 4, dataVertexBuffer, GL3.GL_STATIC_DRAW);
                        gl.glEnableVertexAttribArray(iPosition_2D);
                        gl.glVertexAttribPointer(iPosition_2D, 3, GL3.GL_FLOAT, false, 0, 0);
                        gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);
                       
                        gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, intBuffer.get(1));
                        gl.glBufferData(GL3.GL_ARRAY_BUFFER, dataColorBuffer.capacity() * 4, dataColorBuffer, GL3.GL_STATIC_DRAW);
                        gl.glEnableVertexAttribArray(iColor_2D);
                        gl.glVertexAttribPointer(iColor_2D, 3, GL3.GL_FLOAT, false, 0, 0);
                        gl.glBindBuffer(GL3.GL_ARRAY_BUFFER, 0);

                        gl.glBindVertexArray(0);
                }
                catch (Exception e)
                {
                  e.printStackTrace();
                }
        }

        public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
        {
                gl = drawable.getGL().getGL3();
                gl.glViewport(0, 0, width, height);
        }

        public void display(GLAutoDrawable drawable)
        {
            gl.glClear(GL3.GL_COLOR_BUFFER_BIT | GL3.GL_DEPTH_BUFFER_BIT);

            gl.glUseProgram(shaderState.shaderProgram().program());
            gl.glBindVertexArray(iVao[0]);
            int[] size = {1, 1, 1};
            float[] position = {-10, 0, 0};
            tren.scale(gl, 0.1f, 0.1f, 0.1f);
            tren.translate(gl, -5f+0f, 0f+0f, 0f+0f);
            tren.drawString3D(gl, font, "Text Rendering Problems", position, 1, size);
            tren.resetModelview(gl);
           
            gl.glBindVertexArray(0);
           
                gl.glUseProgram(iProgram2D);
                gl.glUniformMatrix4fv(iMVP_2D, 1, false, MVP, 0);
            gl.glBindVertexArray(iVao[1]);
            gl.glDrawArrays(GL3.GL_LINES, 0, 6);
           
            gl.glBindVertexArray(0);
        }
       
        public void dispose(GLAutoDrawable drawable)
        {
                gl.glDeleteProgram(iProgram2D);
                gl.glDeleteShader(iVertex2D);
                gl.glDeleteShader(iFragment2D);
        }

        private int initVertexShader(GL3 gl, String[] vp)
        {
            int vo = gl.glCreateShader(GL3.GL_VERTEX_SHADER);
            gl.glShaderSource(vo, 1, vp, null);
            gl.glCompileShader(vo);
            printShaderlog(gl, vo);
            return vo;
        }

        private int initFragmentShader(GL3 gl, String[] fp)
        {
            int fo = gl.glCreateShader(GL3.GL_FRAGMENT_SHADER);
            gl.glShaderSource(fo, 1, fp, null);
            gl.glCompileShader(fo);
            printShaderlog(gl, fo);
            return fo;
        }

        private int initShaderProgram(GL3 gl, int vo, int fo)
        {
                int po = gl.glCreateProgram();
                if (vo > 0)
                {
                        gl.glAttachShader(po, vo);
                }
                if (fo > 0)
                {
                        gl.glAttachShader(po, fo);
                }
                gl.glBindFragDataLocation(po, 0, "fragmentColor");
                gl.glLinkProgram(po);
                gl.glValidateProgram(po);
                printProgramlog(gl, po);
                return po;
        }

        private void printShaderlog(GL3 gl, int shader)
        {
                IntBuffer intBuffer = Buffers.newDirectIntBuffer(1);
            gl.glGetShaderiv(shader, GL3.GL_INFO_LOG_LENGTH, intBuffer);
            int infoLength = intBuffer.get(0);
            if (infoLength > 1)
            {
            ByteBuffer byteBuffer = Buffers.newDirectByteBuffer(infoLength);
            gl.glGetShaderInfoLog(shader, infoLength, intBuffer, byteBuffer);
            byteBuffer.rewind();
            byte dst[] = new byte[byteBuffer.capacity()];
            byteBuffer.get(dst, 0, byteBuffer.capacity());
            String message = new String(dst);
            gl.glDeleteShader(shader);
            System.out.println(message);
            throw new IllegalStateException(message);
            }
        }

        private void printProgramlog(GL3 gl, int program)
        {
                IntBuffer intBuffer = Buffers.newDirectIntBuffer(1);
                gl.glGetProgramiv(program, GL3.GL_INFO_LOG_LENGTH, intBuffer);
                int infoLength = intBuffer.get(0);
                if (infoLength > 1)
                {
                        ByteBuffer byteBuffer = Buffers.newDirectByteBuffer(infoLength);
                        gl.glGetProgramInfoLog(program, infoLength, intBuffer, byteBuffer);
                        byteBuffer.rewind();
                        byte dst[] = new byte[byteBuffer.capacity()];
                        byteBuffer.get(dst, 0, byteBuffer.capacity());
                        String message = new String(dst);
                        gl.glDeleteProgram(program);
                        System.out.println(message);
                        throw new IllegalStateException(message);
                }
        }

        public String[] loadShaderFile(String fileName) throws IOException
        {
                String path = "/" + fileName;
                InputStream inputStream = path.getClass().getResourceAsStream(path);
                if (inputStream == null)
                {
                        throw new IllegalStateException("Can not load shader file: " + path);
                }
                StringBuffer stringBuffer = new StringBuffer();
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
                for(String str = bufferedReader.readLine(); str != null; str = bufferedReader.readLine())
                {
                        stringBuffer.append(str).append('\n');
                }
                String[] result = { stringBuffer.toString() };
                inputStream.close();
                bufferedReader.close();
                return result;
        }
}
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer - my text won't show

chakie
Thank you!

So, simply adding Vao[0] and it works for you? How can the demos and simple apps work? Is there something that gets implicitely used somehow?

Well, I would never have figured this out. :)
1234