vrseasons
view 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 source
1 #ifdef USE_GLUT
3 #include <stdlib.h>
5 #ifdef __APPLE__
6 #include <GLUT/glut.h>
7 #else
8 #include <GL/glut.h>
9 #endif
11 #include "game.h"
13 static void display();
14 static void idle();
15 static void reshape(int x, int y);
16 static void key_press(unsigned char key, int x, int y);
17 static void key_release(unsigned char key, int x, int y);
18 static void mouse(int bn, int st, int x, int y);
19 static void motion(int x, int y);
21 static bool state_fullscreen;
22 static int prev_width, prev_height;
23 static int win_width, win_height;
25 int main(int argc, char **argv)
26 {
27 glutInit(&argc, argv);
28 glutInitWindowSize(800, 600);
29 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
30 glutCreateWindow("GLUT");
32 glutDisplayFunc(display);
33 glutIdleFunc(idle);
34 glutReshapeFunc(reshape);
35 glutKeyboardFunc(key_press);
36 glutKeyboardUpFunc(key_release);
37 glutMouseFunc(mouse);
38 glutMotionFunc(motion);
40 if(!game_init(argc, argv)) {
41 return 1;
42 }
43 atexit(game_shutdown);
45 glutMainLoop();
46 return 0;
47 }
49 void quit()
50 {
51 exit(0);
52 }
54 void swap_buffers()
55 {
56 glutSwapBuffers();
57 }
59 void redisplay()
60 {
61 glutPostRedisplay();
62 }
64 void idle()
65 {
66 glutPostRedisplay();
67 }
69 void fullscreen()
70 {
71 if(!state_fullscreen) {
72 prev_width = win_width;
73 prev_height = win_height;
75 glutFullScreen();
76 state_fullscreen = true;
77 }
78 }
80 void windowed()
81 {
82 if(state_fullscreen) {
83 glutReshapeWindow(prev_width, prev_height);
84 state_fullscreen = false;
85 }
86 }
88 void move_window(int x, int y)
89 {
90 if(!state_fullscreen) {
91 glutPositionWindow(x, y);
92 }
93 }
95 void window_position(int *xout, int *yout)
96 {
97 *xout = glutGet(GLUT_WINDOW_X);
98 *yout = glutGet(GLUT_WINDOW_Y);
99 }
101 void resize_window(int x, int y)
102 {
103 if(!state_fullscreen) {
104 glutReshapeWindow(x, y);
105 }
106 }
108 void window_size(int *xout, int *yout)
109 {
110 *xout = win_width;
111 *yout = win_height;
112 }
115 static void display()
116 {
117 game_draw();
118 }
120 static void reshape(int x, int y)
121 {
122 win_width = x;
123 win_height = y;
124 game_reshape(x, y);
125 }
127 static void key_press(unsigned char key, int x, int y)
128 {
129 game_keyboard(key, true);
130 }
132 static void key_release(unsigned char key, int x, int y)
133 {
134 game_keyboard(key, false);
135 }
137 static void mouse(int bn, int st, int x, int y)
138 {
139 game_mbutton(bn - GLUT_LEFT_BUTTON, st == GLUT_DOWN, x, y);
140 }
142 static void motion(int x, int y)
143 {
144 game_mmotion(x, y);
145 }
147 int using_glut;
148 #else
149 int not_using_glut;
150 #endif