18 int main(
int argc,
char * argv[])
try 24 if(ctx.
get_device_count() == 0)
throw std::runtime_error(
"No device detected. Is it plugged in?");
37 std::ostringstream ss; ss <<
"CPP Point Cloud Example (" << dev.get_name() <<
")";
53 s->yaw -= (x -
s->lastX);
54 s->yaw = std::max(
s->yaw, -120.0);
55 s->yaw = std::min(
s->yaw, +120.0);
56 s->pitch += (y -
s->lastY);
57 s->pitch = std::max(
s->pitch, -80.0);
58 s->pitch = std::min(
s->pitch, +80.0);
72 if (!
s->dev->is_streaming())
s->dev->start();
76 if (
s->dev->is_streaming())
s->dev->stop();
84 int frames = 0;
float time = 0, fps = 0;
85 auto t0 = std::chrono::high_resolution_clock::now();
89 if(dev.is_streaming()) dev.wait_for_frames();
91 auto t1 = std::chrono::high_resolution_clock::now();
92 time += std::chrono::duration<float>(
t1-
t0).
count();
105 const rs::intrinsics tex_intrin = dev.get_stream_intrinsics(tex_stream);
106 bool identical = depth_intrin == tex_intrin && extrin.
is_identity();
108 glPushAttrib(GL_ALL_ATTRIB_BITS);
110 tex.
upload(dev, tex_stream);
114 glViewport(0, 0, width, height);
115 glClearColor(52.0
f/255, 72.
f/255, 94.0
f/255.0
f, 1);
116 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
118 glMatrixMode(GL_PROJECTION);
120 gluPerspective(60, (
float)width/height, 0.01
f, 20.0
f);
122 glMatrixMode(GL_MODELVIEW);
124 gluLookAt(0,0,0, 0,0,1, 0,-1,0);
126 glTranslatef(0,0,+0.5
f);
127 glRotated(app_state.
pitch, 1, 0, 0);
128 glRotated(app_state.
yaw, 0, 1, 0);
129 glTranslatef(0,0,-0.5
f);
131 glPointSize((
float)width/640);
132 glEnable(GL_DEPTH_TEST);
133 glEnable(GL_TEXTURE_2D);
140 for(
int y=0; y<depth_intrin.
height; ++
y)
142 for(
int x=0; x<depth_intrin.
width; ++
x)
155 glMatrixMode(GL_PROJECTION);
160 glPushAttrib(GL_ALL_ATTRIB_BITS);
162 glOrtho(0, width, height, 0, -1, +1);
164 std::ostringstream ss; ss << dev.get_name() <<
" (" << app_state.
tex_streams[app_state.
index] <<
")";
167 ss.str(
""); ss << fps <<
" FPS";
183 catch(
const std::exception & e)
185 std::cerr << e.what() << std::endl;
float2 project_to_texcoord(const float3 &point) const
void log_to_console(log_severity min_severity)
Provides convenience methods relating to devices.
void enable_stream(stream stream, int width, int height, format format, int framerate, output_buffer_format output_buffer_type=output_buffer_format::continous)
Enables specific stream and requests specific properties.
GLFWAPI void glfwGetWindowSize(GLFWwindow *window, int *width, int *height)
Retrieves the size of the client area of the specified window.
const std::string & get_failed_args() const
int main(int argc, char *argv[])
void glTexCoord(const rs::float2 &tex_coord)
GLint GLint GLsizei GLsizei height
Cross-stream extrinsics: encode the topology describing how the different devices are connected...
GLint GLint GLint GLint GLint GLint y
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
GLFWAPI void * glfwGetWindowUserPointer(GLFWwindow *window)
Returns the user pointer of the specified window.
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
GLint GLint GLsizei GLsizei GLsizei depth
float2 pixel_to_texcoord(const float2 &pixel) const
Exposes librealsense functionality for C++ compilers.
struct GLFWwindow GLFWwindow
Opaque window object.
GLFWAPI int glfwInit(void)
Initializes the GLFW library.
GLFWAPI void glfwSetWindowUserPointer(GLFWwindow *window, void *pointer)
Sets the user pointer of the specified window.
stream
Streams are different types of data provided by RealSense devices.
GLfixed GLfixed GLint GLint GLfixed points
GLuint GLuint GLsizei count
void start(rs::source source=rs::source::video)
Begins streaming on all enabled streams for this device.
GLFWAPI void glfwSwapBuffers(GLFWwindow *window)
Swaps the front and back buffers of the specified window.
GLFWAPI void glfwMakeContextCurrent(GLFWwindow *window)
Makes the context of the specified window current for the calling thread.
int get_text_width(const char *text)
GLFWAPI void glfwSetWindowShouldClose(GLFWwindow *window, int value)
Sets the close flag of the specified window.
void glVertex(const rs::float3 &vertex)
GLFWAPI GLFWwindow * glfwCreateWindow(int width, int height, const char *title, GLFWmonitor *monitor, GLFWwindow *share)
Creates a window and its associated context.
GLint GLint GLsizei width
GLFWAPI void glfwDestroyWindow(GLFWwindow *window)
Destroys the specified window and its context.
GLFWAPI void glfwGetFramebufferSize(GLFWwindow *window, int *width, int *height)
Retrieves the size of the framebuffer of the specified window.
void draw_text(int x, int y, const char *text)
GLFWAPI void glfwTerminate(void)
Terminates the GLFW library.
GLFWAPI void glfwPollEvents(void)
Processes all pending events.
GLuint get_gl_handle() const
device * get_device(int index)
float3 transform(const float3 &point) const
const std::string & get_failed_function() const
GLint GLint GLint GLint GLint x
void upload(const void *data, int width, int height, rs::format format, int stride=0)
std::vector< rs::stream > tex_streams
int get_device_count() const
GLFWAPI int glfwWindowShouldClose(GLFWwindow *window)
Checks the close flag of the specified window.