bloboland

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