How To: Create an Orthographic Projection Matrix for OpenGL

This version of the code uses the Matrix4f class from LWJGL Utils, but you can obviously use any 4×4 matrix class you’d like:

// Method to create and return a 2D orthographic projection matrix 
public Matrix4f createOrthoProjectionMatrix(float left, float right, float top, float bottom, float near, float far)
	Matrix4f m = new Matrix4f();
	m.m00 = 2.0f / (right - left);
	m.m01 = 0.0f;
	m.m02 = 0.0f;
	m.m03 = 0.0f;
	m.m10 = 0.0f;
	m.m11 = 2.0f / (top - bottom);
	m.m12 = 0.0f;
	m.m13 = 0.0f;
	m.m20 = 0.0f;
	m.m21 = 0.0f;
	m.m22 = -2.0f / (far - near);
	m.m23 = 0.0f;
	m.m30 = -(right + left  ) / (right - left  );
	m.m31 = -(top   + bottom) / (top   - bottom);
	m.m32 = -(far   + near  ) / (far   - near  );
	m.m33 = 1.0f;
	return m;

To place the origin in the bottom-left corner of the window (positive y-axis pointing upwards) you’d then create a matrix like this:

Matrix4f orthographicProjectionMatrix = createOrthoProjectionMatrix(0.0f, windowWidth, windowHeight, 0.0f, -1.0f, 1.0f);

While to place the origin in the top-left corner (positive y-axis pointing downwards) then just switch the windowHeight and 0.0f to make the line:

Matrix4f orthographicProjectionMatrix = createOrthoProjectionMatrix(0.0f, windowWidth, 0.0f, windowHeight, -1.0f, 1.0f);

As a final note, for 2D graphics sitting on z = 0.0f (you can easily have a 3D orthographic projection – for example in a CAD package) we typically specify the near and far values as -1.0f to 1.0f in a right-handed coordinate system (such as OpenGL) – putting them both as 0.0f can cause issues, so its’ best not to.

Microsoft’s IllumiRoom prototype aims for immersion

The basic idea of the IllumiRoom setup is that you tap into visual content from a console and have that content affect how a projector displays additional/augmented/related content onto the walls surrounding your TV – you’ve really got to see it to get it:

Interesting, huh? I like the idea, but… it seems a little impractical to have a projector on your coffee table. Also, to really take full advantage games would have to be created which deliberately interact with this system, which is increased developer effort, and how many people will have and use one of these devices? I really do like the idea, but I just don’t see it reaching critical mass right now. If there was a drive for people to move from buying large TVs to projectors in the first place – then maybe it would stand more of a chance of gaining high adoption, but in that case you generally clear the projection surface so it wouldn’t have to compensate for room geometry in the first place. Still, it’s a great idea and some very cool tech!

3D Projections onto Buildings

The above video is doctored a little to improve contrast and things – so it’s essentially fake, but you can see live video of the process here and here – which definitely isn’t, and is still rather impressive.

I guess they take a depth map of the building with lasers and then compensate for the angles and depth of the building geometry much like logos on sports pitches appear to be a flat and correct 2D images from the perspective of the main TV camera, but are all distorted when you look at them from another angle. They must create clipping masks for the windows and any other special features, too.

Clever stuff.