views:

917

answers:

3

For some reason which I can't figure out for the life of me, my text in my JOGL hello world program won't show up at all. I'll include the display method so you'll all know what I'm talking about.

public void display(GLAutoDrawable gLDrawable)
    {
        final GL gl = gLDrawable.getGL();
        final GLU glu = new GLU();
        GLUT glut = new GLUT();
        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
        gl.glLoadIdentity();
        glu.gluLookAt(0f,0f,0f,0f,0f,-800f,0,1,0);
        gl.glTranslatef(0.0f,0.0f,5.0f);
        gl.glColor3f(1f, 1f, 1f);

     gl.glRasterPos2f(250f,250f);

        glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, "Hello World!");

        gl.glFlush();
    }
A: 

I haven't used JOGL, but in OpenGL with C++, you need to swap GLUT's buffers after flushing with:

glutSwapBuffers();

The equivalent in JOGL would probably be:

glut.glutSwapBuffers();

after gl.glFlush();

Ankit
According to the API there's no such luck. No swap method/function at all: http://download.java.net/media/jogl/builds/nightly/javadoc_public/com/sun/opengl/util/GLUT.html
William
He isn't actually using the GLUT object, just creating it.
DJClayworth
A: 

I don't like the -800f in

glu.gluLookAt(0f,0f,0f,0f,0f,-800f,0,1,0);

try adjusting this number. Perhaps even remove the whole LookAt method call, you shouldn't need that.

Edit It could just as well be a lighting problem. You don't seem to specify any light source, nor did you enable lighting in any way. Maybe your text is displayed but simply as dark as the background...

Peter Perháč
removed and tried modifying glulookat, but problem still happens.
William
is it a text-only problem? when you render a cube, can you see it?
Peter Perháč
+1  A: 

I tried some mods on this but I can't make anything show up either.

The gluLookAt call was definitely bad: you were placing the camera at (0,0,0) and looking towards z=-800, yet you are placing your text at z=0. Clearly nothing will show up.

I also notice that you haven't called glViewport() which you should normally do, to map your scene into the component.

What you have here is almost certainly a GL issue, not a JOGL issue. Have a look at the troubleshooting hints in the OpenGL Programming Guide. If you don't have a copy, and are going to be doing any significant GL programming, I recommend you get one. I would also replace your text with a polygon drawn in the same place. When I do that nothing shows up, so it's almost certainly a matrix issue, not anything to do with your text. When you get the polygon to show up, then you can replace it with the text. Eliminate one issue at a time. You might also try adding the opengl tag to this question, since that will attract some expert OpenGL programmers.

DJClayworth