5 #include "gmath/gmath.h"
10 int win_width, win_height;
14 static float cam_theta, cam_phi;
15 static Mesh *mesh_torus;
17 static bool bnstate[16];
18 static int prev_x, prev_y;
20 bool app_init(int argc, char **argv)
22 if(init_opengl() == -1) {
26 glEnable(GL_MULTISAMPLE);
29 glGetIntegerv(GL_SAMPLES, &aasamples);
30 printf("got %d samples per pixel\n", aasamples);
32 glEnable(GL_CULL_FACE);
33 glEnable(GL_DEPTH_TEST);
34 //glEnable(GL_LIGHTING);
37 Mesh::use_custom_sdr_attr = false;
39 mesh_torus = new Mesh;
40 gen_torus(mesh_torus, 1.0, 0.25, 32, 32);
42 if(!init_backdrop()) {
57 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
60 view_mat.pre_rotate_x(deg_to_rad(cam_phi));
61 view_mat.pre_rotate_y(deg_to_rad(cam_theta));
62 view_mat.pre_translate(0, -1.65, 0);
63 glMatrixMode(GL_MODELVIEW);
64 glLoadMatrixf(view_mat[0]);
70 assert(glGetError() == GL_NO_ERROR);
73 void app_reshape(int x, int y)
75 glViewport(0, 0, x, y);
78 mat.perspective(deg_to_rad(50), win_aspect, 0.5, 500.0);
80 glMatrixMode(GL_PROJECTION);
81 glLoadMatrixf(mat[0]);
84 void app_keyboard(int key, bool pressed)
95 void app_mouse_button(int bn, bool pressed, int x, int y)
97 bnstate[bn] = pressed;
102 void app_mouse_motion(int x, int y)
109 if(!dx && !dy) return;
112 cam_theta += dx * 0.5;
115 if(cam_phi < -90) cam_phi = -90;
116 if(cam_phi > 90) cam_phi = 90;