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 static unsigned int sdr_grid;
22 bool app_init(int argc, char **argv)
24 if(init_opengl() == -1) {
28 glEnable(GL_MULTISAMPLE);
31 glGetIntegerv(GL_SAMPLES, &aasamples);
32 printf("got %d samples per pixel\n", aasamples);
34 glEnable(GL_CULL_FACE);
35 glEnable(GL_DEPTH_TEST);
36 //glEnable(GL_LIGHTING);
39 Mesh::use_custom_sdr_attr = false;
41 mesh_torus = new Mesh;
42 gen_torus(mesh_torus, 1.0, 0.25, 32, 32);
44 if(!(sdr_grid = create_program_load("sdr/grid.v.glsl", "sdr/grid.p.glsl"))) {
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]);
71 glMultMatrixf(xform[0]);
73 bind_program(sdr_grid);
79 glVertex3f(-1, 0, -1);
86 assert(glGetError() == GL_NO_ERROR);
89 void app_reshape(int x, int y)
91 glViewport(0, 0, x, y);
94 mat.perspective(deg_to_rad(50), win_aspect, 0.5, 500.0);
96 glMatrixMode(GL_PROJECTION);
97 glLoadMatrixf(mat[0]);
100 void app_keyboard(int key, bool pressed)
111 void app_mouse_button(int bn, bool pressed, int x, int y)
113 bnstate[bn] = pressed;
118 void app_mouse_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;