Question

Following are implementation methods of GLEventListener
For some reason, no text is shown on screen?
The rest of my level objects draw fine. (with the exception of they all being tinted red)

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);
}
Was it helpful?

Solution

I had gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); inside level.draw()
Once I moved this before my text rendering, I could see it fine.
@Andon, I'll take your other points into consideration about fov

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top