0

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);
}
bobbyrne01
  • 6,295
  • 19
  • 80
  • 150
  • By the way, that is one heck of a crazy FOV you have there; 340 degrees vertically. Humans can generally only see 135 degrees vertically (fovy = 67.5). What you have right now might be applicable for a deer or fish if it were ***horizontal*** FOV, but not a human with eyes both facing forward ;) – Andon M. Coleman Apr 19 '14 at 00:15
  • The other thing to keep in mind is that you are probably clipping your text if it's at z=0. I would consider trying a plain old orthographic projection matrix when drawing your text, with z=-1 as zNear and z=1 as zFar. You cannot get much simpler than that, and it will place z=0 at the exact middle of your depth range. Something to this effect: `glOrtho (0, width, height, 0, -1, 1);` if you expect the point (0,0) to be the top-left corner of your screen. – Andon M. Coleman Apr 19 '14 at 00:27

1 Answers1

0

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

bobbyrne01
  • 6,295
  • 19
  • 80
  • 150