# HG changeset patch # User John Tsiombikas # Date 1409067623 -10800 # Node ID c5054e0cd564f4c5695377fcd3bf605f23eb2dee # Parent e4257df067a12f0bc411c6939a345bb8e39aba8d moved main.cc -> glut/main.cc diff -r e4257df067a1 -r c5054e0cd564 src/glut/main.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/glut/main.cc Tue Aug 26 18:40:23 2014 +0300 @@ -0,0 +1,174 @@ +#include +#include +#include "opengl.h" +#include "game.h" +#include "gameopt.h" +#include "vr/vr.h" + +static bool init(); +static void cleanup(); + +static void display(); +static void idle(); +static void reshape(int x, int y); +static void keyb(unsigned char key, int x, int y); +static void keyb_up(unsigned char key, int x, int y); +static void mouse(int bn, int st, int x, int y); +static void motion(int x, int y); +static void sball_motion(int x, int y, int z); +static void sball_rotate(int x, int y, int z); + +static bool fullscreen_pending; + +int main(int argc, char **argv) +{ + glutInitWindowSize(1024, 600); + glutInit(&argc, argv); + + if(!parse_args(argc, argv)) { + return 1; + } + + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | (opt.stereo ? GLUT_STEREO : 0)); + glutCreateWindow("LD48 #30 - connected worlds"); + + glutDisplayFunc(display); + glutIdleFunc(idle); + glutReshapeFunc(reshape); + glutKeyboardFunc(keyb); + glutKeyboardUpFunc(keyb_up); + glutMouseFunc(mouse); + glutMotionFunc(motion); + glutSpaceballMotionFunc(sball_motion); + glutSpaceballRotateFunc(sball_rotate); + + if(!init()) { + return 1; + } + atexit(cleanup); + + glutMainLoop(); + return 0; +} + +static bool init() +{ + glewInit(); + + if(!game_init()) { + return false; + } + + if(opt.vr) { + int win_xsz = vr_get_opti(VR_OPT_DISPLAY_WIDTH); + int win_ysz = vr_get_opti(VR_OPT_DISPLAY_HEIGHT); + if(win_xsz && win_ysz) { + glutReshapeWindow(win_xsz, win_ysz); + } + } + return true; +} + +static void cleanup() +{ + game_cleanup(); +} + +static void display() +{ + unsigned int msec = glutGet(GLUT_ELAPSED_TIME); + + game_update(msec); + game_render(); +} + +static void idle() +{ + if(fullscreen_pending) { + glutFullScreen(); + } + + glutPostRedisplay(); +} + +static void reshape(int x, int y) +{ + game_reshape(x, y); +} + +static void keyb(unsigned char key, int x, int y) +{ + static bool fullscr; + static int prev_xpos, prev_ypos; + static int prev_xsz, prev_ysz; + + switch(key) { + case 'f': + fullscr = !fullscr; + if(fullscr) { + int xoffs, yoffs; + + prev_xpos = glutGet(GLUT_WINDOW_X); + prev_ypos = glutGet(GLUT_WINDOW_Y); + prev_xsz = glutGet(GLUT_WINDOW_WIDTH); + prev_ysz = glutGet(GLUT_WINDOW_HEIGHT); + + xoffs = vr_get_opti(VR_OPT_WIN_XOFFS); + yoffs = vr_get_opti(VR_OPT_WIN_YOFFS); + if(xoffs || yoffs) { + printf("repositioning: %d,%d\n", xoffs, yoffs); + glutPositionWindow(xoffs, yoffs); + } + fullscreen_pending = true; + } else { + fullscreen_pending = false; + glutPositionWindow(prev_xpos, prev_ypos); + glutReshapeWindow(prev_xsz, prev_ysz); + } + break; + } + game_keyboard(key, true, x, y); +} + +static void keyb_up(unsigned char key, int x, int y) +{ + game_keyboard(key, false, x, y); +} + +static void mouse(int bn, int st, int x, int y) +{ + switch(bn) { + case GLUT_RIGHT_BUTTON + 1: + if(st == GLUT_DOWN) { + game_mwheel(1); + } + break; + + case GLUT_RIGHT_BUTTON + 2: + if(st == GLUT_DOWN) { + game_mwheel(-1); + } + break; + + default: + game_mouse(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y); + } +} + +static void motion(int x, int y) +{ + game_motion(x, y); +} + +#define SBALL_MOVE_SCALE 0.00025 +#define SBALL_ROT_SCALE 0.01 + +static void sball_motion(int x, int y, int z) +{ + game_6dof_move(x * SBALL_MOVE_SCALE, y * SBALL_MOVE_SCALE, z * SBALL_MOVE_SCALE); +} + +static void sball_rotate(int x, int y, int z) +{ + game_6dof_rotate(x * SBALL_ROT_SCALE, y * SBALL_ROT_SCALE, z * SBALL_ROT_SCALE); +} diff -r e4257df067a1 -r c5054e0cd564 src/main.cc --- a/src/main.cc Tue Aug 26 12:59:15 2014 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,174 +0,0 @@ -#include -#include -#include "opengl.h" -#include "game.h" -#include "gameopt.h" -#include "vr/vr.h" - -static bool init(); -static void cleanup(); - -static void display(); -static void idle(); -static void reshape(int x, int y); -static void keyb(unsigned char key, int x, int y); -static void keyb_up(unsigned char key, int x, int y); -static void mouse(int bn, int st, int x, int y); -static void motion(int x, int y); -static void sball_motion(int x, int y, int z); -static void sball_rotate(int x, int y, int z); - -static bool fullscreen_pending; - -int main(int argc, char **argv) -{ - glutInitWindowSize(1024, 600); - glutInit(&argc, argv); - - if(!parse_args(argc, argv)) { - return 1; - } - - glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | (opt.stereo ? GLUT_STEREO : 0)); - glutCreateWindow("LD48 #30 - connected worlds"); - - glutDisplayFunc(display); - glutIdleFunc(idle); - glutReshapeFunc(reshape); - glutKeyboardFunc(keyb); - glutKeyboardUpFunc(keyb_up); - glutMouseFunc(mouse); - glutMotionFunc(motion); - glutSpaceballMotionFunc(sball_motion); - glutSpaceballRotateFunc(sball_rotate); - - if(!init()) { - return 1; - } - atexit(cleanup); - - glutMainLoop(); - return 0; -} - -static bool init() -{ - glewInit(); - - if(!game_init()) { - return false; - } - - if(opt.vr) { - int win_xsz = vr_get_opti(VR_OPT_DISPLAY_WIDTH); - int win_ysz = vr_get_opti(VR_OPT_DISPLAY_HEIGHT); - if(win_xsz && win_ysz) { - glutReshapeWindow(win_xsz, win_ysz); - } - } - return true; -} - -static void cleanup() -{ - game_cleanup(); -} - -static void display() -{ - unsigned int msec = glutGet(GLUT_ELAPSED_TIME); - - game_update(msec); - game_render(); -} - -static void idle() -{ - if(fullscreen_pending) { - glutFullScreen(); - } - - glutPostRedisplay(); -} - -static void reshape(int x, int y) -{ - game_reshape(x, y); -} - -static void keyb(unsigned char key, int x, int y) -{ - static bool fullscr; - static int prev_xpos, prev_ypos; - static int prev_xsz, prev_ysz; - - switch(key) { - case 'f': - fullscr = !fullscr; - if(fullscr) { - int xoffs, yoffs; - - prev_xpos = glutGet(GLUT_WINDOW_X); - prev_ypos = glutGet(GLUT_WINDOW_Y); - prev_xsz = glutGet(GLUT_WINDOW_WIDTH); - prev_ysz = glutGet(GLUT_WINDOW_HEIGHT); - - xoffs = vr_get_opti(VR_OPT_WIN_XOFFS); - yoffs = vr_get_opti(VR_OPT_WIN_YOFFS); - if(xoffs || yoffs) { - printf("repositioning: %d,%d\n", xoffs, yoffs); - glutPositionWindow(xoffs, yoffs); - } - fullscreen_pending = true; - } else { - fullscreen_pending = false; - glutPositionWindow(prev_xpos, prev_ypos); - glutReshapeWindow(prev_xsz, prev_ysz); - } - break; - } - game_keyboard(key, true, x, y); -} - -static void keyb_up(unsigned char key, int x, int y) -{ - game_keyboard(key, false, x, y); -} - -static void mouse(int bn, int st, int x, int y) -{ - switch(bn) { - case GLUT_RIGHT_BUTTON + 1: - if(st == GLUT_DOWN) { - game_mwheel(1); - } - break; - - case GLUT_RIGHT_BUTTON + 2: - if(st == GLUT_DOWN) { - game_mwheel(-1); - } - break; - - default: - game_mouse(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y); - } -} - -static void motion(int x, int y) -{ - game_motion(x, y); -} - -#define SBALL_MOVE_SCALE 0.00025 -#define SBALL_ROT_SCALE 0.01 - -static void sball_motion(int x, int y, int z) -{ - game_6dof_move(x * SBALL_MOVE_SCALE, y * SBALL_MOVE_SCALE, z * SBALL_MOVE_SCALE); -} - -static void sball_rotate(int x, int y, int z) -{ - game_6dof_rotate(x * SBALL_ROT_SCALE, y * SBALL_ROT_SCALE, z * SBALL_ROT_SCALE); -}