bloboland

view src/main.cc @ 0:e4818a3300b9

bloboland initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 15 Dec 2012 07:52:13 +0200
parents
children cfe68befb7cc
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "opengl.h"
4 #include "game.h"
5 #include "opt.h"
7 static void disp();
8 static void reshape(int x, int y);
9 static void keydown(unsigned char key, int x, int y);
10 static void keyup(unsigned char key, int x, int y);
11 static void skeydown(int key, int x, int y);
12 static void skeyup(int key, int x, int y);
13 static void mouse(int bn, int state, int x, int y);
14 static void motion(int x, int y);
15 static void spacemove(int x, int y, int z);
16 static void spacerot(int x, int y, int z);
17 static void spacebut(int bn, int state);
19 int main(int argc, char **argv)
20 {
21 glutInit(&argc, argv);
23 if(!parse_opt(argc, argv)) {
24 return 1;
25 }
27 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | (opt.stereo ? GLUT_STEREO : 0));
28 glutInitWindowSize(800, 450);
29 glutCreateWindow("bloboland");
31 glutDisplayFunc(disp);
32 glutReshapeFunc(reshape);
33 glutKeyboardFunc(keydown);
34 glutKeyboardUpFunc(keyup);
35 glutSpecialFunc(skeydown);
36 glutSpecialUpFunc(skeyup);
37 glutMouseFunc(mouse);
38 glutMotionFunc(motion);
39 glutSpaceballMotionFunc(spacemove);
40 glutSpaceballRotateFunc(spacerot);
41 glutSpaceballButtonFunc(spacebut);
43 glewInit();
45 if(!game_init()) {
46 return 1;
47 }
49 glutMainLoop();
50 }
52 static void disp()
53 {
54 unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
55 game_iter((msec - prev_msec) / 1000.0);
58 glClear(GL_COLOR_BUFFER_BIT);
60 game_render();
62 glutSwapBuffers();
63 }
65 static void reshape(int x, int y)
66 {
67 glViewport(0, 0, x, y);
69 glMatrixMode(GL_PROJECTION);
70 glLoadIdentity();
71 gluPerspective(50.0, (float)x / (float)y, 0.5, 500.0);
72 }
74 static void keydown(unsigned char key, int x, int y)
75 {
76 skeydown(key, x, y);
77 }
79 static void keyup(unsigned char key, int x, int y)
80 {
81 skeyup(key, x, y);
82 }
84 static void skeydown(int key, int x, int y)
85 {
86 if(key == 27) {
87 exit(0);
88 }
90 if(key < sizeof keystate / sizeof *keystate) {
91 keystate[key] = true;
92 }
93 }
95 static void skeyup(int key, int x, int y)
96 {
97 if(key < sizeof keystate / sizeof *keystate) {
98 keystate[key] = false;
99 }
100 }
102 static void mouse(int bn, int state, int x, int y)
103 {
104 }
106 static void motion(int x, int y)
107 {
108 }
110 static void spacemove(int x, int y, int z)
111 {
112 }
114 static void spacerot(int x, int y, int z)
115 {
116 }
118 static void spacebut(int bn, int state)
119 {
120 }