View Full Version : Unable to get a working orthographic projection

03-21-2016, 04:24 AM
I am unable to get my orthographic projection matrix to display a simple spinning triangle. It works correctly with a perspective matrix but not an orthographic one. Do the objects have to be transformed within the -1 to 1. I tried this but it still doesn't work. Here is my ortho matrix code.

// This function builds a 2D projection matrix
void mat4::BuildOrthographicMatrix(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar)
// First Column
m[0] = 2.0f/(right-left);
m[1] = 0.0f;
m[2] = 0.0f;
m[3] = 0.0f;

// Second Column
m[4] = 0.0f;
m[5] = 2.0f/(top-bottom);
m[6] = 0.0f;
m[7] = 0.0f;

// Third Column
m[8] = 0.0f;
m[9] = 0.0f;
m[10] = -2.0f/(zFar-zNear);
m[11] = 0.0f;

// Fourth Column
m[12] = -(right+left)/(right-left);
m[13] = -(top+bottom)/(top-bottom);
m[14] = -(zFar+zNear)/(zFar-zNear);
m[15] = 1.0f;

03-22-2016, 01:45 AM
Ok I figured out what was wrong. My object was tiny and in the corner. I had changed the projection but was still drawing as though it was a 3D projection with a zoomed view. I forgot objects need to be there actual size in pixels. Silly me.