3dphotoshoot
diff src/game.c @ 0:a4bf2687e406
3d photoshoot initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 12 May 2015 05:31:21 +0300 |
parents | |
children | 38377f54527a |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/game.c Tue May 12 05:31:21 2015 +0300 1.3 @@ -0,0 +1,107 @@ 1.4 +#include <stdio.h> 1.5 +#include <stdlib.h> 1.6 +#include <math.h> 1.7 +#include "opengl.h" 1.8 +#include "game.h" 1.9 + 1.10 +static int win_width, win_height; 1.11 + 1.12 + 1.13 +int game_init(void) 1.14 +{ 1.15 + glEnable(GL_DEPTH_TEST); 1.16 + glEnable(GL_CULL_FACE); 1.17 + glEnable(GL_LIGHTING); 1.18 + 1.19 + glClearColor(0.4, 0.4, 0.4, 1); 1.20 + return 0; 1.21 +} 1.22 + 1.23 +void game_shutdown(void) 1.24 +{ 1.25 +} 1.26 + 1.27 +void game_display(unsigned long msec) 1.28 +{ 1.29 + float tsec = (float)msec / 1000.0f; 1.30 + 1.31 + glClearColor(sin(tsec * 10.0), cos(tsec * 10.0), -sin(tsec * 10.0), 1.0); 1.32 + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1.33 + 1.34 + glMatrixMode(GL_MODELVIEW); 1.35 + glLoadIdentity(); 1.36 +} 1.37 + 1.38 +void game_reshape(int x, int y) 1.39 +{ 1.40 + win_width = x; 1.41 + win_height = y; 1.42 + glViewport(0, 0, x, y); 1.43 + 1.44 + glMatrixMode(GL_PROJECTION); 1.45 + glLoadIdentity(); 1.46 + glScalef((float)win_height / (float)win_width, 1.0, 1.0); 1.47 +} 1.48 + 1.49 +void game_keyboard(int key, int pressed) 1.50 +{ 1.51 + if(!pressed) return; 1.52 + 1.53 + switch(key) { 1.54 + case 27: 1.55 + exit(0); 1.56 + 1.57 + default: 1.58 + break; 1.59 + } 1.60 +} 1.61 + 1.62 +#define MAX_TOUCH_IDS 16 1.63 +static struct { 1.64 + int bnstate[8]; 1.65 + int prev_x, prev_y; 1.66 +} mstate[MAX_TOUCH_IDS]; 1.67 + 1.68 +void game_mouse_button(int id, int bn, int pressed, int x, int y) 1.69 +{ 1.70 + if(id >= MAX_TOUCH_IDS) return; 1.71 + 1.72 + mstate[id].prev_x = x; 1.73 + mstate[id].prev_y = y; 1.74 + mstate[id].bnstate[bn] = pressed; 1.75 +} 1.76 + 1.77 +void game_mouse_motion(int id, int x, int y) 1.78 +{ 1.79 + /* 1.80 + int dx, dy, cx, cy; 1.81 + 1.82 + if(id >= MAX_TOUCH_IDS) return; 1.83 + 1.84 + cx = win_width / 2; 1.85 + cy = win_height / 2; 1.86 + 1.87 + dx = x - mstate[id].prev_x; 1.88 + dy = y - mstate[id].prev_y; 1.89 + mstate[id].prev_x = x; 1.90 + mstate[id].prev_y = y; 1.91 + 1.92 + if(!dx && !dy) return; 1.93 + 1.94 + if(mouselook || mstate[id].bnstate[0]) { 1.95 + player_turn(&player, dx * 0.5, dy * 0.5); 1.96 + } 1.97 + if(mstate[id].bnstate[2]) { 1.98 + dbg_cam_dist += 0.1 * dy; 1.99 + if(dbg_cam_dist < 0.0) dbg_cam_dist = 0.0; 1.100 + } 1.101 + 1.102 + if(mouselook) { 1.103 + warping_mouse = 1; 1.104 + set_mouse_pos(cx, cy); 1.105 + mstate[id].prev_x = cx; 1.106 + mstate[id].prev_y = cy; 1.107 + } 1.108 + */ 1.109 +} 1.110 +