3dphotoshoot
view src/pc/camera.c @ 27:3d082c566b53
fixed all the bugs, pc version works
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 18 Jun 2015 04:32:25 +0300 |
parents | a460b1e5af4a |
children |
line source
1 #include <math.h>
2 #include "opengl.h"
3 #include "camera.h"
5 static unsigned int tex;
6 static float tex_matrix[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1};
8 #define TESTPAT_WIDTH 256
9 #define TESTPAT_HEIGHT 256
11 int cam_init(void *platform_data)
12 {
13 unsigned char pal[2][2][3] = {
14 {{255, 128, 64}, {64, 128, 255}},
15 {{128, 255, 64}, {128, 64, 255}}
16 };
18 int i, j;
19 unsigned char pixels[TESTPAT_WIDTH * TESTPAT_HEIGHT * 3];
20 unsigned char *pptr = pixels;
22 for(i=0; i<TESTPAT_HEIGHT; i++) {
23 for(j=0; j<TESTPAT_WIDTH; j++) {
24 int chess = ((i >> 3) & 1) == ((j >> 3) & 1);
25 float x = 2.0 * (float)j / (float)TESTPAT_WIDTH - 1.0;
26 float y = 2.0 * (float)i / (float)TESTPAT_HEIGHT - 1.0;
27 float len = sqrt(x * x + y * y);
28 float wave = cos(len * 4.0 * M_PI);
29 int band = wave >= 0 ? 0 : 1;
31 *pptr++ = pal[band][chess][0] / 2;
32 *pptr++ = pal[band][chess][1] / 2;
33 *pptr++ = pal[band][chess][2] / 2;
34 }
35 }
37 glGenTextures(1, &tex);
38 glBindTexture(GL_TEXTURE_2D, tex);
39 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
40 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
41 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TESTPAT_WIDTH, TESTPAT_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
43 return 0;
44 }
46 void cam_shutdown(void)
47 {
48 glDeleteTextures(1, &tex);
49 }
51 unsigned int cam_texture(void)
52 {
53 return tex;
54 }
56 const float *cam_texture_matrix(void)
57 {
58 return tex_matrix;
59 }
61 int cam_start_video(void)
62 {
63 return 0;
64 }
66 int cam_stop_video(void)
67 {
68 return 0;
69 }
71 int cam_update(void)
72 {
73 return 0;
74 }
76 int cam_is_capturing(void)
77 {
78 return 1;
79 }
81 int cam_video_size(int *xsz, int *ysz)
82 {
83 *xsz = TESTPAT_WIDTH;
84 *ysz = TESTPAT_HEIGHT;
85 return 0;
86 }
88 int cam_take_picture(void)
89 {
90 return -1;
91 }
93 void cam_draw_preview(void)
94 {
95 glPushAttrib(GL_ENABLE_BIT);
96 glDisable(GL_DEPTH_TEST);
97 glDisable(GL_LIGHTING);
98 glEnable(GL_TEXTURE_2D);
99 glDisable(GL_BLEND);
101 glUseProgram(0);
103 glBindTexture(GL_TEXTURE_2D, tex);
105 glBegin(GL_QUADS);
106 glTexCoord2f(0, 0);
107 glVertex2f(-1, -1);
108 glTexCoord2f(1, 0);
109 glVertex2f(1, -1);
110 glTexCoord2f(1, 1);
111 glVertex2f(1, 1);
112 glTexCoord2f(0, 1);
113 glVertex2f(-1, 1);
114 glEnd();
116 glPopAttrib();
117 }