doorbell

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