PDA

View Full Version : 2D transformations



CRasterImage
02-09-2011, 10:55 PM
I am converting a 2D software rendering application to OpenGL. Treating all drawn points with a Z value of 0 and using this to setup my projection matrix:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D( [my pixel dimentions] );

The existing code used a 3x3 matrix to convert the model to the display device.

For the modelview matrix, I go from the existing 3x3 matrix to opengl's 4x4 matrix.

Which cells transfer to which?

Specificly, the x, y translation parts.

m[0] m[4] m[ 8] m[12]
m[1] m[5] m[ 9] m[13]
m[2] m[6] m[10] m[14]
m[3] m[7] m[11] m[15]

I tried them in cells 8 and 9 first. It kind of worked, but didn't scale correctly as 0 and 5 changed. I read something where the author felt that the 4th column is where translation lives in a 4x4 matrix. So I tried cells 12 and 13. But now the model is nowhere to be seen.

What am I missing?

CRasterImage
02-09-2011, 11:02 PM
Nevermind, I found the problem.

In ortho2d, I had my bottom and top values reversed.

cells 12 and 13 seem to be the right places for the transformation values.