TextRenderer不显示文本

时间:2014-04-18 23:18:53

标签: java opengl jogl textrenderer

以下是GLEventListener的实施方法 出于某种原因,屏幕上没有显示文字?
我的其他级别对象绘制得很好。 (除了它们都被染成红色)

private TextRenderer renderer;

public void init(GLAutoDrawable gLDrawable) {

    GL2 gl = gLDrawable.getGL().getGL2();
    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    gl.glShadeModel(GL2.GL_SMOOTH);
    gl.glEnable(GL.GL_TEXTURE_2D);

    renderer = new TextRenderer(new Font("SansSerif", Font.BOLD, 36));
}

public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) {

    final GL2 gl = gLDrawable.getGL().getGL2();

    if (height <= 0) { // avoid a divide by zero error!

        height = 1;
    }

    final float h = (float) width / (float) height;

    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluPerspective(170.0f, h, 1.0, 20.0);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
}

public void display(GLAutoDrawable gLDrawable) {

    renderer.beginRendering(gLDrawable.getWidth(), gLDrawable.getHeight());
    renderer.setColor(1.0f, 0.2f, 0.2f, 0.8f);
    renderer.draw("Text to draw", 0, 0);
    renderer.endRendering();

    // draw squares, circles in the level etc       
    level.draw(gLDrawable);
}

1 个答案:

答案 0 :(得分:0)

gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);level.draw()了 一旦我在文本渲染之前将其移动,我就可以看到它很好 @Andon,我会考虑你对fov的其他观点