简体   繁体   中英

Why won't my text show up?

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();
    }

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.

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();

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM