简体   繁体   English

为什么我的文字不显示?

[英]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. 由于某种原因,我一生都无法弄清楚,JOGL hello world程序中的文本根本不会显示。 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. gluLookAt调用绝对不好:您将相机放置在(0,0,0)处并朝z = -800方向移动,但是您将文本放置在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. 我还注意到,您通常没有调用glViewport()来将场景映射到组件中。

What you have here is almost certainly a GL issue, not a JOGL issue. 您在这里所拥有的几乎可以肯定是总帐问题,而不是JOGL问题。 Have a look at the troubleshooting hints in the OpenGL Programming Guide. 查看《 OpenGL编程指南》中的故障排除提示。 If you don't have a copy, and are going to be doing any significant GL programming, I recommend you get one. 如果您没有副本,并且打算进行任何重要的GL编程,我建议您选一份。 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. 您也可以尝试在这个问题上添加opengl标记,因为这将吸引一些专业的OpenGL程序员。

I haven't used JOGL, but in OpenGL with C++, you need to swap GLUT's buffers after flushing with: 我没有使用JOGL,但是在OpenGL与C ++中,您需要在刷新后交换GLUT的缓冲区:

glutSwapBuffers();

The equivalent in JOGL would probably be: JOGL中的等效内容可能是:

glut.glutSwapBuffers();

after gl.glFlush(); 在gl.glFlush()之后;

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... 也许显示了您的文本,但与背景一样暗...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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