Problems with drawing GUIs

Started by _loco_, November 14, 2015, 15:37:13

Previous topic - Next topic

_loco_

Hi. I'm making a test OpenGL game and I want to draw some GUIs to the screen that are separate from the 3D world. The 3D works fine, but the GUIs don't show up on the screen at all.

This is my basic code:

private void render() { // Called once per frame
	make3D();
	camera.useView(); // Translates the world based on the camera

	render3D(); // Draws some cubes
		
	make2D();

	render2D(); // Draws some quads onscreen
		
	Display.update();
}

public void make2D() {
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPushMatrix();
        GL11.glLoadIdentity();
        GL11.glOrtho(0, WIDTH, 0, HEIGHT, -1, 1);
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glPushMatrix();
        GL11.glLoadIdentity();
}
 
public void make3D() {
        GL11.glMatrixMode(GL11.GL_PROJECTION);
        GL11.glPopMatrix();
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glPopMatrix();
        GL11.glEnable(GL11.GL_DEPTH_TEST);
	    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        GL11.glLoadIdentity();
}


Keep in mind that I am using immediate mode for all my rendering.

(Also, if it helps at all, I am using display lists for my 3D rendering.)

Please help! I don't know why it's not working.

Andrew_3ds

In your make2D method, you call glPushMatrix() twice, and in make3D you call glPopMatrix() twice. That is not how it works; it is supposed to be used as so:
GL11.glPushMatrix(); //Tell OpenGL to start a new matrix and not modify the previous matrix
GL11.glLoadIdentity();
GL11.glOrtho(...)
GL11.glPopMatrix() //Return to the previous matrix being modified


So just change it in your make2D and make3D methods in the correct order and it should fix it.