2 #include "cgmath/cgmath.h"
12 int win_width, win_height;
17 float cam_theta, cam_phi, cam_dist = 10;
18 float view_matrix[16], proj_matrix[16];
24 if(init_opengl() == -1) {
28 glEnable(GL_DEPTH_TEST);
29 glEnable(GL_CULL_FACE);
31 if(!(sdr_foo = create_program_load("sdr/foo.v.glsl", "sdr/foo.p.glsl"))) {
34 glBindAttribLocation(sdr_foo, MESH_ATTR_VERTEX, "apos");
35 glBindAttribLocation(sdr_foo, MESH_ATTR_NORMAL, "anorm");
36 glBindAttribLocation(sdr_foo, MESH_ATTR_TANGENT, "atang");
37 glBindAttribLocation(sdr_foo, MESH_ATTR_TEXCOORD, "atex");
38 link_program(sdr_foo);
40 if(load_level(&lvl, "data/test.lvl") == -1) {
45 if(load_scenefile(&scn, "data/dwall1.obj") == -1) {
52 void game_shutdown(void)
55 free_program(sdr_foo);
58 void game_display(void)
62 glClearColor(0.1, 0.1, 0.1, 1);
63 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
65 cgm_midentity(proj_matrix);
66 cgm_mperspective(proj_matrix, cgm_deg_to_rad(50), win_aspect, 0.5, 500.0);
67 glMatrixMode(GL_PROJECTION);
68 glLoadMatrixf(proj_matrix);
70 cgm_midentity(view_matrix);
71 cgm_mpretranslate(view_matrix, 0, 1.5, -cam_dist);
72 cgm_mprerotate(view_matrix, cam_phi, 1, 0, 0);
73 cgm_mprerotate(view_matrix, cam_theta, 0, 1, 0);
74 glMatrixMode(GL_MODELVIEW);
75 glLoadMatrixf(view_matrix);
77 glUseProgram(sdr_foo);
88 assert(glGetError() == GL_NO_ERROR);
91 void game_reshape(int x, int y)
93 glViewport(0, 0, x, y);
96 win_aspect = (float)x / (float)y;
99 void game_keyboard(int key, int press)
101 if(press && key == 27) {
107 void game_mbutton(int bn, int press, int x, int y)
114 void game_mmotion(int x, int y)
116 int dx = x - mouse_x;
117 int dy = y - mouse_y;
121 if(!(dx | dy)) return;
124 cam_theta += cgm_deg_to_rad(dx * 0.5f);
125 cam_phi += cgm_deg_to_rad(dy * 0.5f);
126 if(cam_phi < -M_PI/2) cam_phi = -M_PI/2;
127 if(cam_phi > M_PI/2) cam_phi = M_PI/2;
130 cam_dist += dy * 0.1;
131 if(cam_dist < 0) cam_dist = 0;