combining glPushMatrix + glScale + glTranslate ?

hi

i feel that i am redundnantly calling these 3 seperate functions , because i always seem to do the 3 together (for obvious reasons). is there anyway these 3 calls can be combined into one?

best
james

You can compute the final matrix by ourself and use glLoadMatrix
so you have to do only

glPushMatrix();
computeMatrix(point, scaleFactor, &matrix);
glMultMatrix(matrix);
drawSomeStuff();
glPopMatrix();

You can also remove the push/popMatrix pair, but you must consider the camera transformation, so you can do something like that


glLoadMatrixf(cameraMatrix);
computeMatrix(point1, scaleFactor1, &matrix);
glMultMatrixf(matrix);
drawStuff();

glLoadMatrixf(cameraMatrix);
computeMatrix(point2, scaleFactor2, &matrix);
glMultMatrixf(matrix);
drawOtherStuff();

if you want remove the glMultMatrix you have to compute the whole matrix on CPU.

or you can create a custom shader where you pass the matrix as uniform in openGL 3.0 style. :slight_smile:

Btw, I don’t know if the matrix multiplication is hardware accelerated, I guess that the computation is simply done by the driver.