nuclear@0: #include nuclear@0: #include nuclear@0: #include "game.h" nuclear@1: #include "board.h" nuclear@0: nuclear@0: static void draw_backdrop(); nuclear@0: nuclear@0: int win_width, win_height; nuclear@0: nuclear@1: static Board board; nuclear@1: nuclear@5: static float cam_theta, cam_phi = 25, cam_dist = 3; nuclear@0: static bool bnstate[8]; nuclear@0: static int prev_x, prev_y; nuclear@0: nuclear@0: nuclear@0: bool game_init() nuclear@0: { nuclear@0: glEnable(GL_DEPTH_TEST); nuclear@0: glEnable(GL_CULL_FACE); nuclear@0: nuclear@0: glEnable(GL_LIGHTING); nuclear@0: glEnable(GL_LIGHT0); nuclear@0: nuclear@5: if(GLEW_ARB_multisample) { nuclear@5: glEnable(GL_MULTISAMPLE); nuclear@5: } nuclear@5: nuclear@1: if(!board.init()) { nuclear@1: return false; nuclear@1: } nuclear@1: nuclear@0: return true; nuclear@0: } nuclear@0: nuclear@0: void game_cleanup() nuclear@0: { nuclear@1: board.destroy(); nuclear@0: } nuclear@0: nuclear@0: void game_update(unsigned long time_msec) nuclear@0: { nuclear@0: } nuclear@0: nuclear@0: void game_display() nuclear@0: { nuclear@0: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); nuclear@0: nuclear@0: glMatrixMode(GL_MODELVIEW); nuclear@0: glLoadIdentity(); nuclear@0: glTranslatef(0, 0, -cam_dist); nuclear@0: glRotatef(cam_phi, 1, 0, 0); nuclear@0: glRotatef(cam_theta, 0, 1, 0); nuclear@0: nuclear@0: draw_backdrop(); nuclear@0: nuclear@1: board.draw(); nuclear@0: } nuclear@0: nuclear@0: static void draw_backdrop() nuclear@0: { nuclear@0: glPushAttrib(GL_ENABLE_BIT); nuclear@0: glDisable(GL_LIGHTING); nuclear@0: glDisable(GL_DEPTH_TEST); nuclear@0: nuclear@0: glMatrixMode(GL_PROJECTION); nuclear@0: glPushMatrix(); nuclear@0: glLoadIdentity(); nuclear@0: glMatrixMode(GL_MODELVIEW); nuclear@0: glPushMatrix(); nuclear@0: glLoadIdentity(); nuclear@0: nuclear@0: glBegin(GL_QUADS); nuclear@0: glColor3f(0.9, 0.8, 0.6); nuclear@0: glVertex2f(-1, -1); nuclear@0: glVertex2f(1, -1); nuclear@0: glColor3f(0.4, 0.5, 0.8); nuclear@0: glVertex2f(1, 1); nuclear@0: glVertex2f(-1, 1); nuclear@0: glEnd(); nuclear@0: nuclear@0: glMatrixMode(GL_PROJECTION); nuclear@0: glPopMatrix(); nuclear@0: glMatrixMode(GL_MODELVIEW); nuclear@0: glPopMatrix(); nuclear@0: nuclear@0: glPopAttrib(); nuclear@0: } nuclear@0: nuclear@0: void game_reshape(int x, int y) nuclear@0: { nuclear@0: glMatrixMode(GL_PROJECTION); nuclear@0: glLoadIdentity(); nuclear@5: gluPerspective(45, (float)x / (float)y, 0.2, 200.0); nuclear@0: nuclear@0: glViewport(0, 0, x, y); nuclear@0: } nuclear@0: nuclear@0: void game_keyboard(int bn, bool press) nuclear@0: { nuclear@0: if(press) { nuclear@0: switch(bn) { nuclear@0: case 27: nuclear@0: quit(); nuclear@0: } nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: void game_mbutton(int bn, bool press, int x, int y) nuclear@0: { nuclear@0: bnstate[bn] = press; nuclear@0: prev_x = x; nuclear@0: prev_y = y; nuclear@0: } nuclear@0: nuclear@0: void game_mmotion(int x, int y) nuclear@0: { nuclear@0: int dx = x - prev_x; nuclear@0: int dy = y - prev_y; nuclear@0: prev_x = x; nuclear@0: prev_y = y; nuclear@0: nuclear@0: if(bnstate[0]) { nuclear@0: cam_theta += dx * 0.5; nuclear@0: cam_phi += dy * 0.5; nuclear@0: nuclear@0: if(cam_phi < -90) cam_phi = -90; nuclear@0: if(cam_phi > 90) cam_phi = 90; nuclear@0: nuclear@0: redisplay(); nuclear@0: } nuclear@0: if(bnstate[2]) { nuclear@0: cam_dist += dy * 0.1; nuclear@0: if(cam_dist < 0.0) cam_dist = 0.0; nuclear@0: nuclear@0: redisplay(); nuclear@0: } nuclear@0: }