36 #if defined(__APPLE__) 37 #include <GLUT/glut.h> 78 void chunk_cb(
void *buffer,
void *pkt_data,
int pkt_num,
int pkt_size,
void *ud)
80 if(pkt_num == 73 || pkt_num == 146)
return;
84 raw += (pkt_num-220) * 12;
85 frame += 320 * (pkt_num-2);
86 }
else if(pkt_num > 146){
87 raw += (pkt_num-147) * 12 + 4;
88 frame += 320 * (pkt_num-2);
89 }
else if(pkt_num > 73){
90 raw += (pkt_num-74) * 12 + 8;
91 frame += 320 * (pkt_num-1);
94 frame += 320 * pkt_num;
99 frame[0] = (raw[0]<<3) | (raw[1]>>5);
100 frame[1] = ((raw[2]<<9) | (raw[3]<<1) | (raw[4]>>7) ) & 2047;
101 frame[2] = ((raw[5]<<7) | (raw[6]>>1) ) & 2047;
102 frame[3] = ((raw[8]<<5) | (raw[9]>>3) ) & 2047;
103 frame[4] = (raw[11]<<3) | (raw[12]>>5);
104 frame[5] = ((raw[13]<<9) | (raw[14]<<1) | (raw[15]>>7) ) & 2047;
105 frame[6] = ((raw[16]<<7) | (raw[17]>>1) ) & 2047;
106 frame[7] = ((raw[19]<<5) | (raw[20]>>3) ) & 2047;
135 glTexImage2D(GL_TEXTURE_2D, 0, 3, 320, 240, 0, GL_RGB, GL_UNSIGNED_BYTE,
depth_front);
137 glBegin(GL_TRIANGLE_FAN);
138 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
139 glTexCoord2f(0, 0); glVertex3f(0,0,0);
140 glTexCoord2f(1, 0); glVertex3f(320,0,0);
141 glTexCoord2f(1, 1); glVertex3f(320,240,0);
142 glTexCoord2f(0, 1); glVertex3f(0,240,0);
153 glutDestroyWindow(
window);
201 glViewport(0,0,Width,Height);
202 glMatrixMode(GL_PROJECTION);
204 glOrtho (0, 320, 240, 0, -1.0f, 1.0f);
205 glMatrixMode(GL_MODELVIEW);
211 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
213 glDepthFunc(GL_LESS);
214 glDepthMask(GL_FALSE);
215 glDisable(GL_DEPTH_TEST);
217 glDisable(GL_ALPHA_TEST);
218 glEnable(GL_TEXTURE_2D);
219 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
220 glShadeModel(GL_FLAT);
224 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
225 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
232 printf(
"GL thread\n");
236 glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
237 glutInitWindowSize(320, 240);
238 glutInitWindowPosition(0, 0);
240 window = glutCreateWindow(
"LibFreenect");
262 for (i=0; i<320*240; i++) {
264 int lb = pval & 0xff;
319 printf(
"'w'-tilt up, 's'-level, 'x'-tilt down, '0'-'6'-select LED mode\n");
323 if (accelCount++ >= 2000)
337 printf(
"\nshutting down streams...\n");
344 printf(
"-- done!\n");
348 int main(
int argc,
char **argv)
355 printf(
"Kinect camera test\n");
358 for (i=0; i<2048; i++) {
368 printf(
"freenect_init() failed\n");
376 printf (
"Number of devices found: %d\n", nr_devices);
378 int user_device_number = 0;
380 user_device_number = atoi(argv[1]);
382 if (nr_devices < 1) {
388 printf(
"Could not open device\n");
395 printf(
"pthread_create failed\n");
void * freenect_threadfunc(void *arg)
void freenect_select_subdevices(freenect_context *ctx, freenect_device_flags subdevs)
void freenect_get_mks_accel(freenect_raw_tilt_state *state, double *x, double *y, double *z)
void chunk_cb(void *buffer, void *pkt_data, int pkt_num, int pkt_size, void *ud)
pthread_t freenect_thread
pthread_mutex_t gl_backbuf_mutex
int freenect_num_devices(freenect_context *ctx)
int freenect_start_depth(freenect_device *dev)
int freenect_set_led(freenect_device *dev, freenect_led_options option)
void * gl_threadfunc(void *arg)
int freenect_shutdown(freenect_context *ctx)
pthread_cond_t gl_frame_cond
FREENECTAPI void freenect_set_depth_chunk_callback(freenect_device *dev, freenect_chunk_cb cb)
int freenect_set_tilt_degs(freenect_device *dev, double angle)
void freenect_set_depth_callback(freenect_device *dev, freenect_depth_cb cb)
void freenect_set_log_level(freenect_context *ctx, freenect_loglevel level)
freenect_frame_mode freenect_find_depth_mode(freenect_resolution res, freenect_depth_format fmt)
void ReSizeGLScene(int Width, int Height)
freenect_raw_tilt_state * freenect_get_tilt_state(freenect_device *dev)
int freenect_update_tilt_state(freenect_device *dev)
int freenect_close_device(freenect_device *dev)
int freenect_set_depth_mode(freenect_device *dev, const freenect_frame_mode mode)
int freenect_open_device(freenect_context *ctx, freenect_device **dev, int index)
void depth_cb(freenect_device *dev, void *v_depth, uint32_t timestamp)
Data from the tilt motor and accelerometer.
int freenect_stop_depth(freenect_device *dev)
void InitGL(int Width, int Height)
void keyPressed(unsigned char key, int x, int y)
int main(int argc, char **argv)
int freenect_process_events(freenect_context *ctx)
int freenect_init(freenect_context **ctx, freenect_usb_context *usb_ctx)