How do I set parallel projection?

Started by Hungry Joe, May 04, 2004, 20:12:35

Previous topic - Next topic

Hungry Joe

Hi there. Just had a really great time coding as I managed to reuse some old code and accomplish roughly what I set out to do. Normally I give up in a bad mood. Not tonight!

except...

anyone know how to set parallel projection (I'm writing something a little like populous and want it to look isometric).

this is my initGL
private void init_gl() {
		GL11.glShadeModel(GL11.GL_SMOOTH); // Enable Smooth Shading
		GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
		GL11.glClearDepth(0.0); // Depth Buffer Setup
		GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
		GL11.glDepthFunc(GL11.GL_GEQUAL); // The Type Of Depth Testing To Do
		GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix
		GL11.glLoadIdentity(); // Reset The Projection Matrix
		GL11.glEnable(GL11.GL_POINT_SMOOTH );
		// Calculate The Aspect Ratio Of The Window
		GLU.gluPerspective(45.0f, (float) Display.getWidth()
		//		/ (float) Display.getHeight(), 0.1f, 100.0f);
		GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix
		// Really Nice Perspective Calculations
		GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
		//sync to monitor
		Window.setVSyncEnabled(true);
	}


which lines do i need to change and what to? will GLU lookat still work?

thanks folks!

cfmdobbie

Parallel projections in OpenGL are defined with the glOrtho or gluOrtho2D calls.  For example:

GL11.glOrtho(0, width, 0, height, -1, 1);

This will create a parallel projection with a coordinate system running from 0 to width on the x-axis, 0 to height on the y-axis, and -1 to 1 on the z-axis.

Your glOrtho call will replace the gluPerspective call.
ellomynameis Charlie Dobbie.

Hungry Joe

I'm trying that with
GL11.glOrtho(0, (float) Display.getWidth(), 0, (float) Display.getHeight(), 0.1f, 100.0f);


and I'm getting a black screen but I havent't tinkered with it at all yet, and I've got a feeling its probably not pointing at my model. thanks veyr muych

Hungry Joe

aha! not screen width, but width of frustrum. i tried it with 4, 3 and its perfect. ta