doorbell
view spycam/src/spycam.cc @ 7:dc4018af3a40
video broadcast with UDP. retarded amount of data, unusable.
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 16 Mar 2016 02:50:30 +0200 |
parents | |
children |
line source
1 #include <GLES2/gl2.h>
2 #include <gmath/gmath.h>
3 #include "spycam.h"
4 #include "sdr.h"
6 static unsigned int sdr_prog, tex;
7 static Mat4 world_matrix, view_matrix, proj_matrix;
8 static int win_width, win_height;
10 bool app_init()
11 {
12 glClearColor(0.2, 0.2, 0.2, 1);
14 if(!(sdr_prog = create_program_load("sdr/vertex.glsl", "sdr/pixel.glsl"))) {
15 fprintf(stderr, "failed to load shader program\n");
16 return false;
17 }
18 glUseProgram(sdr_prog);
19 glBindAttribLocation(sdr_prog, 0, "a_vertex");
20 glBindAttribLocation(sdr_prog, 1, "a_texcoord");
22 unsigned char *pixels = new unsigned char[256 * 256 * 3];
23 unsigned char *pptr = pixels;
24 for(int i=0; i<256; i++) {
25 for(int j=0; j<256; j++) {
26 bool chess = ((i >> 4) & 1) == ((j >> 4) & 1);
27 *pptr++ = chess ? 255 : 64;
28 *pptr++ = 128;
29 *pptr++ = chess ? 64 : 255;
30 }
31 }
33 glGenTextures(1, &tex);
34 glBindTexture(GL_TEXTURE_2D, tex);
35 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
36 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
37 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
38 glGenerateMipmap(GL_TEXTURE_2D);
39 delete [] pixels;
41 return true;
42 }
44 void app_cleanup()
45 {
46 }
48 void app_draw()
49 {
50 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
52 glUseProgram(sdr_prog);
53 set_uniform_matrix4(sdr_prog, "world_mat", world_matrix[0]);
54 set_uniform_matrix4(sdr_prog, "view_mat", view_matrix[0]);
55 set_uniform_matrix4(sdr_prog, "proj_mat", proj_matrix[0]);
57 glBindTexture(GL_TEXTURE_2D, tex);
59 static const float quad_verts[] = {-1, -1, 1, -1, 1, 1, -1, 1};
60 static const float quad_texcoords[] = {0, 0, 1, 0, 1, 1, 0, 1};
61 static const unsigned int quad_idx[] = {0, 1, 2, 0, 2, 3};
63 glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, quad_verts);
64 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, quad_texcoords);
65 glEnableVertexAttribArray(0);
66 glEnableVertexAttribArray(1);
68 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, quad_idx);
70 glDisableVertexAttribArray(0);
71 glDisableVertexAttribArray(1);
72 }
74 void app_reshape(int x, int y)
75 {
76 win_width = x;
77 win_height = y;
78 glViewport(0, 0, x, y);
79 }
81 void app_keyboard(int key, bool press)
82 {
83 if(press) {
84 switch(key) {
85 case 27:
86 app_quit();
87 break;
88 }
89 }
90 }
92 void app_mouse_button(int bn, bool press, int x, int y)
93 {
94 }
96 void app_mouse_motion(int x, int y)
97 {
98 }