GL11 3D World Render Problems.

Started by Caironater, October 25, 2011, 01:45:48

Previous topic - Next topic

Caironater

Am I forgetting some vital thing here?
As far as i can see, it *should* render, but all I'm getting is the GL clear colour.
import org.lwjgl.opengl.GL11;

public class RenderManager
{
	public RenderManager()
	{
	}
	
	public void render()
	{
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
		EntityPlayer player = getPlayer();
		if (getIsInGame() && player != null)
		{
			GL11.glPushMatrix();
			{
				GL11.glTranslated(player.posX, player.posY, player.posZ);
				GL11.glRotatef((float)player.pitch, 1.0F, 0.0F, 0.0F);
				GL11.glRotatef((float)player.yaw, 0.0F, 1.0F, 0.0F);
				GL11.glRotatef((float)player.roll, 0.0F, 0.0F, 1.0F);
				
				GL11.glColor3f(1.0F, 0.0F, 0.0F);

				GL11.glBegin(GL11.GL_QUADS);
				{
					GL11.glVertex3i(0, 0, 0);
					GL11.glVertex3i(1000, 0, 0);
					GL11.glVertex3i(1000, 0, 1000);
					GL11.glVertex3i(0, 0, 1000);
				}
				GL11.glEnd();
			}
			GL11.glPopMatrix();
		}
		getCurrentGui().drawGui();
	}
}

abcdef

Two things

Everytime you start the render loop you need to start from a common position. Currently everytime you translate and rotate you are just adding on to what you did before. To do this you need to glLoadIdentity() at the beginning of your loop (just after glClear is fine).

Also if you draw a large quad you may need to back up the camera so you can see it so you might want to set your initial camera position in infront of the quad, most people use a z translation at the beginning to accomplish this.

Caironater

Quote from: abcdef on October 25, 2011, 08:52:29
Two things

Everytime you start the render loop you need to start from a common position. Currently everytime you translate and rotate you are just adding on to what you did before. To do this you need to glLoadIdentity() at the beginning of your loop (just after glClear is fine).

Also if you draw a large quad you may need to back up the camera so you can see it so you might want to set your initial camera position in infront of the quad, most people use a z translation at the beginning to accomplish this.

Woo!
Adding the glLoadIdentity() fixed it. Many thanks!

Caironater

Actually...
Using glLoadIdentity(); is messing with my GUI stuff. Now the Gui's are starting to draw from the centre of the screen, instead of the lower left. I could ofcourse just retranslate it so that it's fine, but that's a bit hacky.

EDIT: After trying to glTranslate it, it appears that it is also zoomed out or something. I've moved it backwards a fair way past the edge, and it hasn't shown the other edge yet :/