vrseasons

diff src/main_glut.cc @ 0:393ef1143c9c

VR seasons
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 07 Apr 2015 11:16:56 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/main_glut.cc	Tue Apr 07 11:16:56 2015 +0300
     1.3 @@ -0,0 +1,150 @@
     1.4 +#ifdef USE_GLUT
     1.5 +
     1.6 +#include <stdlib.h>
     1.7 +
     1.8 +#ifdef __APPLE__
     1.9 +#include <GLUT/glut.h>
    1.10 +#else
    1.11 +#include <GL/glut.h>
    1.12 +#endif
    1.13 +
    1.14 +#include "game.h"
    1.15 +
    1.16 +static void display();
    1.17 +static void idle();
    1.18 +static void reshape(int x, int y);
    1.19 +static void key_press(unsigned char key, int x, int y);
    1.20 +static void key_release(unsigned char key, int x, int y);
    1.21 +static void mouse(int bn, int st, int x, int y);
    1.22 +static void motion(int x, int y);
    1.23 +
    1.24 +static bool state_fullscreen;
    1.25 +static int prev_width, prev_height;
    1.26 +static int win_width, win_height;
    1.27 +
    1.28 +int main(int argc, char **argv)
    1.29 +{
    1.30 +	glutInit(&argc, argv);
    1.31 +	glutInitWindowSize(800, 600);
    1.32 +	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
    1.33 +	glutCreateWindow("GLUT");
    1.34 +
    1.35 +	glutDisplayFunc(display);
    1.36 +	glutIdleFunc(idle);
    1.37 +	glutReshapeFunc(reshape);
    1.38 +	glutKeyboardFunc(key_press);
    1.39 +	glutKeyboardUpFunc(key_release);
    1.40 +	glutMouseFunc(mouse);
    1.41 +	glutMotionFunc(motion);
    1.42 +
    1.43 +	if(!game_init(argc, argv)) {
    1.44 +		return 1;
    1.45 +	}
    1.46 +	atexit(game_shutdown);
    1.47 +
    1.48 +	glutMainLoop();
    1.49 +	return 0;
    1.50 +}
    1.51 +
    1.52 +void quit()
    1.53 +{
    1.54 +	exit(0);
    1.55 +}
    1.56 +
    1.57 +void swap_buffers()
    1.58 +{
    1.59 +	glutSwapBuffers();
    1.60 +}
    1.61 +
    1.62 +void redisplay()
    1.63 +{
    1.64 +	glutPostRedisplay();
    1.65 +}
    1.66 +
    1.67 +void idle()
    1.68 +{
    1.69 +	glutPostRedisplay();
    1.70 +}
    1.71 +
    1.72 +void fullscreen()
    1.73 +{
    1.74 +	if(!state_fullscreen) {
    1.75 +		prev_width = win_width;
    1.76 +		prev_height = win_height;
    1.77 +
    1.78 +		glutFullScreen();
    1.79 +		state_fullscreen = true;
    1.80 +	}
    1.81 +}
    1.82 +
    1.83 +void windowed()
    1.84 +{
    1.85 +	if(state_fullscreen) {
    1.86 +		glutReshapeWindow(prev_width, prev_height);
    1.87 +		state_fullscreen = false;
    1.88 +	}
    1.89 +}
    1.90 +
    1.91 +void move_window(int x, int y)
    1.92 +{
    1.93 +	if(!state_fullscreen) {
    1.94 +		glutPositionWindow(x, y);
    1.95 +	}
    1.96 +}
    1.97 +
    1.98 +void window_position(int *xout, int *yout)
    1.99 +{
   1.100 +	*xout = glutGet(GLUT_WINDOW_X);
   1.101 +	*yout = glutGet(GLUT_WINDOW_Y);
   1.102 +}
   1.103 +
   1.104 +void resize_window(int x, int y)
   1.105 +{
   1.106 +	if(!state_fullscreen) {
   1.107 +		glutReshapeWindow(x, y);
   1.108 +	}
   1.109 +}
   1.110 +
   1.111 +void window_size(int *xout, int *yout)
   1.112 +{
   1.113 +	*xout = win_width;
   1.114 +	*yout = win_height;
   1.115 +}
   1.116 +
   1.117 +
   1.118 +static void display()
   1.119 +{
   1.120 +	game_draw();
   1.121 +}
   1.122 +
   1.123 +static void reshape(int x, int y)
   1.124 +{
   1.125 +	win_width = x;
   1.126 +	win_height = y;
   1.127 +	game_reshape(x, y);
   1.128 +}
   1.129 +
   1.130 +static void key_press(unsigned char key, int x, int y)
   1.131 +{
   1.132 +	game_keyboard(key, true);
   1.133 +}
   1.134 +
   1.135 +static void key_release(unsigned char key, int x, int y)
   1.136 +{
   1.137 +	game_keyboard(key, false);
   1.138 +}
   1.139 +
   1.140 +static void mouse(int bn, int st, int x, int y)
   1.141 +{
   1.142 +	game_mbutton(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
   1.143 +}
   1.144 +
   1.145 +static void motion(int x, int y)
   1.146 +{
   1.147 +	game_mmotion(x, y);
   1.148 +}
   1.149 +
   1.150 +int using_glut;
   1.151 +#else
   1.152 +int not_using_glut;
   1.153 +#endif