Skip to content

Instantly share code, notes, and snippets.

@greggman
Created February 17, 2014 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greggman/9047289 to your computer and use it in GitHub Desktop.
Save greggman/9047289 to your computer and use it in GitHub Desktop.
Show GL matrix storage

this code

void printMat(const char* l) {
    float mat[16] = { 0, };
    glGetFloatv(GL_MODELVIEW_MATRIX, mat);
    printf("%s\n", l);
    printf("%f %f %f %f\n", mat[0], mat[1], mat[2], mat[3]);
    printf("%f %f %f %f\n", mat[4], mat[5], mat[6], mat[7]);
    printf("%f %f %f %f\n", mat[8], mat[9], mat[10], mat[11]);
    printf("%f %f %f %f\n", mat[12], mat[13], mat[14], mat[15]);
}

... 

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
printMat("--before--");
glTranslatef(1.0f, 2.0f, 3.0f);
printMat("--trans--");

prints this

--before--
1.000000 0.000000 0.000000 0.000000
0.000000 1.000000 0.000000 0.000000
0.000000 0.000000 1.000000 0.000000
0.000000 0.000000 0.000000 1.000000
--trans--
1.000000 0.000000 0.000000 0.000000
0.000000 1.000000 0.000000 0.000000
0.000000 0.000000 1.000000 0.000000
1.000000 2.000000 3.000000 1.000000

Showing that the storage format of matrices in GL is

xAxis.x, xAxis.y, xAxis.z, 0,
yAxis.x, yAxis.y, yAxis.z, 0,
zAxis.x, zAxis.y, zAxis.z, 0,
translation.x, translation.y, translation.z, 1    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment