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;
}
Ok, Ive done some more testing to try and get this resolved and after reading some threads on the use of glOrtho I have rewritten the matrix code and sort of got it working.
//mProjectionMatrix.BuildOrthographicMatrix(-1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 50.0f); // WORKS (ISH)
mProjectionMatrix.BuildOrthographicMatrix(0.0f, 800.0f, 600.0f, 0.0f, 1.0f, 50.0f); // TESTING
The first line display my rotating triangle which stretches to the boundaries of the window as it rotates. Not exactly what I want - but at least something displays!
The second line is really what I’m looking for but unfortunately nothing appears in the window.
Any ideas on what I’m doing wrong?
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.