3dphotoshoot

view src/game.c @ 7:7f6e6eb3d20e

some progress...
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 23 May 2015 23:14:44 +0300
parents 38377f54527a
children 9fc7d52f578d
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <math.h>
4 #include "opengl.h"
5 #include "game.h"
6 #include "camera.h"
8 static void draw_quad(float sz);
10 static int win_width, win_height;
13 int game_init(void)
14 {
15 glEnable(GL_DEPTH_TEST);
16 glEnable(GL_CULL_FACE);
17 //glEnable(GL_LIGHTING);
19 glClearColor(0.4, 0.4, 0.4, 1);
20 return 0;
21 }
23 void game_shutdown(void)
24 {
25 }
27 void game_display(unsigned long msec)
28 {
29 unsigned int tex = cam_texture();
30 //cam_update();
32 //float tsec = (float)msec / 1000.0f;
34 //glClearColor(sin(tsec * 10.0), cos(tsec * 10.0), -sin(tsec * 10.0), 1.0);
35 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
37 glMatrixMode(GL_MODELVIEW);
38 glLoadIdentity();
40 if(tex) {
41 glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex);
42 glEnable(GL_TEXTURE_EXTERNAL_OES);
44 draw_quad(0.5);
46 glDisable(GL_TEXTURE_EXTERNAL_OES);
47 }
48 }
50 static void draw_quad(float sz)
51 {
52 static const float varr[] = {-1, -1, 1, -1, 1, 1, -1, 1};
53 static const float tcarr[] = {0, 0, 1, 0, 1, 1, 0, 1};
54 static const float colarr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
56 glPushMatrix();
57 glScalef(sz, sz, sz);
59 glEnableClientState(GL_VERTEX_ARRAY);
60 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
61 glEnableClientState(GL_COLOR_ARRAY);
63 glVertexPointer(2, GL_FLOAT, 0, varr);
64 glTexCoordPointer(2, GL_FLOAT, 0, tcarr);
65 glColorPointer(3, GL_FLOAT, 0, colarr);
67 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
69 glDisableClientState(GL_VERTEX_ARRAY);
70 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
71 glDisableClientState(GL_COLOR_ARRAY);
73 glPopMatrix();
74 }
76 void game_reshape(int x, int y)
77 {
78 win_width = x;
79 win_height = y;
80 glViewport(0, 0, x, y);
82 glMatrixMode(GL_PROJECTION);
83 glLoadIdentity();
84 glScalef((float)win_height / (float)win_width, 1.0, 1.0);
85 }
87 void game_keyboard(int key, int pressed)
88 {
89 if(!pressed) return;
91 switch(key) {
92 case 27:
93 exit(0);
95 default:
96 break;
97 }
98 }
100 #define MAX_TOUCH_IDS 16
101 static struct {
102 int bnstate[8];
103 int prev_x, prev_y;
104 } mstate[MAX_TOUCH_IDS];
106 void game_mouse_button(int id, int bn, int pressed, int x, int y)
107 {
108 if(id >= MAX_TOUCH_IDS) return;
110 mstate[id].prev_x = x;
111 mstate[id].prev_y = y;
112 mstate[id].bnstate[bn] = pressed;
113 }
115 void game_mouse_motion(int id, int x, int y)
116 {
117 /*
118 int dx, dy, cx, cy;
120 if(id >= MAX_TOUCH_IDS) return;
122 cx = win_width / 2;
123 cy = win_height / 2;
125 dx = x - mstate[id].prev_x;
126 dy = y - mstate[id].prev_y;
127 mstate[id].prev_x = x;
128 mstate[id].prev_y = y;
130 if(!dx && !dy) return;
132 if(mouselook || mstate[id].bnstate[0]) {
133 player_turn(&player, dx * 0.5, dy * 0.5);
134 }
135 if(mstate[id].bnstate[2]) {
136 dbg_cam_dist += 0.1 * dy;
137 if(dbg_cam_dist < 0.0) dbg_cam_dist = 0.0;
138 }
140 if(mouselook) {
141 warping_mouse = 1;
142 set_mouse_pos(cx, cy);
143 mstate[id].prev_x = cx;
144 mstate[id].prev_y = cy;
145 }
146 */
147 }