nuclear@0: #include nuclear@0: #include "opengl.h" nuclear@0: #include "game.h" nuclear@0: #include nuclear@0: #include nuclear@0: #include "main.h" nuclear@0: #include "scene.h" nuclear@0: #include "timer.h" nuclear@0: #include "rtarg.h" nuclear@0: #include "opt.h" nuclear@0: nuclear@0: static bool vr_mode = true; nuclear@0: static int win_width, win_height; nuclear@0: static RenderTarget vr_rtarg; nuclear@1: static Options opt; nuclear@0: nuclear@0: bool game_init(int argc, char **argv) nuclear@0: { nuclear@1: if(!parse_args(&opt, argc, argv)) { nuclear@0: return false; nuclear@0: } nuclear@0: nuclear@0: init_gl(); nuclear@0: nuclear@0: if(vr_mode) { nuclear@0: if(vr_init() == -1) { nuclear@0: return false; nuclear@0: } nuclear@0: nuclear@0: win_width = vr_geti_def(VR_DISPLAY_WIDTH, 1280); nuclear@0: win_height = vr_geti_def(VR_DISPLAY_HEIGHT, 800); nuclear@0: resize_window(win_width, win_height); nuclear@0: nuclear@0: int rt_width = vr_geti_def(VR_RENDER_XRES, win_width); nuclear@0: int rt_height = vr_geti_def(VR_RENDER_YRES, win_height); nuclear@0: vr_rtarg.create(rt_width, rt_height); nuclear@0: } nuclear@0: nuclear@0: return true; nuclear@0: } nuclear@0: nuclear@0: void game_shutdown() nuclear@0: { nuclear@0: vr_shutdown(); nuclear@0: } nuclear@0: nuclear@0: void game_draw() nuclear@0: { nuclear@0: static unsigned long prev_msec; nuclear@0: unsigned long msec = get_msec(); nuclear@0: float dt = (float)(msec - prev_msec) / 1000.0; nuclear@0: nuclear@0: update_scene(msec, dt); nuclear@0: nuclear@0: if(vr_mode) { nuclear@0: set_render_target(&vr_rtarg); nuclear@0: nuclear@0: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); nuclear@0: nuclear@0: for(int i=0; i<2; i++) { nuclear@0: vr_begin(i); nuclear@0: nuclear@0: glViewport(i == VR_EYE_LEFT ? 0 : vr_rtarg.get_width() / 2, 0, vr_rtarg.get_width() / 2, vr_rtarg.get_height()); nuclear@0: nuclear@0: glMatrixMode(GL_PROJECTION); nuclear@0: float proj[16]; nuclear@0: if(vr_proj_matrix(i, 0.5, 500.0, proj)) { nuclear@0: glLoadMatrixf(proj); nuclear@0: } else { nuclear@0: glLoadIdentity(); nuclear@0: gluPerspective(50.0, (float)win_width / 2.0 / (float)win_height, 0.5, 500.0); nuclear@0: } nuclear@0: nuclear@0: float view[16]; nuclear@0: vr_view_matrix(i, view); nuclear@0: nuclear@0: glMatrixMode(GL_MODELVIEW); nuclear@0: glLoadMatrixf(view); nuclear@0: glTranslatef(0, -vr_getf(VR_EYE_HEIGHT), 0); nuclear@0: nuclear@0: draw_scene(); nuclear@0: nuclear@0: vr_end(); nuclear@0: } nuclear@0: nuclear@0: set_render_target(0); nuclear@0: glViewport(0, 0, win_width, win_height); nuclear@0: nuclear@0: vr_swap_buffers(); nuclear@0: nuclear@0: } else { nuclear@0: glMatrixMode(GL_MODELVIEW); nuclear@0: glLoadIdentity(); nuclear@0: nuclear@0: draw_scene(); nuclear@0: nuclear@0: swap_buffers(); nuclear@0: } nuclear@0: nuclear@0: assert(glGetError() == GL_NO_ERROR); nuclear@0: } nuclear@0: nuclear@0: void game_reshape(int x, int y) nuclear@0: { nuclear@0: glViewport(0, 0, x, y); nuclear@0: nuclear@0: if(vr_mode) { nuclear@0: vr_rtarg.resize(x, y); nuclear@0: nuclear@0: float umax = (float)vr_rtarg.get_width() / (float)vr_rtarg.get_tex_width(); nuclear@0: float vmax = (float)vr_rtarg.get_height() / (float)vr_rtarg.get_tex_height(); nuclear@0: vr_output_texture(vr_rtarg.get_texture(), 0, 0, umax, vmax); nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: void game_keyboard(int key, bool press) nuclear@0: { nuclear@0: if(press) { nuclear@0: switch(key) { nuclear@0: case 27: nuclear@0: quit(); nuclear@0: nuclear@0: case ' ': nuclear@0: if(vr_mode) { nuclear@0: vr_recenter(); nuclear@0: } nuclear@0: break; nuclear@0: } nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: void game_mbutton(int bn, bool press, int x, int y) nuclear@0: { nuclear@0: } nuclear@0: nuclear@0: void game_mmotion(int x, int y) nuclear@0: { nuclear@0: }