# HG changeset patch # User Eleni Maria Stea # Date 1384722160 -7200 # Node ID 61d593076c56d54f9fcd38b55c380737aa9c201f # Parent 96b022f1210e437a4697bc2ebd5c971967d26572 foo diff -r 96b022f1210e -r 61d593076c56 data/shaders/invisible.v.glsl --- a/data/shaders/invisible.v.glsl Sun Nov 17 12:46:45 2013 +0200 +++ b/data/shaders/invisible.v.glsl Sun Nov 17 23:02:40 2013 +0200 @@ -4,7 +4,7 @@ void main() { const float threshold = 0.8; - const float scale = 4.0; + const float scale = 5.0; float texel = texture2D(depth_tex, gl_MultiTexCoord0.xy).r; vec4 vpos = gl_Vertex; diff -r 96b022f1210e -r 61d593076c56 src/main.cc --- a/src/main.cc Sun Nov 17 12:46:45 2013 +0200 +++ b/src/main.cc Sun Nov 17 23:02:40 2013 +0200 @@ -18,7 +18,7 @@ KinectParams kin_params; Frame *frame; -static const char *filename = "data/textures/wallpaper.jpg"; +static const char *filename = "data/textures/wp2.jpg"; static const char *vsdr_path = "data/shaders/invisible.v.glsl"; static const char *fsdr_path = "data/shaders/invisible.f.glsl"; static unsigned char tex; @@ -30,6 +30,13 @@ static float aspect; static bool show; static bool wireframe; +static bool fullscreen; + +static float phi = 0; +static float theta = 0; +static float distance = 10; +static int prev_x = -1, prev_y = -1; +static int bn; static void cleanup(); static bool init(); @@ -38,6 +45,8 @@ static void display(); static void reshape(int w, int h); static void keyb(unsigned char key, int x, int y); +static void mouse(int button, int status, int x, int y); +static void motion(int x, int y); static void idle(); bool has_video; @@ -63,6 +72,8 @@ glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyb); + glutMouseFunc(mouse); + glutMotionFunc(motion); glutIdleFunc(idle); atexit(cleanup); @@ -73,13 +84,63 @@ glutMainLoop(); } +static bool init() +{ + glClearColor(1, 0, 0, 1); + + frame = new Frame; + if(!(tex = load_texture(filename, &tex_width, &tex_height))) { + fprintf(stderr, "Failed to load texture: %s\n", filename); + return false; + } + + /* shaders setup */ + if(!(sprog = sdr_getprog(vsdr_path, fsdr_path))) { + fprintf(stderr, "Failed to create shader program!\n"); + return false; + } + + glUseProgram(sprog); + int dloc = glGetUniformLocation(sprog, "depth_tex"); + if(dloc != -1) + glUniform1i(dloc, 1); + int tloc = glGetUniformLocation(sprog, "tex"); + if(tloc != -1) + glUniform1i(tloc, 0); + glUseProgram(0); + + /* debugging */ + debugging = glGenLists(1); + glNewList(debugging, GL_COMPILE); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, frame->video_tex); + draw_tess_quad(-1, -1, 1, 2, 1, 1, true); + glBindTexture(GL_TEXTURE_2D, frame->depth_tex); + draw_tess_quad(0, -1, 1, 2, 1, 1, true); + glDisable(GL_TEXTURE_2D); + glEndList(); + + return true; +} + +static void init_tessquad() +{ + if(drawing) + glDeleteLists(drawing, 1); + + drawing = glGenLists(1); + glNewList(drawing, GL_COMPILE); + float fov_rads = FOV / 180.0 * M_PI; + float ysz = QUAD_DIST * tan(fov_rads / 2.0); + float xsz = ysz * aspect; + draw_tess_quad(-xsz, -ysz, xsz * 2, ysz * 2, tex_width/8 - 1, tex_height/8 - 1); + glEndList(); +} + static void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - has_depth = false; has_video = false; if(freenect_process_events(kin_ctx) != 0) { fprintf(stderr, "Failed to process events.\n"); @@ -87,6 +148,14 @@ } frame->process(); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + // camera + glRotatef(phi, 1, 0, 0); + glRotatef(theta, 0, 1, 0); + glTranslatef(0, 0, -distance); + glUseProgram(sprog); // draw video frame @@ -146,6 +215,14 @@ case 'w': wireframe = wireframe ? false : true; break; + case 'r': + theta = 0; + phi = 0; + distance = 0; + break; + case 'f': + glutFullScreen(); + break; case 27: exit(0); default: @@ -153,6 +230,42 @@ } } +static void mouse(int button, int state, int x, int y) +{ + bn = button; + prev_x = x; + prev_y = y; +} + +static void motion(int x, int y) +{ + switch(bn) { + case GLUT_LEFT_BUTTON: + theta += x - prev_x; + phi += y - prev_y; + + theta = theta < 0 ? 360 + theta : theta; + theta = theta > 360 ? theta - 360 : theta; + + phi = phi < -90 ? 90 + phi : phi; + phi = phi > 90 ? phi - 90 : phi; + break; + + case GLUT_RIGHT_BUTTON: + distance *= (y - prev_y) * 0.01 + 1; + if(distance < 0.0) { + distance = 0.0; + } + break; + + default: + break; + } + + prev_x = x; + prev_y = y; +} + static void idle() { glutPostRedisplay(); @@ -166,56 +279,3 @@ stop_kinect_frames(kin_dev); stop_kinect(kin_ctx, kin_dev); } - -static bool init() -{ - glClearColor(1, 0, 0, 1); - - frame = new Frame; - if(!(tex = load_texture(filename, &tex_width, &tex_height))) { - fprintf(stderr, "Failed to load texture: %s\n", filename); - return false; - } - - /* shaders setup */ - if(!(sprog = sdr_getprog(vsdr_path, fsdr_path))) { - fprintf(stderr, "Failed to create shader program!\n"); - return false; - } - - glUseProgram(sprog); - int dloc = glGetUniformLocation(sprog, "depth_tex"); - if(dloc != -1) - glUniform1i(dloc, 1); - int tloc = glGetUniformLocation(sprog, "tex"); - if(tloc != -1) - glUniform1i(tloc, 0); - glUseProgram(0); - - /* debugging */ - debugging = glGenLists(1); - glNewList(debugging, GL_COMPILE); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, frame->video_tex); - draw_tess_quad(-1, -1, 1, 2, 1, 1, true); - glBindTexture(GL_TEXTURE_2D, frame->depth_tex); - draw_tess_quad(0, -1, 1, 2, 1, 1, true); - glDisable(GL_TEXTURE_2D); - glEndList(); - - return true; -} - -static void init_tessquad() -{ - if(drawing) - glDeleteLists(drawing, 1); - - drawing = glGenLists(1); - glNewList(drawing, GL_COMPILE); - float fov_rads = FOV / 180.0 * M_PI; - float ysz = QUAD_DIST * tan(fov_rads / 2.0); - float xsz = ysz * aspect; - draw_tess_quad(-xsz, -ysz, xsz * 2, ysz * 2, tex_width/8 - 1, tex_height/8 - 1); - glEndList(); -}