10 void reshape(int x, int y);
11 void keydown(unsigned char key, int x, int y);
12 void mouse(int bn, int st, int x, int y);
13 void motion(int x, int y);
15 static float cam_theta, cam_phi, cam_dist = 5;
16 static int prev_x, prev_y;
17 static int bnstate[8];
19 /* ----------------------------------- */
20 static struct g3d_mesh torus;
21 static struct bsptree torus_bsp;
22 /* ----------------------------------- */
24 int main(int argc, char **argv)
26 glutInit(&argc, argv);
27 glutInitWindowSize(800, 600);
28 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
29 glutCreateWindow("OpenGL test");
31 glutDisplayFunc(display);
32 glutReshapeFunc(reshape);
33 glutKeyboardFunc(keydown);
35 glutMotionFunc(motion);
48 glEnable(GL_DEPTH_TEST);
49 glEnable(GL_CULL_FACE);
50 glEnable(GL_LIGHTING);
53 gen_torus_mesh(&torus, 1.0, 0.25, 24, 12);
56 if(bsp_add_mesh(&torus_bsp, &torus) == -1) {
57 fprintf(stderr, "failed to construct torus BSP tree\n");
68 destroy_bsp(&torus_bsp);
76 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
78 glMatrixMode(GL_MODELVIEW);
80 glTranslatef(0, 0, -cam_dist);
81 glRotatef(cam_phi, 1, 0, 0);
82 glRotatef(cam_theta, 0, 1, 0);
84 glGetFloatv(GL_MODELVIEW_MATRIX, mat);
89 //g3d_draw_indexed(torus.prim, torus.varr, torus.vcount, torus.iarr, torus.icount);
90 draw_bsp(&torus_bsp, vdir[0], vdir[1], vdir[2]);
95 void reshape(int x, int y)
97 glViewport(0, 0, x, y);
98 glMatrixMode(GL_PROJECTION);
100 gluPerspective(50, (float)x / (float)y, 0.5, 500.0);
103 void keydown(unsigned char key, int x, int y)
111 void mouse(int bn, int st, int x, int y)
115 bnstate[bn - GLUT_LEFT] = st == GLUT_DOWN ? 1 : 0;
118 void motion(int x, int y)
125 if(!dx && !dy) return;
128 cam_theta += dx * 0.5;
131 if(cam_phi < -90) cam_phi = -90;
132 if(cam_phi > 90) cam_phi = 90;
136 cam_dist += dy * 0.1;
138 if(cam_dist < 0.0f) cam_dist = 0.0f;
143 /* dummy functions to allow linking with all the demo code */
144 void swap_buffers(void *buf)
148 unsigned int get_msec(void)
150 return glutGet(GLUT_ELAPSED_TIME);
153 void wait_vsync(void)