00001
00002
00003
00005
00007
00008
00009 #include <librealsense/rs.hpp>
00010 #include <cstdio>
00011
00012
00013 #include <GLFW/glfw3.h>
00014
00015 int main() try
00016 {
00017
00018 rs::context ctx;
00019 printf("There are %d connected RealSense devices.\n", ctx.get_device_count());
00020 if(ctx.get_device_count() == 0) return EXIT_FAILURE;
00021
00022
00023 rs::device * dev = ctx.get_device(0);
00024 printf("\nUsing device 0, an %s\n", dev->get_name());
00025 printf(" Serial number: %s\n", dev->get_serial());
00026 printf(" Firmware version: %s\n", dev->get_firmware_version());
00027
00028
00029 dev->enable_stream(rs::stream::depth, 640, 480, rs::format::z16, 60);
00030 dev->enable_stream(rs::stream::color, 640, 480, rs::format::rgb8, 60);
00031 dev->enable_stream(rs::stream::infrared, 640, 480, rs::format::y8, 60);
00032 try { dev->enable_stream(rs::stream::infrared2, 640, 480, rs::format::y8, 60); }
00033 catch(...) { printf("Device does not provide infrared2 stream.\n"); }
00034 dev->start();
00035
00036
00037 glfwInit();
00038 GLFWwindow * win = glfwCreateWindow(1280, 960, "librealsense tutorial #2", nullptr, nullptr);
00039 glfwMakeContextCurrent(win);
00040 while(!glfwWindowShouldClose(win))
00041 {
00042
00043 glfwPollEvents();
00044 dev->wait_for_frames();
00045
00046 glClear(GL_COLOR_BUFFER_BIT);
00047 glPixelZoom(1, -1);
00048
00049
00050 glRasterPos2f(-1, 1);
00051 glPixelTransferf(GL_RED_SCALE, 0xFFFF * dev->get_depth_scale() / 2.0f);
00052 glDrawPixels(640, 480, GL_RED, GL_UNSIGNED_SHORT, dev->get_frame_data(rs::stream::depth));
00053 glPixelTransferf(GL_RED_SCALE, 1.0f);
00054
00055
00056 glRasterPos2f(0, 1);
00057 glDrawPixels(640, 480, GL_RGB, GL_UNSIGNED_BYTE, dev->get_frame_data(rs::stream::color));
00058
00059
00060 glRasterPos2f(-1, 0);
00061 glDrawPixels(640, 480, GL_LUMINANCE, GL_UNSIGNED_BYTE, dev->get_frame_data(rs::stream::infrared));
00062
00063
00064 if(dev->is_stream_enabled(rs::stream::infrared2))
00065 {
00066 glRasterPos2f(0, 0);
00067 glDrawPixels(640, 480, GL_LUMINANCE, GL_UNSIGNED_BYTE, dev->get_frame_data(rs::stream::infrared2));
00068 }
00069
00070 glfwSwapBuffers(win);
00071 }
00072
00073 return EXIT_SUCCESS;
00074 }
00075 catch(const rs::error & e)
00076 {
00077
00078 printf("rs::error was thrown when calling %s(%s):\n", e.get_failed_function().c_str(), e.get_failed_args().c_str());
00079 printf(" %s\n", e.what());
00080 return EXIT_FAILURE;
00081 }