You're misusing the glPushMatrix
and glPopMatrix
and also not adding or performing state switches in the correct order.
In you init code you need to change it to the following.
GL11.glViewport(0, 0, width, height);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluPerspective(45.0f, (float) width / (float) height, 0.5f, 50.0f);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glShadeModel(GL_SMOOTH);
GL11.glClearColor(0f, 0.0f, 0.0f, 0.0f);
GL11.glClearDepth(1.0);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthFunc(GL11.GL_LEQUAL);
You don't have to perform state switches after the glLoadMatrix
and glLoadIdentity
though it would be better doing so. 1 The code is more readable. 2 Some things gets reset after calling glLoadIdentity
though just the stuff about and within the Matrix itself.
Then you also need to fix your Enable2D_GUI
and Disable2D_GUI
to the following.
Enable2D_GUI
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, width, height, 0f, 1f, -1f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glDisable(GL11.GL_DEPTH_TEST);
Disable2D_GUI
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_DEPTH_TEST);
Aleast of what I know you can not use the glPushMatrix
and glPopMatrix
in between glMatrixMode
and glLoadIdentity
calls. I could be mistaking Then I also added the glLoadIdentity
calls instead to reset the Matrices.