36 #if defined(__APPLE__) 37 #include <GLUT/glut.h> 116 glTexImage2D(GL_TEXTURE_2D, 0, 3, 640, 480, 0, GL_RGB, GL_UNSIGNED_BYTE,
depth_front);
119 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
123 GLfloat x_accel_raw, x_accel,y_accel_raw,y_accel;
128 GLfloat accel_length = sqrt(x_accel_raw * x_accel_raw + y_accel_raw * y_accel_raw);
129 x_accel = x_accel_raw/accel_length;
130 y_accel = y_accel_raw/accel_length;
139 glTranslatef((640.0/2.0),(480.0/2.0) ,0.0);
141 glTranslatef(-(640.0/2.0),-(480.0/2.0) ,0.0);
142 glBegin(GL_TRIANGLE_FAN);
143 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
144 glTexCoord2f(0, 1); glVertex3f(0,0,1.0);
145 glTexCoord2f(1, 1); glVertex3f(640,0,1.0);
146 glTexCoord2f(1, 0); glVertex3f(640,480,1.0);
147 glTexCoord2f(0, 0); glVertex3f(0,480,1.0);
153 glTexImage2D(GL_TEXTURE_2D, 0, 3, 640, 480, 0, GL_RGB, GL_UNSIGNED_BYTE,
rgb_front);
155 glTexImage2D(GL_TEXTURE_2D, 0, 1, 640, 480, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE,
rgb_front+640*4);
158 glTranslatef(640+(640.0/2.0),(480.0/2.0) ,0.0);
160 glTranslatef(-(640+(640.0/2.0)),-(480.0/2.0) ,0.0);
162 glBegin(GL_TRIANGLE_FAN);
163 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
164 glTexCoord2f(0, 1); glVertex3f(640,0,0);
165 glTexCoord2f(1, 1); glVertex3f(1280,0,0);
166 glTexCoord2f(1, 0); glVertex3f(1280,480,0);
167 glTexCoord2f(0, 0); glVertex3f(640,480,0);
178 glutDestroyWindow(
window);
259 glDisable(GL_DEPTH_TEST);
263 glEnable(GL_DEPTH_TEST);
274 glViewport(0,0,Width,Height);
275 glMatrixMode(GL_PROJECTION);
277 glOrtho (0, 1280, 0, 480, -5.0f, 5.0f);
278 glMatrixMode(GL_MODELVIEW);
285 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
289 glDisable(GL_DEPTH_TEST);
291 glDisable(GL_ALPHA_TEST);
292 glEnable(GL_TEXTURE_2D);
293 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
294 glShadeModel(GL_FLAT);
298 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
299 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
303 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
304 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
311 printf(
"GL thread\n");
315 glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_ALPHA | GLUT_DEPTH);
316 glutInitWindowSize(1280, 480);
317 glutInitWindowPosition(0, 0);
319 window = glutCreateWindow(
"LibFreenect");
341 for (i=0; i<640*480; i++) {
343 int lb = pval & 0xff;
417 printf(
"'w' - tilt up, 's' - level, 'x' - tilt down, '0'-'6' - select LED mode \n");
418 printf(
"'f' - change video format, 'm' - mirror video, 'o' - rotate video with accelerometer \n");
419 printf(
"'e' - auto exposure, 'b' - white balance, 'r' - raw color \n");
423 if (accelCount++ >= 2000)
443 printf(
"\nshutting down streams...\n");
451 printf(
"-- done!\n");
455 int main(
int argc,
char **argv)
465 printf(
"Kinect camera test\n");
468 for (i=0; i<2048; i++) {
478 printf(
"freenect_init() failed\n");
486 printf (
"Number of devices found: %d\n", nr_devices);
488 int user_device_number = 0;
490 user_device_number = atoi(argv[1]);
492 if (nr_devices < 1) {
498 printf(
"Could not open device\n");
505 printf(
"pthread_create failed\n");
void freenect_set_video_callback(freenect_device *dev, freenect_video_cb cb)
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)
int main(int argc, char **argv)
freenect_flag_value
Possible values for setting each freenect_flag
int freenect_stop_video(freenect_device *dev)
freenect_video_format current_format
int freenect_num_devices(freenect_context *ctx)
void depth_cb(freenect_device *dev, void *v_depth, uint32_t timestamp)
void ReSizeGLScene(int Width, int Height)
int freenect_start_depth(freenect_device *dev)
pthread_t freenect_thread
int freenect_set_led(freenect_device *dev, freenect_led_options option)
int freenect_set_video_buffer(freenect_device *dev, void *buf)
int freenect_shutdown(freenect_context *ctx)
FREENECTAPI int freenect_set_flag(freenect_device *dev, freenect_flag flag, freenect_flag_value value)
int freenect_set_video_mode(freenect_device *dev, const freenect_frame_mode mode)
int freenect_set_tilt_degs(freenect_device *dev, double angle)
void freenect_set_depth_callback(freenect_device *dev, freenect_depth_cb cb)
void rgb_cb(freenect_device *dev, void *rgb, uint32_t timestamp)
void freenect_set_log_level(freenect_context *ctx, freenect_loglevel level)
int freenect_start_video(freenect_device *dev)
void * freenect_threadfunc(void *arg)
freenect_frame_mode freenect_find_video_mode(freenect_resolution res, freenect_video_format fmt)
pthread_mutex_t gl_backbuf_mutex
freenect_frame_mode freenect_find_depth_mode(freenect_resolution res, freenect_depth_format fmt)
pthread_cond_t gl_frame_cond
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)
Data from the tilt motor and accelerometer.
freenect_video_format requested_format
int freenect_stop_depth(freenect_device *dev)
void * gl_threadfunc(void *arg)
void keyPressed(unsigned char key, int x, int y)
int freenect_process_events(freenect_context *ctx)
void InitGL(int Width, int Height)
int freenect_init(freenect_context **ctx, freenect_usb_context *usb_ctx)