为什么我的文字不会出现?

时间:2023-01-29 21:12:33

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.

出于某种原因我无法理解我的生活,我的JOGL hello world程序中的文字根本不会显示出来。我将包括显示方法,所以你们都知道我在说什么。

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

3 个解决方案

#1


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

我尝试了一些mods,但我也无法显示任何内容。

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.

gluLookAt调用肯定是坏的:你把相机放在(0,0,0)并朝着z = -800看,但是你把文字放在z = 0。显然没有任何东西会出现。

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

我还注意到你没有调用通常应该做的glViewport()来将场景映射到组件中。

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.

你在这里几乎肯定是GL问题,而不是JOGL问题。请查看OpenGL编程指南中的故障排除提示。如果您没有副本,并且将要进行任何重要的GL编程,我建议您获得一个。我也会用在同一个地方绘制的多边形替换你的文字。当我这样做时,没有任何东西出现,所以它几乎肯定是一个矩阵问题,与你的文本没有任何关系。当您显示多边形时,可以将其替换为文本。一次消除一个问题。您也可以尝试将opengl标记添加到此问题中,因为这会吸引一些专家OpenGL程序员。

#2


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

我没有使用JOGL,但在使用C ++的OpenGL中,你需要在刷新后用以下方法交换GLUT的缓冲区:

glutSwapBuffers();

The equivalent in JOGL would probably be:

JOGL中的等价物可能是:

glut.glutSwapBuffers();

after gl.glFlush();

#3


I don't like the -800f in

我不喜欢-800f

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.

尝试调整这个数字。甚至可能删除整个LookAt方法调用,你不应该需要它。

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

编辑它也可能是一个照明问题。您似乎没有指定任何光源,也没有以任何方式启用照明。也许你的文字显示但只是像背景一样黑暗......

#1


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

我尝试了一些mods,但我也无法显示任何内容。

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.

gluLookAt调用肯定是坏的:你把相机放在(0,0,0)并朝着z = -800看,但是你把文字放在z = 0。显然没有任何东西会出现。

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

我还注意到你没有调用通常应该做的glViewport()来将场景映射到组件中。

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.

你在这里几乎肯定是GL问题,而不是JOGL问题。请查看OpenGL编程指南中的故障排除提示。如果您没有副本,并且将要进行任何重要的GL编程,我建议您获得一个。我也会用在同一个地方绘制的多边形替换你的文字。当我这样做时,没有任何东西出现,所以它几乎肯定是一个矩阵问题,与你的文本没有任何关系。当您显示多边形时,可以将其替换为文本。一次消除一个问题。您也可以尝试将opengl标记添加到此问题中,因为这会吸引一些专家OpenGL程序员。

#2


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

我没有使用JOGL,但在使用C ++的OpenGL中,你需要在刷新后用以下方法交换GLUT的缓冲区:

glutSwapBuffers();

The equivalent in JOGL would probably be:

JOGL中的等价物可能是:

glut.glutSwapBuffers();

after gl.glFlush();

#3


I don't like the -800f in

我不喜欢-800f

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.

尝试调整这个数字。甚至可能删除整个LookAt方法调用,你不应该需要它。

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

编辑它也可能是一个照明问题。您似乎没有指定任何光源,也没有以任何方式启用照明。也许你的文字显示但只是像背景一样黑暗......