00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <librealsense/rs.h>
00010 #include <stdlib.h>
00011 #include <stdint.h>
00012 #include <stdio.h>
00013
00014
00015 #include <GLFW/glfw3.h>
00016
00017
00018 rs_error * e = 0;
00019 void check_error()
00020 {
00021 if(e)
00022 {
00023 printf("rs_error was raised when calling %s(%s):\n", rs_get_failed_function(e), rs_get_failed_args(e));
00024 printf(" %s\n", rs_get_error_message(e));
00025 exit(EXIT_FAILURE);
00026 }
00027 }
00028
00029 int main()
00030 {
00031
00032 rs_context * ctx = rs_create_context(RS_API_VERSION, &e);
00033 check_error();
00034 printf("There are %d connected RealSense devices.\n", rs_get_device_count(ctx, &e));
00035 check_error();
00036 if(rs_get_device_count(ctx, &e) == 0) return EXIT_FAILURE;
00037
00038
00039 rs_device * dev = rs_get_device(ctx, 0, &e);
00040 check_error();
00041 printf("\nUsing device 0, an %s\n", rs_get_device_name(dev, &e));
00042 check_error();
00043 printf(" Serial number: %s\n", rs_get_device_serial(dev, &e));
00044 check_error();
00045 printf(" Firmware version: %s\n", rs_get_device_firmware_version(dev, &e));
00046 check_error();
00047
00048
00049 rs_enable_stream(dev, RS_STREAM_DEPTH, 640, 480, RS_FORMAT_Z16, 60, &e);
00050 check_error();
00051 rs_enable_stream(dev, RS_STREAM_COLOR, 640, 480, RS_FORMAT_RGB8, 60, &e);
00052 check_error();
00053 rs_enable_stream(dev, RS_STREAM_INFRARED, 640, 480, RS_FORMAT_Y8, 60, &e);
00054 check_error();
00055 rs_enable_stream(dev, RS_STREAM_INFRARED2, 640, 480, RS_FORMAT_Y8, 60, NULL);
00056 rs_start_device(dev, &e);
00057 check_error();
00058
00059
00060 glfwInit();
00061 GLFWwindow * win = glfwCreateWindow(1280, 960, "librealsense tutorial #2", NULL, NULL);
00062 glfwMakeContextCurrent(win);
00063 while(!glfwWindowShouldClose(win))
00064 {
00065
00066 glfwPollEvents();
00067 rs_wait_for_frames(dev, &e);
00068 check_error();
00069
00070 glClear(GL_COLOR_BUFFER_BIT);
00071 glPixelZoom(1, -1);
00072
00073
00074 glRasterPos2f(-1, 1);
00075 glPixelTransferf(GL_RED_SCALE, 0xFFFF * rs_get_device_depth_scale(dev, &e) / 2.0f);
00076 check_error();
00077 glDrawPixels(640, 480, GL_RED, GL_UNSIGNED_SHORT, rs_get_frame_data(dev, RS_STREAM_DEPTH, &e));
00078 check_error();
00079 glPixelTransferf(GL_RED_SCALE, 1.0f);
00080
00081
00082 glRasterPos2f(0, 1);
00083 glDrawPixels(640, 480, GL_RGB, GL_UNSIGNED_BYTE, rs_get_frame_data(dev, RS_STREAM_COLOR, &e));
00084 check_error();
00085
00086
00087 glRasterPos2f(-1, 0);
00088 glDrawPixels(640, 480, GL_LUMINANCE, GL_UNSIGNED_BYTE, rs_get_frame_data(dev, RS_STREAM_INFRARED, &e));
00089 check_error();
00090
00091
00092 if(rs_is_stream_enabled(dev, RS_STREAM_INFRARED2, NULL))
00093 {
00094 glRasterPos2f(0, 0);
00095 glDrawPixels(640, 480, GL_LUMINANCE, GL_UNSIGNED_BYTE, rs_get_frame_data(dev, RS_STREAM_INFRARED2, &e));
00096 }
00097
00098 glfwSwapBuffers(win);
00099 }
00100
00101 return EXIT_SUCCESS;
00102 }