glPushMatrix () ;
glTranslatef(0.0f, -500.0f, 1200.0f ) ;
glRotatef ( 270.0f, 1.0f, 0.0f, 0.0f );
glColor3f ( 0.0f, 1.0f, 1.0f );
gluCylinder(quadric,10.0f,10.0f,1000.0f,32,32);
glPopMatrix();
glPushMatrix () ;
glTranslatef(0.0f, -500.0f, 1200.0f ) ;
glRotatef ( 270.0f, 0.0f, 1.0f, 0.0f );
glColor3f ( 0.0f, 1.0f, 1.0f );
gluCylinder(quadric,10.0f,10.0f,1000.0f,32,32);
glPopMatrix();
(This code draws 2 independent objects: one with rotated x-axis, the other one with rotated y-axis)
Every glPushMatrix()
call needs an correspondending glPopMatrix()
call. If you want to make 'local' transformations for one object (i.e. translate, rotate) you can simply call glPushMatrix()
, do your transformation, draw your object and call glPopMatrix()
. Then your coordinate system is finally untransformed again, and you can draw your next object.
If you don't get that, you could also use glLoadIdentity()
on your Modelview Matrix after you applied some transformations (to reset all transformations again) - but if you're using transformation related code (i.e. gluLookAt) on your ModelviewMatrix you have to do that again, after every glLoadIdentity()
call.
glLoadIdentity();
glTranslatef(0.0f, -500.0f, 1200.0f ) ;
glRotatef ( 270.0f, 1.0f, 0.0f, 0.0f );
glColor3f ( 0.0f, 1.0f, 1.0f );
gluCylinder(quadric,10.0f,10.0f,1000.0f,32,32);
glLoadIdentity();
glTranslatef(0.0f, -500.0f, 1200.0f ) ;
glRotatef ( 270.0f, 0.0f, 1.0f, 0.0f );
glColor3f ( 0.0f, 1.0f, 1.0f );
gluCylinder(quadric,10.0f,10.0f,1000.0f,32,32);