If your square center is at the origin, glTranslatef then glRotatef.
To rotate about a custom center, here is the generic formula :
TranslationFromRotCenterToOrigin * RotationMatrix * TranslationFromOriginToRotCenter
which gives something in reverse order in OpenGL ( cause glTranslatef/glRotatef multiplies the current OpenGL matrix by the specified translation/rotation matrix )
glLoadIdentity();
glTranslatef( 5, 5, 5);
glTranslatef( toRotCenterX, toRotCenterY, toRotCenterZ );
glRotatef( 45, x, y, z );
glTranslatef( -toRotCenterX, -toRotCenterY, -toRotCenterZ );
Hope this helps
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…