3dphotoshoot

annotate 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
rev   line source
nuclear@0 1 #include <stdio.h>
nuclear@0 2 #include <stdlib.h>
nuclear@0 3 #include <math.h>
nuclear@0 4 #include "opengl.h"
nuclear@0 5 #include "game.h"
nuclear@7 6 #include "camera.h"
nuclear@7 7
nuclear@8 8 static void draw_quad(float hsz, float vsz);
nuclear@0 9
nuclear@0 10 static int win_width, win_height;
nuclear@0 11
nuclear@0 12
nuclear@0 13 int game_init(void)
nuclear@0 14 {
nuclear@0 15 glEnable(GL_DEPTH_TEST);
nuclear@0 16 glEnable(GL_CULL_FACE);
nuclear@7 17 //glEnable(GL_LIGHTING);
nuclear@0 18
nuclear@0 19 glClearColor(0.4, 0.4, 0.4, 1);
nuclear@8 20
nuclear@8 21 cam_start_video();
nuclear@0 22 return 0;
nuclear@0 23 }
nuclear@0 24
nuclear@0 25 void game_shutdown(void)
nuclear@0 26 {
nuclear@8 27 cam_shutdown();
nuclear@0 28 }
nuclear@0 29
nuclear@0 30 void game_display(unsigned long msec)
nuclear@0 31 {
nuclear@7 32 unsigned int tex = cam_texture();
nuclear@8 33 cam_update();
nuclear@7 34
nuclear@4 35 //float tsec = (float)msec / 1000.0f;
nuclear@0 36
nuclear@4 37 //glClearColor(sin(tsec * 10.0), cos(tsec * 10.0), -sin(tsec * 10.0), 1.0);
nuclear@0 38 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
nuclear@0 39
nuclear@0 40 glMatrixMode(GL_MODELVIEW);
nuclear@0 41 glLoadIdentity();
nuclear@7 42
nuclear@7 43 if(tex) {
nuclear@7 44 glBindTexture(GL_TEXTURE_EXTERNAL_OES, tex);
nuclear@7 45 glEnable(GL_TEXTURE_EXTERNAL_OES);
nuclear@8 46 }
nuclear@7 47
nuclear@8 48 draw_quad(0.5 * 1.33333, 0.5);
nuclear@7 49
nuclear@8 50 if(tex) {
nuclear@7 51 glDisable(GL_TEXTURE_EXTERNAL_OES);
nuclear@7 52 }
nuclear@7 53 }
nuclear@7 54
nuclear@8 55 static void draw_quad(float hsz, float vsz)
nuclear@7 56 {
nuclear@7 57 static const float varr[] = {-1, -1, 1, -1, 1, 1, -1, 1};
nuclear@8 58 static const float tcarr[] = {0, 1, 1, 1, 1, 0, 0, 0};
nuclear@8 59 static const float colarr[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
nuclear@7 60
nuclear@7 61 glPushMatrix();
nuclear@8 62 glScalef(hsz, vsz, 1);
nuclear@7 63
nuclear@7 64 glEnableClientState(GL_VERTEX_ARRAY);
nuclear@7 65 glEnableClientState(GL_TEXTURE_COORD_ARRAY);
nuclear@7 66 glEnableClientState(GL_COLOR_ARRAY);
nuclear@7 67
nuclear@7 68 glVertexPointer(2, GL_FLOAT, 0, varr);
nuclear@7 69 glTexCoordPointer(2, GL_FLOAT, 0, tcarr);
nuclear@8 70 glColorPointer(4, GL_FLOAT, 0, colarr);
nuclear@7 71
nuclear@8 72 glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
nuclear@7 73
nuclear@7 74 glDisableClientState(GL_VERTEX_ARRAY);
nuclear@7 75 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
nuclear@7 76 glDisableClientState(GL_COLOR_ARRAY);
nuclear@7 77
nuclear@7 78 glPopMatrix();
nuclear@0 79 }
nuclear@0 80
nuclear@0 81 void game_reshape(int x, int y)
nuclear@0 82 {
nuclear@0 83 win_width = x;
nuclear@0 84 win_height = y;
nuclear@0 85 glViewport(0, 0, x, y);
nuclear@0 86
nuclear@0 87 glMatrixMode(GL_PROJECTION);
nuclear@0 88 glLoadIdentity();
nuclear@0 89 glScalef((float)win_height / (float)win_width, 1.0, 1.0);
nuclear@0 90 }
nuclear@0 91
nuclear@0 92 void game_keyboard(int key, int pressed)
nuclear@0 93 {
nuclear@0 94 if(!pressed) return;
nuclear@0 95
nuclear@0 96 switch(key) {
nuclear@0 97 case 27:
nuclear@0 98 exit(0);
nuclear@0 99
nuclear@0 100 default:
nuclear@0 101 break;
nuclear@0 102 }
nuclear@0 103 }
nuclear@0 104
nuclear@0 105 #define MAX_TOUCH_IDS 16
nuclear@0 106 static struct {
nuclear@0 107 int bnstate[8];
nuclear@0 108 int prev_x, prev_y;
nuclear@0 109 } mstate[MAX_TOUCH_IDS];
nuclear@0 110
nuclear@0 111 void game_mouse_button(int id, int bn, int pressed, int x, int y)
nuclear@0 112 {
nuclear@0 113 if(id >= MAX_TOUCH_IDS) return;
nuclear@0 114
nuclear@0 115 mstate[id].prev_x = x;
nuclear@0 116 mstate[id].prev_y = y;
nuclear@0 117 mstate[id].bnstate[bn] = pressed;
nuclear@0 118 }
nuclear@0 119
nuclear@0 120 void game_mouse_motion(int id, int x, int y)
nuclear@0 121 {
nuclear@0 122 /*
nuclear@0 123 int dx, dy, cx, cy;
nuclear@0 124
nuclear@0 125 if(id >= MAX_TOUCH_IDS) return;
nuclear@0 126
nuclear@0 127 cx = win_width / 2;
nuclear@0 128 cy = win_height / 2;
nuclear@0 129
nuclear@0 130 dx = x - mstate[id].prev_x;
nuclear@0 131 dy = y - mstate[id].prev_y;
nuclear@0 132 mstate[id].prev_x = x;
nuclear@0 133 mstate[id].prev_y = y;
nuclear@0 134
nuclear@0 135 if(!dx && !dy) return;
nuclear@0 136
nuclear@0 137 if(mouselook || mstate[id].bnstate[0]) {
nuclear@0 138 player_turn(&player, dx * 0.5, dy * 0.5);
nuclear@0 139 }
nuclear@0 140 if(mstate[id].bnstate[2]) {
nuclear@0 141 dbg_cam_dist += 0.1 * dy;
nuclear@0 142 if(dbg_cam_dist < 0.0) dbg_cam_dist = 0.0;
nuclear@0 143 }
nuclear@0 144
nuclear@0 145 if(mouselook) {
nuclear@0 146 warping_mouse = 1;
nuclear@0 147 set_mouse_pos(cx, cy);
nuclear@0 148 mstate[id].prev_x = cx;
nuclear@0 149 mstate[id].prev_y = cy;
nuclear@0 150 }
nuclear@0 151 */
nuclear@0 152 }
nuclear@0 153