I've seen topics posted elsewhere about doing a 2D HUD in OpenGL using the orthogonal perspective but I'm having trouble doing it in Java using JOGL.
Here is what I have so far...
These are my two methods for switching into and out of the orthogonal mode:
public void switchToOrtho(GLAutoDrawable drawable)
{
GL2 gl = drawable.getGL().getGL2();
gl.glDisable(GL2.GL_DEPTH_TEST);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glOrthof(0, drawable.getWidth(), 0, drawable.getHeight(), -1, 1);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void switchBackToFrustum(GLAutoDrawable drawable)
{
GL2 gl = drawable.getGL().getGL2();
gl.glEnable(GL2.GL_DEPTH_TEST);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glPopMatrix();
gl.glMatrixMode(GL2.GL_MODELVIEW);
}
Then I put this code inside my display method:
switchToOrtho(drawable);
gl.glBegin(GL2.GL_QUADS); // Begin drawing quads
gl.glVertex2f(0.0f, 100.0f); // Top left vertex
gl.glVertex2f( 100.0f, 100.0f); // Top right vertex
gl.glVertex2f( 100.0f,0.0f); // Bottom right vertex
gl.glVertex2f(0.0f,0.0f); // Bottom left vertex
gl.glEnd(); // Finish drawing quads
switchBackToFrustum(drawable);
However, nothing displays - if I put a TextRenderer in there and draw text, though, that displays correctly.
Does anyone have any ideas what the problem is?
Thanks,
David
Ps: Whoops, I didn't realize that this was the same overall forum as the NeHe category where I also posted this. A moderator can delete that one.
[color="red"]EDIT: Someone else saw the problem with my code - apparently, I just needed to draw the vertices in reverse order.