cpp-multicam.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 
4 #include <librealsense/rs.hpp>
5 #include "example.hpp"
6 
7 #include <iostream>
8 #include <algorithm>
9 
10 std::vector<texture_buffer> buffers;
11 
12 int main(int argc, char * argv[]) try
13 {
15  //rs::log_to_file(rs::log_severity::debug, "librealsense.log");
16 
18  if(ctx.get_device_count() == 0) throw std::runtime_error("No device detected. Is it plugged in?");
19 
20  // Enumerate all devices
21  std::vector<rs::device *> devices;
22  for(int i=0; i<ctx.get_device_count(); ++i)
23  {
24  devices.push_back(ctx.get_device(i));
25  }
26 
27  // Configure and start our devices
28  for(auto dev : devices)
29  {
30  std::cout << "Starting " << dev->get_name() << "... ";
33  dev->start();
34  std::cout << "done." << std::endl;
35  }
36 
37  // Depth and color
38  buffers.resize(ctx.get_device_count() * 2);
39 
40  // Open a GLFW window
41  glfwInit();
42  std::ostringstream ss; ss << "CPP Multi-Camera Example";
43  GLFWwindow * win = glfwCreateWindow(1280, 960, ss.str().c_str(), 0, 0);
45 
46  int windowWidth, windowHeight;
47  glfwGetWindowSize(win, &windowWidth, &windowHeight);
48 
49  // Does not account for correct aspect ratios
50  auto perTextureWidth = int(windowWidth / devices.size());
51  auto perTextureHeight = 480;
52 
53  while (!glfwWindowShouldClose(win))
54  {
55  // Wait for new images
57 
58  // Draw the images
59  int w,h;
60  glfwGetFramebufferSize(win, &w, &h);
61  glViewport(0, 0, w, h);
62  glClear(GL_COLOR_BUFFER_BIT);
63 
64  glfwGetWindowSize(win, &w, &h);
65  glPushMatrix();
66  glOrtho(0, w, h, 0, -1, +1);
67  glPixelZoom(1, -1);
68  int i=0, x=0;
69  for(auto dev : devices)
70  {
71  dev->poll_for_frames();
72  const auto c = dev->get_stream_intrinsics(rs::stream::color), d = dev->get_stream_intrinsics(rs::stream::depth);
73  buffers[i++].show(*dev, rs::stream::color, x, 0, perTextureWidth, perTextureHeight);
74  buffers[i++].show(*dev, rs::stream::depth, x, perTextureHeight, perTextureWidth, perTextureHeight);
75  x += perTextureWidth;
76  }
77 
78  glPopMatrix();
79  glfwSwapBuffers(win);
80  }
81 
82  glfwDestroyWindow(win);
83  glfwTerminate();
84  return EXIT_SUCCESS;
85 }
86 catch(const rs::error & e)
87 {
88  std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n " << e.what() << std::endl;
89  return EXIT_FAILURE;
90 }
91 catch(const std::exception & e)
92 {
93  std::cerr << e.what() << std::endl;
94  return EXIT_FAILURE;
95 }
void log_to_console(log_severity min_severity)
Definition: rs.hpp:1104
int main(int argc, char *argv[])
GLFWAPI void glfwGetWindowSize(GLFWwindow *window, int *width, int *height)
Retrieves the size of the client area of the specified window.
Definition: window.c:456
const std::string & get_failed_args() const
Definition: rs.hpp:315
virtual void start(rs_source source)=0
rs_error * e
virtual const char * get_name() const =0
const GLuint * buffers
Definition: glext.h:529
Exposes librealsense functionality for C++ compilers.
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:1944
struct GLFWwindow GLFWwindow
Opaque window object.
Definition: glfw3.h:722
GLFWAPI int glfwInit(void)
Initializes the GLFW library.
const GLubyte * c
Definition: glext.h:11542
Context.
Definition: rs.hpp:319
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
GLFWAPI void glfwSwapBuffers(GLFWwindow *window)
Swaps the front and back buffers of the specified window.
Definition: context.c:544
GLFWAPI void glfwMakeContextCurrent(GLFWwindow *window)
Makes the context of the specified window current for the calling thread.
Definition: context.c:531
virtual void enable_stream(rs_stream stream, int width, int height, rs_format format, int fps, rs_output_buffer_format output)=0
auto ctx
GLFWAPI GLFWwindow * glfwCreateWindow(int width, int height, const char *title, GLFWmonitor *monitor, GLFWwindow *share)
Creates a window and its associated context.
Definition: window.c:116
rs_device * dev
GLFWAPI void glfwDestroyWindow(GLFWwindow *window)
Destroys the specified window and its context.
Definition: window.c:369
GLFWAPI void glfwGetFramebufferSize(GLFWwindow *window, int *width, int *height)
Retrieves the size of the framebuffer of the specified window.
Definition: window.c:484
GLFWAPI void glfwTerminate(void)
Terminates the GLFW library.
GLFWAPI void glfwPollEvents(void)
Processes all pending events.
Definition: window.c:682
device * get_device(int index)
Definition: rs.hpp:354
const std::string & get_failed_function() const
Definition: rs.hpp:314
GLint GLint GLint GLint GLint x
Definition: glext.h:114
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:726
std::vector< texture_buffer > buffers
int get_device_count() const
Definition: rs.hpp:343
GLFWAPI int glfwWindowShouldClose(GLFWwindow *window)
Checks the close flag of the specified window.
Definition: window.c:406


librealsense
Author(s): Sergey Dorodnicov , Mark Horn , Reagan Lopez
autogenerated on Fri Mar 13 2020 03:16:17