nuclear@2: #include nuclear@2: #include nuclear@2: #include "opengl.h" nuclear@2: #include "game.h" nuclear@13: #include "gameopt.h" nuclear@6: #include "vr/vr.h" nuclear@2: nuclear@2: static bool init(); nuclear@2: static void cleanup(); nuclear@2: nuclear@2: static void display(); nuclear@2: static void idle(); nuclear@2: static void reshape(int x, int y); nuclear@2: static void keyb(unsigned char key, int x, int y); nuclear@2: static void keyb_up(unsigned char key, int x, int y); nuclear@2: static void mouse(int bn, int st, int x, int y); nuclear@2: static void motion(int x, int y); nuclear@2: static void sball_motion(int x, int y, int z); nuclear@2: static void sball_rotate(int x, int y, int z); nuclear@2: nuclear@12: static bool fullscreen_pending; nuclear@12: nuclear@2: int main(int argc, char **argv) nuclear@2: { nuclear@2: glutInitWindowSize(1024, 600); nuclear@2: glutInit(&argc, argv); nuclear@13: nuclear@13: if(!parse_args(argc, argv)) { nuclear@13: return 1; nuclear@13: } nuclear@13: nuclear@13: glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | (opt.stereo ? GLUT_STEREO : 0)); nuclear@13: glutCreateWindow("LD48 #30 - connected worlds"); nuclear@2: nuclear@2: glutDisplayFunc(display); nuclear@2: glutIdleFunc(idle); nuclear@2: glutReshapeFunc(reshape); nuclear@2: glutKeyboardFunc(keyb); nuclear@2: glutKeyboardUpFunc(keyb_up); nuclear@2: glutMouseFunc(mouse); nuclear@2: glutMotionFunc(motion); nuclear@2: glutSpaceballMotionFunc(sball_motion); nuclear@2: glutSpaceballRotateFunc(sball_rotate); nuclear@2: nuclear@2: if(!init()) { nuclear@2: return 1; nuclear@2: } nuclear@2: atexit(cleanup); nuclear@2: nuclear@2: glutMainLoop(); nuclear@2: return 0; nuclear@2: } nuclear@2: nuclear@2: static bool init() nuclear@2: { nuclear@2: glewInit(); nuclear@2: nuclear@2: if(!game_init()) { nuclear@2: return false; nuclear@2: } nuclear@7: nuclear@13: if(opt.vr) { nuclear@13: int win_xsz = vr_get_opti(VR_OPT_DISPLAY_WIDTH); nuclear@13: int win_ysz = vr_get_opti(VR_OPT_DISPLAY_HEIGHT); nuclear@13: if(win_xsz && win_ysz) { nuclear@13: glutReshapeWindow(win_xsz, win_ysz); nuclear@13: } nuclear@7: } nuclear@2: return true; nuclear@2: } nuclear@2: nuclear@2: static void cleanup() nuclear@2: { nuclear@2: game_cleanup(); nuclear@2: } nuclear@2: nuclear@2: static void display() nuclear@2: { nuclear@2: unsigned int msec = glutGet(GLUT_ELAPSED_TIME); nuclear@2: nuclear@2: game_update(msec); nuclear@7: game_render(); nuclear@2: } nuclear@2: nuclear@2: static void idle() nuclear@2: { nuclear@12: if(fullscreen_pending) { nuclear@12: glutFullScreen(); nuclear@12: } nuclear@12: nuclear@2: glutPostRedisplay(); nuclear@2: } nuclear@2: nuclear@2: static void reshape(int x, int y) nuclear@2: { nuclear@2: game_reshape(x, y); nuclear@2: } nuclear@2: nuclear@2: static void keyb(unsigned char key, int x, int y) nuclear@2: { nuclear@11: static bool fullscr; nuclear@12: static int prev_xpos, prev_ypos; nuclear@11: static int prev_xsz, prev_ysz; nuclear@11: nuclear@11: switch(key) { nuclear@11: case 'f': nuclear@11: fullscr = !fullscr; nuclear@11: if(fullscr) { nuclear@11: int xoffs, yoffs; nuclear@11: nuclear@12: prev_xpos = glutGet(GLUT_WINDOW_X); nuclear@12: prev_ypos = glutGet(GLUT_WINDOW_Y); nuclear@11: prev_xsz = glutGet(GLUT_WINDOW_WIDTH); nuclear@11: prev_ysz = glutGet(GLUT_WINDOW_HEIGHT); nuclear@11: nuclear@11: xoffs = vr_get_opti(VR_OPT_WIN_XOFFS); nuclear@11: yoffs = vr_get_opti(VR_OPT_WIN_YOFFS); nuclear@11: if(xoffs || yoffs) { nuclear@11: printf("repositioning: %d,%d\n", xoffs, yoffs); nuclear@12: glutPositionWindow(xoffs, yoffs); nuclear@11: } nuclear@13: fullscreen_pending = true; nuclear@11: } else { nuclear@12: fullscreen_pending = false; nuclear@12: glutPositionWindow(prev_xpos, prev_ypos); nuclear@11: glutReshapeWindow(prev_xsz, prev_ysz); nuclear@11: } nuclear@11: break; nuclear@11: } nuclear@2: game_keyboard(key, true, x, y); nuclear@2: } nuclear@2: nuclear@2: static void keyb_up(unsigned char key, int x, int y) nuclear@2: { nuclear@2: game_keyboard(key, false, x, y); nuclear@2: } nuclear@2: nuclear@2: static void mouse(int bn, int st, int x, int y) nuclear@2: { nuclear@3: switch(bn) { nuclear@3: case GLUT_RIGHT_BUTTON + 1: nuclear@3: if(st == GLUT_DOWN) { nuclear@3: game_mwheel(1); nuclear@3: } nuclear@3: break; nuclear@3: nuclear@3: case GLUT_RIGHT_BUTTON + 2: nuclear@3: if(st == GLUT_DOWN) { nuclear@3: game_mwheel(-1); nuclear@3: } nuclear@3: break; nuclear@3: nuclear@3: default: nuclear@3: game_mouse(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y); nuclear@3: } nuclear@2: } nuclear@2: nuclear@2: static void motion(int x, int y) nuclear@2: { nuclear@2: game_motion(x, y); nuclear@2: } nuclear@2: nuclear@2: #define SBALL_MOVE_SCALE 0.00025 nuclear@2: #define SBALL_ROT_SCALE 0.01 nuclear@2: nuclear@2: static void sball_motion(int x, int y, int z) nuclear@2: { nuclear@2: game_6dof_move(x * SBALL_MOVE_SCALE, y * SBALL_MOVE_SCALE, z * SBALL_MOVE_SCALE); nuclear@2: } nuclear@2: nuclear@2: static void sball_rotate(int x, int y, int z) nuclear@2: { nuclear@2: game_6dof_rotate(x * SBALL_ROT_SCALE, y * SBALL_ROT_SCALE, z * SBALL_ROT_SCALE); nuclear@2: }