#include #include #include using namespace std; typedef unsigned char uchar; void disp(void); void drawAxis(void); void keyb(uchar key, int x, int y); int main(int argc,char **argv){ glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutCreateWindow("Axis4"); glClearColor(0.0,0.0,0.0,0.0); glutDisplayFunc(disp); glutKeyboardFunc(keyb); glutMainLoop(); } void disp(void){ glClear(GL_COLOR_BUFFER_BIT); drawAxis(); // store the position glPushMatrix(); // rotate 45 degrees around the Z axis glRotatef(45,0.0,0.0,1.0); // move 0.5 in the positive X direction glTranslatef(0.5,0.0,0.0); // draw the white teapot. glColor3f(1.0,1.0,1.0); glutSolidTeapot(0.1); // return to the original position glPopMatrix(); // save the original position glPushMatrix(); // move 0.5 in the positive X direction glTranslatef(0.5,0.0,0.0); // rotate 45 degrees around the Z axis glRotatef(45,0.0,0.0,1.0); // make it a yellow one glColor3f(1.0,1.0,0.0); // this is a teapot which is FIRST rotated // and AFTER that translated. glutSolidTeapot(0.1); glPopMatrix(); glutSwapBuffers(); } void drawAxis(){ glBegin(GL_LINES); glColor3f(1.0,0.0,0.0); glVertex3f(0.0,0.0,0.0); glVertex3f(0.80,0.0,0.0); glColor3f(0.0,1.0,0.0); glVertex3f(0.0,0.0,0.0); glVertex3f(0.0,0.80,0.0); glColor3f(0.0,0.0,1.0); glVertex3f(0.0,0.0,0.0); glVertex3f(0.0,0.0,0.80); glEnd(); } void keyb(uchar k, int x, int y){ if(k == 'q'){ exit(0); } }