conworlds
changeset 19:c5054e0cd564
moved main.cc -> glut/main.cc
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 26 Aug 2014 18:40:23 +0300 |
parents | e4257df067a1 |
children | 782ff06817fb |
files | src/glut/main.cc src/main.cc |
diffstat | 2 files changed, 174 insertions(+), 174 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/glut/main.cc Tue Aug 26 18:40:23 2014 +0300 1.3 @@ -0,0 +1,174 @@ 1.4 +#include <stdio.h> 1.5 +#include <stdlib.h> 1.6 +#include "opengl.h" 1.7 +#include "game.h" 1.8 +#include "gameopt.h" 1.9 +#include "vr/vr.h" 1.10 + 1.11 +static bool init(); 1.12 +static void cleanup(); 1.13 + 1.14 +static void display(); 1.15 +static void idle(); 1.16 +static void reshape(int x, int y); 1.17 +static void keyb(unsigned char key, int x, int y); 1.18 +static void keyb_up(unsigned char key, int x, int y); 1.19 +static void mouse(int bn, int st, int x, int y); 1.20 +static void motion(int x, int y); 1.21 +static void sball_motion(int x, int y, int z); 1.22 +static void sball_rotate(int x, int y, int z); 1.23 + 1.24 +static bool fullscreen_pending; 1.25 + 1.26 +int main(int argc, char **argv) 1.27 +{ 1.28 + glutInitWindowSize(1024, 600); 1.29 + glutInit(&argc, argv); 1.30 + 1.31 + if(!parse_args(argc, argv)) { 1.32 + return 1; 1.33 + } 1.34 + 1.35 + glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | (opt.stereo ? GLUT_STEREO : 0)); 1.36 + glutCreateWindow("LD48 #30 - connected worlds"); 1.37 + 1.38 + glutDisplayFunc(display); 1.39 + glutIdleFunc(idle); 1.40 + glutReshapeFunc(reshape); 1.41 + glutKeyboardFunc(keyb); 1.42 + glutKeyboardUpFunc(keyb_up); 1.43 + glutMouseFunc(mouse); 1.44 + glutMotionFunc(motion); 1.45 + glutSpaceballMotionFunc(sball_motion); 1.46 + glutSpaceballRotateFunc(sball_rotate); 1.47 + 1.48 + if(!init()) { 1.49 + return 1; 1.50 + } 1.51 + atexit(cleanup); 1.52 + 1.53 + glutMainLoop(); 1.54 + return 0; 1.55 +} 1.56 + 1.57 +static bool init() 1.58 +{ 1.59 + glewInit(); 1.60 + 1.61 + if(!game_init()) { 1.62 + return false; 1.63 + } 1.64 + 1.65 + if(opt.vr) { 1.66 + int win_xsz = vr_get_opti(VR_OPT_DISPLAY_WIDTH); 1.67 + int win_ysz = vr_get_opti(VR_OPT_DISPLAY_HEIGHT); 1.68 + if(win_xsz && win_ysz) { 1.69 + glutReshapeWindow(win_xsz, win_ysz); 1.70 + } 1.71 + } 1.72 + return true; 1.73 +} 1.74 + 1.75 +static void cleanup() 1.76 +{ 1.77 + game_cleanup(); 1.78 +} 1.79 + 1.80 +static void display() 1.81 +{ 1.82 + unsigned int msec = glutGet(GLUT_ELAPSED_TIME); 1.83 + 1.84 + game_update(msec); 1.85 + game_render(); 1.86 +} 1.87 + 1.88 +static void idle() 1.89 +{ 1.90 + if(fullscreen_pending) { 1.91 + glutFullScreen(); 1.92 + } 1.93 + 1.94 + glutPostRedisplay(); 1.95 +} 1.96 + 1.97 +static void reshape(int x, int y) 1.98 +{ 1.99 + game_reshape(x, y); 1.100 +} 1.101 + 1.102 +static void keyb(unsigned char key, int x, int y) 1.103 +{ 1.104 + static bool fullscr; 1.105 + static int prev_xpos, prev_ypos; 1.106 + static int prev_xsz, prev_ysz; 1.107 + 1.108 + switch(key) { 1.109 + case 'f': 1.110 + fullscr = !fullscr; 1.111 + if(fullscr) { 1.112 + int xoffs, yoffs; 1.113 + 1.114 + prev_xpos = glutGet(GLUT_WINDOW_X); 1.115 + prev_ypos = glutGet(GLUT_WINDOW_Y); 1.116 + prev_xsz = glutGet(GLUT_WINDOW_WIDTH); 1.117 + prev_ysz = glutGet(GLUT_WINDOW_HEIGHT); 1.118 + 1.119 + xoffs = vr_get_opti(VR_OPT_WIN_XOFFS); 1.120 + yoffs = vr_get_opti(VR_OPT_WIN_YOFFS); 1.121 + if(xoffs || yoffs) { 1.122 + printf("repositioning: %d,%d\n", xoffs, yoffs); 1.123 + glutPositionWindow(xoffs, yoffs); 1.124 + } 1.125 + fullscreen_pending = true; 1.126 + } else { 1.127 + fullscreen_pending = false; 1.128 + glutPositionWindow(prev_xpos, prev_ypos); 1.129 + glutReshapeWindow(prev_xsz, prev_ysz); 1.130 + } 1.131 + break; 1.132 + } 1.133 + game_keyboard(key, true, x, y); 1.134 +} 1.135 + 1.136 +static void keyb_up(unsigned char key, int x, int y) 1.137 +{ 1.138 + game_keyboard(key, false, x, y); 1.139 +} 1.140 + 1.141 +static void mouse(int bn, int st, int x, int y) 1.142 +{ 1.143 + switch(bn) { 1.144 + case GLUT_RIGHT_BUTTON + 1: 1.145 + if(st == GLUT_DOWN) { 1.146 + game_mwheel(1); 1.147 + } 1.148 + break; 1.149 + 1.150 + case GLUT_RIGHT_BUTTON + 2: 1.151 + if(st == GLUT_DOWN) { 1.152 + game_mwheel(-1); 1.153 + } 1.154 + break; 1.155 + 1.156 + default: 1.157 + game_mouse(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y); 1.158 + } 1.159 +} 1.160 + 1.161 +static void motion(int x, int y) 1.162 +{ 1.163 + game_motion(x, y); 1.164 +} 1.165 + 1.166 +#define SBALL_MOVE_SCALE 0.00025 1.167 +#define SBALL_ROT_SCALE 0.01 1.168 + 1.169 +static void sball_motion(int x, int y, int z) 1.170 +{ 1.171 + game_6dof_move(x * SBALL_MOVE_SCALE, y * SBALL_MOVE_SCALE, z * SBALL_MOVE_SCALE); 1.172 +} 1.173 + 1.174 +static void sball_rotate(int x, int y, int z) 1.175 +{ 1.176 + game_6dof_rotate(x * SBALL_ROT_SCALE, y * SBALL_ROT_SCALE, z * SBALL_ROT_SCALE); 1.177 +}
2.1 --- a/src/main.cc Tue Aug 26 12:59:15 2014 +0300 2.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 2.3 @@ -1,174 +0,0 @@ 2.4 -#include <stdio.h> 2.5 -#include <stdlib.h> 2.6 -#include "opengl.h" 2.7 -#include "game.h" 2.8 -#include "gameopt.h" 2.9 -#include "vr/vr.h" 2.10 - 2.11 -static bool init(); 2.12 -static void cleanup(); 2.13 - 2.14 -static void display(); 2.15 -static void idle(); 2.16 -static void reshape(int x, int y); 2.17 -static void keyb(unsigned char key, int x, int y); 2.18 -static void keyb_up(unsigned char key, int x, int y); 2.19 -static void mouse(int bn, int st, int x, int y); 2.20 -static void motion(int x, int y); 2.21 -static void sball_motion(int x, int y, int z); 2.22 -static void sball_rotate(int x, int y, int z); 2.23 - 2.24 -static bool fullscreen_pending; 2.25 - 2.26 -int main(int argc, char **argv) 2.27 -{ 2.28 - glutInitWindowSize(1024, 600); 2.29 - glutInit(&argc, argv); 2.30 - 2.31 - if(!parse_args(argc, argv)) { 2.32 - return 1; 2.33 - } 2.34 - 2.35 - glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | (opt.stereo ? GLUT_STEREO : 0)); 2.36 - glutCreateWindow("LD48 #30 - connected worlds"); 2.37 - 2.38 - glutDisplayFunc(display); 2.39 - glutIdleFunc(idle); 2.40 - glutReshapeFunc(reshape); 2.41 - glutKeyboardFunc(keyb); 2.42 - glutKeyboardUpFunc(keyb_up); 2.43 - glutMouseFunc(mouse); 2.44 - glutMotionFunc(motion); 2.45 - glutSpaceballMotionFunc(sball_motion); 2.46 - glutSpaceballRotateFunc(sball_rotate); 2.47 - 2.48 - if(!init()) { 2.49 - return 1; 2.50 - } 2.51 - atexit(cleanup); 2.52 - 2.53 - glutMainLoop(); 2.54 - return 0; 2.55 -} 2.56 - 2.57 -static bool init() 2.58 -{ 2.59 - glewInit(); 2.60 - 2.61 - if(!game_init()) { 2.62 - return false; 2.63 - } 2.64 - 2.65 - if(opt.vr) { 2.66 - int win_xsz = vr_get_opti(VR_OPT_DISPLAY_WIDTH); 2.67 - int win_ysz = vr_get_opti(VR_OPT_DISPLAY_HEIGHT); 2.68 - if(win_xsz && win_ysz) { 2.69 - glutReshapeWindow(win_xsz, win_ysz); 2.70 - } 2.71 - } 2.72 - return true; 2.73 -} 2.74 - 2.75 -static void cleanup() 2.76 -{ 2.77 - game_cleanup(); 2.78 -} 2.79 - 2.80 -static void display() 2.81 -{ 2.82 - unsigned int msec = glutGet(GLUT_ELAPSED_TIME); 2.83 - 2.84 - game_update(msec); 2.85 - game_render(); 2.86 -} 2.87 - 2.88 -static void idle() 2.89 -{ 2.90 - if(fullscreen_pending) { 2.91 - glutFullScreen(); 2.92 - } 2.93 - 2.94 - glutPostRedisplay(); 2.95 -} 2.96 - 2.97 -static void reshape(int x, int y) 2.98 -{ 2.99 - game_reshape(x, y); 2.100 -} 2.101 - 2.102 -static void keyb(unsigned char key, int x, int y) 2.103 -{ 2.104 - static bool fullscr; 2.105 - static int prev_xpos, prev_ypos; 2.106 - static int prev_xsz, prev_ysz; 2.107 - 2.108 - switch(key) { 2.109 - case 'f': 2.110 - fullscr = !fullscr; 2.111 - if(fullscr) { 2.112 - int xoffs, yoffs; 2.113 - 2.114 - prev_xpos = glutGet(GLUT_WINDOW_X); 2.115 - prev_ypos = glutGet(GLUT_WINDOW_Y); 2.116 - prev_xsz = glutGet(GLUT_WINDOW_WIDTH); 2.117 - prev_ysz = glutGet(GLUT_WINDOW_HEIGHT); 2.118 - 2.119 - xoffs = vr_get_opti(VR_OPT_WIN_XOFFS); 2.120 - yoffs = vr_get_opti(VR_OPT_WIN_YOFFS); 2.121 - if(xoffs || yoffs) { 2.122 - printf("repositioning: %d,%d\n", xoffs, yoffs); 2.123 - glutPositionWindow(xoffs, yoffs); 2.124 - } 2.125 - fullscreen_pending = true; 2.126 - } else { 2.127 - fullscreen_pending = false; 2.128 - glutPositionWindow(prev_xpos, prev_ypos); 2.129 - glutReshapeWindow(prev_xsz, prev_ysz); 2.130 - } 2.131 - break; 2.132 - } 2.133 - game_keyboard(key, true, x, y); 2.134 -} 2.135 - 2.136 -static void keyb_up(unsigned char key, int x, int y) 2.137 -{ 2.138 - game_keyboard(key, false, x, y); 2.139 -} 2.140 - 2.141 -static void mouse(int bn, int st, int x, int y) 2.142 -{ 2.143 - switch(bn) { 2.144 - case GLUT_RIGHT_BUTTON + 1: 2.145 - if(st == GLUT_DOWN) { 2.146 - game_mwheel(1); 2.147 - } 2.148 - break; 2.149 - 2.150 - case GLUT_RIGHT_BUTTON + 2: 2.151 - if(st == GLUT_DOWN) { 2.152 - game_mwheel(-1); 2.153 - } 2.154 - break; 2.155 - 2.156 - default: 2.157 - game_mouse(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y); 2.158 - } 2.159 -} 2.160 - 2.161 -static void motion(int x, int y) 2.162 -{ 2.163 - game_motion(x, y); 2.164 -} 2.165 - 2.166 -#define SBALL_MOVE_SCALE 0.00025 2.167 -#define SBALL_ROT_SCALE 0.01 2.168 - 2.169 -static void sball_motion(int x, int y, int z) 2.170 -{ 2.171 - game_6dof_move(x * SBALL_MOVE_SCALE, y * SBALL_MOVE_SCALE, z * SBALL_MOVE_SCALE); 2.172 -} 2.173 - 2.174 -static void sball_rotate(int x, int y, int z) 2.175 -{ 2.176 - game_6dof_rotate(x * SBALL_ROT_SCALE, y * SBALL_ROT_SCALE, z * SBALL_ROT_SCALE); 2.177 -}