nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: #include "opengl.h" nuclear@0: #include "game.h" nuclear@7: #include "camera.h" nuclear@7: nuclear@7: static void draw_quad(float sz); nuclear@0: nuclear@0: static int win_width, win_height; nuclear@0: nuclear@0: nuclear@0: int game_init(void) nuclear@0: { nuclear@0: glEnable(GL_DEPTH_TEST); nuclear@0: glEnable(GL_CULL_FACE); nuclear@7: //glEnable(GL_LIGHTING); nuclear@0: nuclear@0: glClearColor(0.4, 0.4, 0.4, 1); nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: void game_shutdown(void) nuclear@0: { nuclear@0: } nuclear@0: nuclear@0: void game_display(unsigned long msec) nuclear@0: { nuclear@7: unsigned int tex = cam_texture(); nuclear@7: //cam_update(); nuclear@7: nuclear@4: //float tsec = (float)msec / 1000.0f; nuclear@0: nuclear@4: //glClearColor(sin(tsec * 10.0), cos(tsec * 10.0), -sin(tsec * 10.0), 1.0); nuclear@0: glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); nuclear@0: nuclear@0: glMatrixMode(GL_MODELVIEW); nuclear@0: glLoadIdentity(); nuclear@7: nuclear@7: if(tex) { nuclear@7: glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex); nuclear@7: glEnable(GL_TEXTURE_EXTERNAL_OES); nuclear@7: nuclear@7: draw_quad(0.5); nuclear@7: nuclear@7: glDisable(GL_TEXTURE_EXTERNAL_OES); nuclear@7: } nuclear@7: } nuclear@7: nuclear@7: static void draw_quad(float sz) nuclear@7: { nuclear@7: static const float varr[] = {-1, -1, 1, -1, 1, 1, -1, 1}; nuclear@7: static const float tcarr[] = {0, 0, 1, 0, 1, 1, 0, 1}; nuclear@7: static const float colarr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; nuclear@7: nuclear@7: glPushMatrix(); nuclear@7: glScalef(sz, sz, sz); nuclear@7: nuclear@7: glEnableClientState(GL_VERTEX_ARRAY); nuclear@7: glEnableClientState(GL_TEXTURE_COORD_ARRAY); nuclear@7: glEnableClientState(GL_COLOR_ARRAY); nuclear@7: nuclear@7: glVertexPointer(2, GL_FLOAT, 0, varr); nuclear@7: glTexCoordPointer(2, GL_FLOAT, 0, tcarr); nuclear@7: glColorPointer(3, GL_FLOAT, 0, colarr); nuclear@7: nuclear@7: glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); nuclear@7: nuclear@7: glDisableClientState(GL_VERTEX_ARRAY); nuclear@7: glDisableClientState(GL_TEXTURE_COORD_ARRAY); nuclear@7: glDisableClientState(GL_COLOR_ARRAY); nuclear@7: nuclear@7: glPopMatrix(); nuclear@0: } nuclear@0: nuclear@0: void game_reshape(int x, int y) nuclear@0: { nuclear@0: win_width = x; nuclear@0: win_height = y; nuclear@0: glViewport(0, 0, x, y); nuclear@0: nuclear@0: glMatrixMode(GL_PROJECTION); nuclear@0: glLoadIdentity(); nuclear@0: glScalef((float)win_height / (float)win_width, 1.0, 1.0); nuclear@0: } nuclear@0: nuclear@0: void game_keyboard(int key, int pressed) nuclear@0: { nuclear@0: if(!pressed) return; nuclear@0: nuclear@0: switch(key) { nuclear@0: case 27: nuclear@0: exit(0); nuclear@0: nuclear@0: default: nuclear@0: break; nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: #define MAX_TOUCH_IDS 16 nuclear@0: static struct { nuclear@0: int bnstate[8]; nuclear@0: int prev_x, prev_y; nuclear@0: } mstate[MAX_TOUCH_IDS]; nuclear@0: nuclear@0: void game_mouse_button(int id, int bn, int pressed, int x, int y) nuclear@0: { nuclear@0: if(id >= MAX_TOUCH_IDS) return; nuclear@0: nuclear@0: mstate[id].prev_x = x; nuclear@0: mstate[id].prev_y = y; nuclear@0: mstate[id].bnstate[bn] = pressed; nuclear@0: } nuclear@0: nuclear@0: void game_mouse_motion(int id, int x, int y) nuclear@0: { nuclear@0: /* nuclear@0: int dx, dy, cx, cy; nuclear@0: nuclear@0: if(id >= MAX_TOUCH_IDS) return; nuclear@0: nuclear@0: cx = win_width / 2; nuclear@0: cy = win_height / 2; nuclear@0: nuclear@0: dx = x - mstate[id].prev_x; nuclear@0: dy = y - mstate[id].prev_y; nuclear@0: mstate[id].prev_x = x; nuclear@0: mstate[id].prev_y = y; nuclear@0: nuclear@0: if(!dx && !dy) return; nuclear@0: nuclear@0: if(mouselook || mstate[id].bnstate[0]) { nuclear@0: player_turn(&player, dx * 0.5, dy * 0.5); nuclear@0: } nuclear@0: if(mstate[id].bnstate[2]) { nuclear@0: dbg_cam_dist += 0.1 * dy; nuclear@0: if(dbg_cam_dist < 0.0) dbg_cam_dist = 0.0; nuclear@0: } nuclear@0: nuclear@0: if(mouselook) { nuclear@0: warping_mouse = 1; nuclear@0: set_mouse_pos(cx, cy); nuclear@0: mstate[id].prev_x = cx; nuclear@0: mstate[id].prev_y = cy; nuclear@0: } nuclear@0: */ nuclear@0: } nuclear@0: