32 #if defined(__APPLE__) 33 #include <GLUT/glut.h> 44 pthread_mutex_init(&
m_mutex, NULL);
83 :
Freenect::FreenectDevice(_ctx, _index),
86 m_new_rgb_frame(false), m_new_depth_frame(false)
96 copy(rgb, rgb+getVideoBufferSize(), m_buffer_video.begin());
97 m_new_rgb_frame =
true;
105 copy(depth, depth+getDepthBufferSize()/2, m_buffer_depth.begin());
106 m_new_depth_frame =
true;
109 bool getRGB(std::vector<uint8_t> &buffer)
113 if (!m_new_rgb_frame)
116 buffer.swap(m_buffer_video);
117 m_new_rgb_frame =
false;
126 if (!m_new_depth_frame)
129 buffer.swap(m_buffer_depth);
130 m_new_depth_frame =
false;
157 static std::vector<uint8_t> rgb(640*480*3);
158 static std::vector<uint16_t>
depth(640*480);
163 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
169 if (!
color) glColor3ub(255, 255, 255);
170 for (
int i = 0; i < 480*640; ++i)
173 glColor3ub( rgb[3*i+0],
179 glVertex3f( (i%640 - (640-1)/2.f) * depth[i] / f,
180 (i/640 - (480-1)/2.f) * depth[i] / f,
189 glColor3ub(255, 0, 0);
190 glVertex3f( 0, 0, 0);
191 glVertex3f( 50, 0, 0);
192 glColor3ub(0, 255, 0);
194 glVertex3f(0, 50, 0);
195 glColor3ub(0, 0, 255);
197 glVertex3f(0, 0, 50);
201 glMatrixMode(GL_MODELVIEW);
224 glutDestroyWindow(
window);
234 if (
mx >= 0 &&
my >= 0)
247 if (state == GLUT_DOWN)
251 case GLUT_LEFT_BUTTON:
265 else if (state == GLUT_UP && button == GLUT_LEFT_BUTTON)
275 glViewport(0, 0, width, height);
276 glMatrixMode(GL_PROJECTION);
278 gluPerspective(50.0, (
float)width / height, 900.0, 11000.0);
280 glMatrixMode(GL_MODELVIEW);
292 std::cout <<
"\nAvailable Controls:" << std::endl;
293 std::cout <<
"===================" << std::endl;
294 std::cout <<
"Rotate : Mouse Left Button" << std::endl;
295 std::cout <<
"Zoom : Mouse Wheel" << std::endl;
296 std::cout <<
"Toggle Color : C" << std::endl;
297 std::cout <<
"Quit : Q or Esc\n" << std::endl;
301 int main(
int argc,
char **argv)
307 glutInit(&argc, argv);
309 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
310 glutInitWindowSize(640, 480);
311 glutInitWindowPosition(0, 0);
313 window = glutCreateWindow(
"LibFreenect");
314 glClearColor(0.45f, 0.45f, 0.45f, 0.0f);
316 glEnable(GL_DEPTH_TEST);
317 glEnable(GL_ALPHA_TEST);
318 glAlphaFunc(GL_GREATER, 0.0f);
320 glMatrixMode(GL_PROJECTION);
321 gluPerspective(50.0, 1.0, 900.0, 11000.0);
void resizeGLScene(int width, int height)
void DepthCallback(void *_depth, uint32_t timestamp)
ConcreteDevice & createDevice(int _index)
int main(int argc, char **argv)
std::vector< uint8_t > m_buffer_video
bool getRGB(std::vector< uint8_t > &buffer)
void mouseMoved(int x, int y)
Freenect::Freenect freenect
std::vector< uint16_t > m_buffer_depth
MyFreenectDevice(freenect_context *_ctx, int _index)
bool getDepth(std::vector< uint16_t > &buffer)
freenect_frame_mode freenect_find_video_mode(freenect_resolution res, freenect_video_format fmt)
void VideoCallback(void *_rgb, uint32_t timestamp)
freenect_frame_mode freenect_find_depth_mode(freenect_resolution res, freenect_depth_format fmt)
void mouseButtonPressed(int button, int state, int x, int y)
MyFreenectDevice * device
void keyPressed(unsigned char key, int x, int y)