5 void reshape(int x, int y);
6 void keypress(unsigned char key, int x, int y);
7 void mouse(int bn, int st, int x, int y);
8 void motion(int x, int y);
10 float cam_theta, cam_phi = 25, cam_dist = 8;
15 int main(int argc, char **argv)
17 glutInit(&argc, argv);
18 glutInitWindowSize(1024, 768);
19 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
20 glutCreateWindow("miniglut test");
22 glutDisplayFunc(display);
23 glutReshapeFunc(reshape);
24 glutKeyboardFunc(keypress);
26 glutMotionFunc(motion);
28 glEnable(GL_DEPTH_TEST);
29 glEnable(GL_CULL_FACE);
30 glEnable(GL_LIGHTING);
45 float lpos[] = {-1, 2, 3, 0};
47 tm = glutGet(GLUT_ELAPSED_TIME);
49 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
51 glMatrixMode(GL_MODELVIEW);
53 glTranslatef(0, 0, -cam_dist);
54 glRotatef(cam_phi, 1, 0, 0);
55 glRotatef(cam_theta, 0, 1, 0);
57 glLightfv(GL_LIGHT0, GL_POSITION, lpos);
61 glRotatef(tm / 10.0f, 1, 0, 0);
62 glRotatef(tm / 10.0f, 0, 1, 0);
64 glutSolidTorus(0.3, 1, 16, 24);
67 glutSolidSphere(0.4, 16, 8);
70 glTranslatef(-2.5, 0, 0);
75 glTranslatef(2.5, -1, 0);
76 glRotatef(-90, 1, 0, 0);
77 glutSolidCone(1.1, 2, 16, 2);
82 glVertex3f(-5, -1.3, 5);
83 glVertex3f(5, -1.3, 5);
84 glVertex3f(5, -1.3, -5);
85 glVertex3f(-5, -1.3, -5);
92 void reshape(int x, int y)
94 float vsz, aspect = (float)x / (float)y;
95 glViewport(0, 0, x, y);
96 glMatrixMode(GL_PROJECTION);
98 vsz = 0.4663f * ZNEAR;
99 glFrustum(-aspect * vsz, aspect * vsz, -vsz, vsz, 0.5, 500.0);
102 void keypress(unsigned char key, int x, int y)
112 glutIdleFunc(anim ? idle : 0);
118 void mouse(int bn, int st, int x, int y)
120 int bidx = bn - GLUT_LEFT_BUTTON;
121 bnstate[bidx] = st == GLUT_DOWN;
126 void motion(int x, int y)
128 int dx = x - mouse_x;
129 int dy = y - mouse_y;
133 if(!(dx | dy)) return;
136 cam_theta += dx * 0.5;
138 if(cam_phi < -90) cam_phi = -90;
139 if(cam_phi > 90) cam_phi = 90;
143 cam_dist += dy * 0.1;
144 if(cam_dist < 0) cam_dist = 0;