5 #include "gmath/gmath.h"
11 int win_width, win_height;
15 static float cam_theta, cam_phi;
16 static Mesh *mesh_torus;
17 static Texture *tex_grid;
19 static bool bnstate[16];
20 static int prev_x, prev_y;
22 static unsigned int sdr_grid;
24 bool app_init(int argc, char **argv)
26 if(init_opengl() == -1) {
30 glEnable(GL_MULTISAMPLE);
33 glGetIntegerv(GL_SAMPLES, &aasamples);
34 printf("got %d samples per pixel\n", aasamples);
36 glEnable(GL_CULL_FACE);
37 glEnable(GL_DEPTH_TEST);
38 //glEnable(GL_LIGHTING);
41 Mesh::use_custom_sdr_attr = false;
43 mesh_torus = new Mesh;
44 gen_torus(mesh_torus, 1.0, 0.25, 32, 32);
46 if(!(sdr_grid = create_program_load("sdr/grid.v.glsl", "sdr/grid.p.glsl"))) {
49 if(!(tex_grid = load_texture("data/purple_grid.png"))) {
63 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
66 view_mat.pre_rotate_x(deg_to_rad(cam_phi));
67 view_mat.pre_rotate_y(deg_to_rad(cam_theta));
68 view_mat.pre_translate(0, -1.65, 0);
69 glMatrixMode(GL_MODELVIEW);
70 glLoadMatrixf(view_mat[0]);
77 glMultMatrixf(xform[0]);
79 bind_program(sdr_grid);
80 bind_texture(tex_grid);
87 glVertex3f(-1, 0, -1);
96 assert(glGetError() == GL_NO_ERROR);
99 void app_reshape(int x, int y)
101 glViewport(0, 0, x, y);
104 mat.perspective(deg_to_rad(50), win_aspect, 0.5, 500.0);
106 glMatrixMode(GL_PROJECTION);
107 glLoadMatrixf(mat[0]);
110 void app_keyboard(int key, bool pressed)
121 void app_mouse_button(int bn, bool pressed, int x, int y)
123 bnstate[bn] = pressed;
128 void app_mouse_motion(int x, int y)
135 if(!dx && !dy) return;
138 cam_theta += dx * 0.5;
141 if(cam_phi < -90) cam_phi = -90;
142 if(cam_phi > 90) cam_phi = 90;