3dphotoshoot
view src/game.c @ 8:9fc7d52f578d
FINALLY I'm getting an image out of the camera
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 25 May 2015 04:14:38 +0300 |
parents | 7f6e6eb3d20e |
children | d1b456d08713 |
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 hsz, float vsz);
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);
21 cam_start_video();
22 return 0;
23 }
25 void game_shutdown(void)
26 {
27 cam_shutdown();
28 }
30 void game_display(unsigned long msec)
31 {
32 unsigned int tex = cam_texture();
33 cam_update();
35 //float tsec = (float)msec / 1000.0f;
37 //glClearColor(sin(tsec * 10.0), cos(tsec * 10.0), -sin(tsec * 10.0), 1.0);
38 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
40 glMatrixMode(GL_MODELVIEW);
41 glLoadIdentity();
43 if(tex) {
44 glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex);
45 glEnable(GL_TEXTURE_EXTERNAL_OES);
46 }
48 draw_quad(0.5 * 1.33333, 0.5);
50 if(tex) {
51 glDisable(GL_TEXTURE_EXTERNAL_OES);
52 }
53 }
55 static void draw_quad(float hsz, float vsz)
56 {
57 static const float varr[] = {-1, -1, 1, -1, 1, 1, -1, 1};
58 static const float tcarr[] = {0, 1, 1, 1, 1, 0, 0, 0};
59 static const float colarr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
61 glPushMatrix();
62 glScalef(hsz, vsz, 1);
64 glEnableClientState(GL_VERTEX_ARRAY);
65 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
66 glEnableClientState(GL_COLOR_ARRAY);
68 glVertexPointer(2, GL_FLOAT, 0, varr);
69 glTexCoordPointer(2, GL_FLOAT, 0, tcarr);
70 glColorPointer(4, GL_FLOAT, 0, colarr);
72 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
74 glDisableClientState(GL_VERTEX_ARRAY);
75 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
76 glDisableClientState(GL_COLOR_ARRAY);
78 glPopMatrix();
79 }
81 void game_reshape(int x, int y)
82 {
83 win_width = x;
84 win_height = y;
85 glViewport(0, 0, x, y);
87 glMatrixMode(GL_PROJECTION);
88 glLoadIdentity();
89 glScalef((float)win_height / (float)win_width, 1.0, 1.0);
90 }
92 void game_keyboard(int key, int pressed)
93 {
94 if(!pressed) return;
96 switch(key) {
97 case 27:
98 exit(0);
100 default:
101 break;
102 }
103 }
105 #define MAX_TOUCH_IDS 16
106 static struct {
107 int bnstate[8];
108 int prev_x, prev_y;
109 } mstate[MAX_TOUCH_IDS];
111 void game_mouse_button(int id, int bn, int pressed, int x, int y)
112 {
113 if(id >= MAX_TOUCH_IDS) return;
115 mstate[id].prev_x = x;
116 mstate[id].prev_y = y;
117 mstate[id].bnstate[bn] = pressed;
118 }
120 void game_mouse_motion(int id, int x, int y)
121 {
122 /*
123 int dx, dy, cx, cy;
125 if(id >= MAX_TOUCH_IDS) return;
127 cx = win_width / 2;
128 cy = win_height / 2;
130 dx = x - mstate[id].prev_x;
131 dy = y - mstate[id].prev_y;
132 mstate[id].prev_x = x;
133 mstate[id].prev_y = y;
135 if(!dx && !dy) return;
137 if(mouselook || mstate[id].bnstate[0]) {
138 player_turn(&player, dx * 0.5, dy * 0.5);
139 }
140 if(mstate[id].bnstate[2]) {
141 dbg_cam_dist += 0.1 * dy;
142 if(dbg_cam_dist < 0.0) dbg_cam_dist = 0.0;
143 }
145 if(mouselook) {
146 warping_mouse = 1;
147 set_mouse_pos(cx, cy);
148 mstate[id].prev_x = cx;
149 mstate[id].prev_y = cy;
150 }
151 */
152 }