4 void reshape(int x, int y);
5 void keypress(unsigned char key, int x, int y);
6 void mouse(int bn, int st, int x, int y);
7 void motion(int x, int y);
9 float cam_theta, cam_phi = 25, cam_dist = 8;
13 int main(int argc, char **argv)
15 glutInit(&argc, argv);
16 glutInitWindowSize(1024, 768);
17 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
18 glutCreateWindow("miniglut test");
20 glutDisplayFunc(display);
21 glutReshapeFunc(reshape);
22 glutKeyboardFunc(keypress);
24 glutMotionFunc(motion);
26 glEnable(GL_DEPTH_TEST);
27 glEnable(GL_CULL_FACE);
28 glEnable(GL_LIGHTING);
38 float lpos[] = {-1, 2, 3, 0};
39 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
41 glMatrixMode(GL_MODELVIEW);
43 glTranslatef(0, 0, -cam_dist);
44 glRotatef(cam_phi, 1, 0, 0);
45 glRotatef(cam_theta, 0, 1, 0);
47 glLightfv(GL_LIGHT0, GL_POSITION, lpos);
49 glutSolidTorus(0.3, 1, 16, 24);
50 glutSolidSphere(0.4, 16, 8);
53 glTranslatef(-2.5, 0, 0);
58 glTranslatef(2.5, -1, 0);
59 glRotatef(-90, 1, 0, 0);
60 glutSolidCone(1.1, 2, 16, 2);
65 glVertex3f(-5, -1.3, 5);
66 glVertex3f(5, -1.3, 5);
67 glVertex3f(5, -1.3, -5);
68 glVertex3f(-5, -1.3, -5);
75 void reshape(int x, int y)
77 float vsz, aspect = (float)x / (float)y;
78 glViewport(0, 0, x, y);
79 glMatrixMode(GL_PROJECTION);
81 vsz = 0.4663f * ZNEAR;
82 glFrustum(-aspect * vsz, aspect * vsz, -vsz, vsz, 0.5, 500.0);
85 void keypress(unsigned char key, int x, int y)
87 if(key == 27 || key == 'q') {
92 void mouse(int bn, int st, int x, int y)
94 int bidx = bn - GLUT_LEFT_BUTTON;
95 bnstate[bidx] = st == GLUT_DOWN;
100 void motion(int x, int y)
102 int dx = x - mouse_x;
103 int dy = y - mouse_y;
107 if(!(dx | dy)) return;
110 cam_theta += dx * 0.5;
112 if(cam_phi < -90) cam_phi = -90;
113 if(cam_phi > 90) cam_phi = 90;
117 cam_dist += dy * 0.1;
118 if(cam_dist < 0) cam_dist = 0;