Question

The goal

I'm trying to implement an orthographic camera for 2D rendering with OpenGL.

The issue

Nothing is drawn to the screen.

The setup

Each frame I am updating the camera using this call:

updateCamera(&gCamera, -10.0f, 10.0f, 0.0f, 10.0f, 1.0f, -1.0f);

The updateCamera method has the following declaration:

void updateCamera(Camera* cam, float top, float bottom, float left, float right, float zFar, float zNear);

The camera struct simply has a float opm[4][4] member which represents the matrix.

The updateCamera method has the following implementation:

cam->opm[0][0] = 2.0f / (right - left);
cam->opm[1][1] = 2.0f / (top - bottom);
cam->opm[2][2] = -2.0f / (zFar - zNear);
cam->opm[3][0] = -(right + left) / (right - left);
cam->opm[3][1] = -(top + bottom) / (top - bottom);
cam->opm[3][2] = -(zFar + zNear) / (zFar - zNear);
cam->opm[3][3] = 1.0f;

Everything is drawn correctly if I use an identity matrix instead of the one above. Perhaps there is an issue in my calculation of the matrix?

Was it helpful?

Solution

The problem lies in the definition of the vertices and the call to updateCamera.

The triangle is so small that it is not drawn with those parameters.

Using the following draw call:

updateCamera(&gCamera, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f);

everything works.

OTHER TIPS

Use an identity matrix first to find out if drawing works - then add scaling and translation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top