stratgame

annotate src/main.cc @ 3:8d95187cb3ee

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 23 May 2012 17:10:46 +0300
parents 369b51c9e4a8
children
rev   line source
nuclear@0 1 #include <stdio.h>
nuclear@0 2 #include <stdlib.h>
nuclear@0 3 #include <unistd.h>
nuclear@0 4 #include "opengl.h"
nuclear@0 5 #include "part.h"
nuclear@0 6 #include "menu_part.h"
nuclear@0 7 #include "game_part.h"
nuclear@0 8
nuclear@0 9 static bool init();
nuclear@0 10 static void cleanup();
nuclear@0 11 static void disp();
nuclear@0 12 static void idle();
nuclear@0 13 static void reshape(int x, int y);
nuclear@0 14 static void key_press(unsigned char key, int x, int y);
nuclear@0 15 static void key_release(unsigned char key, int x, int y);
nuclear@0 16 static void mouse(int bn, int state, int x, int y);
nuclear@0 17 static void motion(int x, int y);
nuclear@0 18 static void sball_motion(int x, int y, int z);
nuclear@0 19 static void sball_rotate(int x, int y, int z);
nuclear@0 20 static void sball_button(int bn, int state);
nuclear@0 21
nuclear@0 22 int main(int argc, char **argv)
nuclear@0 23 {
nuclear@0 24 glutInit(&argc, argv);
nuclear@1 25 glutInitWindowSize(800, 450);
nuclear@0 26 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_STENCIL);
nuclear@0 27 glutCreateWindow("Foo");
nuclear@0 28
nuclear@0 29 glutDisplayFunc(disp);
nuclear@0 30 glutIdleFunc(idle);
nuclear@0 31 glutReshapeFunc(reshape);
nuclear@0 32 glutKeyboardFunc(key_press);
nuclear@0 33 glutKeyboardUpFunc(key_release);
nuclear@0 34 glutMouseFunc(mouse);
nuclear@0 35 glutMotionFunc(motion);
nuclear@0 36 glutPassiveMotionFunc(motion);
nuclear@0 37 glutSpaceballMotionFunc(sball_motion);
nuclear@0 38 glutSpaceballRotateFunc(sball_rotate);
nuclear@0 39 glutSpaceballButtonFunc(sball_button);
nuclear@0 40
nuclear@0 41 if(!init()) {
nuclear@0 42 return 1;
nuclear@0 43 }
nuclear@0 44 atexit(cleanup);
nuclear@0 45
nuclear@0 46 glutMainLoop();
nuclear@0 47 return 0;
nuclear@0 48 }
nuclear@0 49
nuclear@0 50
nuclear@0 51 static bool init()
nuclear@0 52 {
nuclear@0 53 glewInit();
nuclear@0 54
nuclear@0 55 menu_part = new MainMenu;
nuclear@2 56 if(!menu_part->init()) {
nuclear@2 57 return false;
nuclear@2 58 }
nuclear@2 59
nuclear@0 60 game_part = new Game;
nuclear@2 61 if(!game_part->init()) {
nuclear@2 62 return false;
nuclear@2 63 }
nuclear@2 64
nuclear@3 65 //menu_part->start();
nuclear@3 66 game_part->start();
nuclear@0 67 return true;
nuclear@0 68 }
nuclear@0 69
nuclear@0 70 static void cleanup()
nuclear@0 71 {
nuclear@0 72 delete menu_part;
nuclear@0 73 delete game_part;
nuclear@0 74 }
nuclear@0 75
nuclear@0 76 static void disp()
nuclear@0 77 {
nuclear@0 78 unsigned int msec = glutGet(GLUT_ELAPSED_TIME);
nuclear@0 79 cur_part->update(msec);
nuclear@0 80 cur_part->draw();
nuclear@0 81
nuclear@0 82 glutSwapBuffers();
nuclear@0 83 usleep(1000);
nuclear@0 84 }
nuclear@0 85
nuclear@0 86 static void idle()
nuclear@0 87 {
nuclear@0 88 glutPostRedisplay();
nuclear@0 89 }
nuclear@0 90
nuclear@0 91 static void reshape(int x, int y)
nuclear@0 92 {
nuclear@0 93 glViewport(0, 0, x, y);
nuclear@0 94
nuclear@0 95 cur_part->reshape(x, y);
nuclear@0 96 }
nuclear@0 97
nuclear@0 98 static void key_press(unsigned char key, int x, int y)
nuclear@0 99 {
nuclear@0 100 cur_part->key(key, true);
nuclear@0 101 }
nuclear@0 102
nuclear@0 103 static void key_release(unsigned char key, int x, int y)
nuclear@0 104 {
nuclear@0 105 cur_part->key(key, false);
nuclear@0 106 }
nuclear@0 107
nuclear@0 108 static void mouse(int bn, int state, int x, int y)
nuclear@0 109 {
nuclear@0 110 cur_part->mouse_button(bn - GLUT_LEFT_BUTTON, state == GLUT_DOWN);
nuclear@0 111 }
nuclear@0 112
nuclear@0 113 static void motion(int x, int y)
nuclear@0 114 {
nuclear@0 115 cur_part->mouse_motion(x, y);
nuclear@0 116 }
nuclear@0 117
nuclear@0 118 static int sbmotion[6];
nuclear@0 119
nuclear@0 120 static void sball_motion(int x, int y, int z)
nuclear@0 121 {
nuclear@0 122 sbmotion[0] = x;
nuclear@0 123 sbmotion[1] = y;
nuclear@0 124 sbmotion[2] = z;
nuclear@0 125 cur_part->spaceball_motion(sbmotion[0], sbmotion[1], sbmotion[2],
nuclear@0 126 sbmotion[3], sbmotion[4], sbmotion[5]);
nuclear@0 127 }
nuclear@0 128
nuclear@0 129 static void sball_rotate(int x, int y, int z)
nuclear@0 130 {
nuclear@0 131 sbmotion[3] = x;
nuclear@0 132 sbmotion[4] = y;
nuclear@0 133 sbmotion[5] = z;
nuclear@0 134 cur_part->spaceball_motion(sbmotion[0], sbmotion[1], sbmotion[2],
nuclear@0 135 sbmotion[3], sbmotion[4], sbmotion[5]);
nuclear@0 136 }
nuclear@0 137
nuclear@0 138 static void sball_button(int bn, int state)
nuclear@0 139 {
nuclear@0 140 cur_part->spaceball_button(bn, state == GLUT_DOWN);
nuclear@0 141 }