3dphotoshoot
diff src/pc/camera.c @ 26:a460b1e5af4a
added GLUT frontend
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 18 Jun 2015 03:55:05 +0300 |
parents | ac80210d5fbe |
children | 3d082c566b53 |
line diff
1.1 --- a/src/pc/camera.c Thu Jun 18 03:12:30 2015 +0300 1.2 +++ b/src/pc/camera.c Thu Jun 18 03:55:05 2015 +0300 1.3 @@ -1,42 +1,117 @@ 1.4 +#include <math.h> 1.5 +#include "opengl.h" 1.6 #include "camera.h" 1.7 1.8 +static unsigned int tex; 1.9 +static float tex_matrix[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; 1.10 + 1.11 +#define TESTPAT_WIDTH 256 1.12 +#define TESTPAT_HEIGHT 256 1.13 + 1.14 int cam_init(void *platform_data) 1.15 { 1.16 + unsigned char pal[2][2][3] = { 1.17 + {{255, 128, 64}, {64, 128, 255}}, 1.18 + {{128, 255, 64}, {128, 64, 255}} 1.19 + }; 1.20 + 1.21 + int i, j; 1.22 + unsigned char pixels[TESTPAT_WIDTH * TESTPAT_HEIGHT * 3]; 1.23 + unsigned char *pptr = pixels; 1.24 + 1.25 + for(i=0; i<TESTPAT_HEIGHT; i++) { 1.26 + for(j=0; j<TESTPAT_WIDTH; j++) { 1.27 + int chess = ((i >> 3) & 1) == ((j >> 3) & 1); 1.28 + float x = 2.0 * (float)j / (float)TESTPAT_WIDTH - 1.0; 1.29 + float y = 2.0 * (float)i / (float)TESTPAT_HEIGHT - 1.0; 1.30 + float len = sqrt(x * x + y * y); 1.31 + float wave = cos(len * 4.0 * M_PI); 1.32 + int band = wave >= 0 ? 0 : 1; 1.33 + 1.34 + *pptr++ = pal[band][chess][0]; 1.35 + *pptr++ = pal[band][chess][1]; 1.36 + *pptr++ = pal[band][chess][2]; 1.37 + } 1.38 + } 1.39 + 1.40 + glGenTextures(1, &tex); 1.41 + glBindTexture(GL_TEXTURE_2D, tex); 1.42 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1.43 + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1.44 + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, TESTPAT_WIDTH, TESTPAT_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels); 1.45 + 1.46 + return 0; 1.47 +} 1.48 + 1.49 +void cam_shutdown(void) 1.50 +{ 1.51 + glDeleteTextures(1, &tex); 1.52 +} 1.53 + 1.54 +unsigned int cam_texture(void) 1.55 +{ 1.56 + return tex; 1.57 +} 1.58 + 1.59 +const float *cam_texture_matrix(void) 1.60 +{ 1.61 + return tex_matrix; 1.62 +} 1.63 + 1.64 +int cam_start_video(void) 1.65 +{ 1.66 + return 0; 1.67 +} 1.68 + 1.69 +int cam_stop_video(void) 1.70 +{ 1.71 + return 0; 1.72 +} 1.73 + 1.74 +int cam_update(void) 1.75 +{ 1.76 + return 0; 1.77 +} 1.78 + 1.79 +int cam_is_capturing(void) 1.80 +{ 1.81 + return 1; 1.82 +} 1.83 + 1.84 +int cam_video_size(int *xsz, int *ysz) 1.85 +{ 1.86 + *xsz = TESTPAT_WIDTH; 1.87 + *ysz = TESTPAT_HEIGHT; 1.88 + return 0; 1.89 +} 1.90 + 1.91 +int cam_take_picture(void) 1.92 +{ 1.93 return -1; 1.94 } 1.95 1.96 -void cam_shutdown(void) 1.97 +void cam_draw_preview(void) 1.98 { 1.99 + glPushAttrib(GL_ENABLE_BIT); 1.100 + glDisable(GL_DEPTH_TEST); 1.101 + glDisable(GL_LIGHTING); 1.102 + glEnable(GL_TEXTURE_2D); 1.103 + glDisable(GL_BLEND); 1.104 + 1.105 + glUseProgram(0); 1.106 + 1.107 + glBindTexture(GL_TEXTURE_2D, tex); 1.108 + 1.109 + glBegin(GL_QUADS); 1.110 + glTexCoord2f(0, 0); 1.111 + glVertex2f(-1, -1); 1.112 + glTexCoord2f(1, 0); 1.113 + glVertex2f(1, -1); 1.114 + glTexCoord2f(1, 1); 1.115 + glVertex2f(1, 1); 1.116 + glTexCoord2f(0, 1); 1.117 + glVertex2f(-1, 1); 1.118 + glEnd(); 1.119 + 1.120 + glPopAttrib(); 1.121 } 1.122 - 1.123 -unsigned int cam_texture(void) 1.124 -{ 1.125 -} 1.126 - 1.127 -const float *cam_texture_matrix(void) 1.128 -{ 1.129 -} 1.130 - 1.131 -int cam_start_video(void) 1.132 -{ 1.133 -} 1.134 - 1.135 -int cam_stop_video(void) 1.136 -{ 1.137 -} 1.138 - 1.139 -int cam_update(void) 1.140 -{ 1.141 -} 1.142 - 1.143 -int cam_is_capturing(void) 1.144 -{ 1.145 -} 1.146 - 1.147 -int cam_video_size(int *xsz, int *ysz) 1.148 -{ 1.149 -} 1.150 - 1.151 -int cam_take_picture(void) 1.152 -{ 1.153 -}