36 #if defined(__APPLE__) 37 #include <GLUT/glut.h> 38 #include <OpenGL/gl.h> 39 #include <OpenGL/glu.h> 50 pthread_mutex_init( &
m_mutex, NULL );
56 pthread_mutex_unlock( &
m_mutex );
83 for(
unsigned int i = 0 ; i < 2048 ; i++) {
85 v = std::pow(v, 3)* 6;
94 std::copy(rgb, rgb+getVideoBufferSize(), m_buffer_video.begin());
95 m_new_rgb_frame =
true;
101 for(
unsigned int i = 0 ; i < 640*480 ; i++) {
102 int pval = m_gamma[depth[i]];
103 int lb = pval & 0xff;
106 m_buffer_depth[3*i+0] = 255;
107 m_buffer_depth[3*i+1] = 255-lb;
108 m_buffer_depth[3*i+2] = 255-lb;
111 m_buffer_depth[3*i+0] = 255;
112 m_buffer_depth[3*i+1] = lb;
113 m_buffer_depth[3*i+2] = 0;
116 m_buffer_depth[3*i+0] = 255-lb;
117 m_buffer_depth[3*i+1] = 255;
118 m_buffer_depth[3*i+2] = 0;
121 m_buffer_depth[3*i+0] = 0;
122 m_buffer_depth[3*i+1] = 255;
123 m_buffer_depth[3*i+2] = lb;
126 m_buffer_depth[3*i+0] = 0;
127 m_buffer_depth[3*i+1] = 255-lb;
128 m_buffer_depth[3*i+2] = 255;
131 m_buffer_depth[3*i+0] = 0;
132 m_buffer_depth[3*i+1] = 0;
133 m_buffer_depth[3*i+2] = 255-lb;
136 m_buffer_depth[3*i+0] = 0;
137 m_buffer_depth[3*i+1] = 0;
138 m_buffer_depth[3*i+2] = 0;
142 m_new_depth_frame =
true;
144 bool getRGB(std::vector<uint8_t> &buffer) {
146 if (!m_new_rgb_frame)
148 buffer.swap(m_buffer_video);
149 m_new_rgb_frame =
false;
155 if (!m_new_depth_frame)
157 buffer.swap(m_buffer_depth);
158 m_new_depth_frame =
false;
164 std::vector<uint8_t> m_buffer_video;
168 bool m_new_rgb_frame;
169 bool m_new_depth_frame;
187 static std::vector<uint8_t>
depth(640*480*4);
188 static std::vector<uint8_t> rgb(640*480*4);
203 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
206 glEnable(GL_TEXTURE_2D);
209 glTexImage2D(GL_TEXTURE_2D, 0, 3, 640, 480, 0, GL_RGB, GL_UNSIGNED_BYTE, &depth[0]);
211 glBegin(GL_TRIANGLE_FAN);
212 glColor4f(255.0f, 255.0f, 255.0f, 255.0f);
213 glTexCoord2f(0, 0); glVertex3f(0,0,0);
214 glTexCoord2f(1, 0); glVertex3f(640,0,0);
215 glTexCoord2f(1, 1); glVertex3f(640,480,0);
216 glTexCoord2f(0, 1); glVertex3f(0,480,0);
221 glTexImage2D(GL_TEXTURE_2D, 0, 3, 640, 480, 0, GL_RGB, GL_UNSIGNED_BYTE, &rgb[0]);
223 glTexImage2D(GL_TEXTURE_2D, 0, 1, 640, 480, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, &rgb[0]);
225 glBegin(GL_TRIANGLE_FAN);
226 glColor4f(255.0f, 255.0f, 255.0f, 255.0f);
227 glTexCoord2f(0, 0); glVertex3f(640,0,0);
228 glTexCoord2f(1, 0); glVertex3f(1280,0,0);
229 glTexCoord2f(1, 1); glVertex3f(1280,480,0);
230 glTexCoord2f(0, 1); glVertex3f(640,480,0);
239 glutDestroyWindow(
window);
279 if (key ==
's' || key ==
'd') {
299 glViewport(0,0,Width,Height);
300 glMatrixMode(GL_PROJECTION);
302 glOrtho (0, 1280, 480, 0, -1.0f, 1.0f);
303 glMatrixMode(GL_MODELVIEW);
308 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
310 glDepthFunc(GL_LESS);
311 glDisable(GL_DEPTH_TEST);
313 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
314 glShadeModel(GL_SMOOTH);
317 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
318 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
321 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
322 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
328 printf(
"GL thread\n");
332 glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
333 glutInitWindowSize(1280, 480);
334 glutInitWindowPosition(0, 0);
336 window = glutCreateWindow(
"LibFreenect");
350 int main(
int argc,
char **argv) {
void DepthCallback(void *_depth, uint32_t timestamp)
Freenect::Freenect freenect
void setTiltDegrees(double _angle)
void keyPressed(unsigned char key, int x, int y)
ConcreteDevice & createDevice(int _index)
void setLed(freenect_led_options _option)
bool getRGB(std::vector< uint8_t > &buffer)
void ReSizeGLScene(int Width, int Height)
std::vector< uint8_t > m_buffer_depth
MyFreenectDevice * device
void * gl_threadfunc(void *arg)
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 setVideoFormat(freenect_video_format requested_format, freenect_resolution requested_resolution=FREENECT_RESOLUTION_MEDIUM)
void VideoCallback(void *_rgb, uint32_t timestamp)
freenect_video_format requested_format(FREENECT_VIDEO_RGB)
FreenectTiltState getState() const
std::vector< uint16_t > m_gamma
bool getDepth(std::vector< uint8_t > &buffer)
freenect_video_format getVideoFormat()
void InitGL(int Width, int Height)
int main(int argc, char **argv)