librealsense icon indicating copy to clipboard operation
librealsense copied to clipboard

Displaying Camera Frames in Custom OpenGL Window?

Open HippoEug opened this issue 8 years ago • 7 comments


Required Info
Camera Model D400
Firmware Version 05.09.02.00
Operating System & Version Win 10
Kernel Version (Linux Only)
Platform PC
SDK Version 2.16.1
Language C++
Segment others

Issue Description

Good morning/afternoon/evening,

I am trying to create a custom version of Realsense Viewer with additional function using the D435. Here is a rough sketch up of the output currently using OpenGL and Dear ImGui. image

Here is what I am trying to do: image image

As simple as this! Displaying the streams onto my own OpenGL Window using C++.

Here is my current code:

glfwInit(); GLFWwindow* window = glfwCreateWindow(1280, 720, "IntelRealsenseX", NULL, NULL); glfwMakeContextCurrent(window); ImGui_ImplGlfw_InitForOpenGL(window, true);

Here is the example code from realsense SDK:

window app(1280, 720, "CPP - Align Example"); ImGui_ImplGfw_Init(app, false); rs2::colorizer color_map; texture renderer; ... renderer.render(other_frame, altered_other_frame_rect); // I believe this is the output to OpenGL Window?

Another simpler example from realsense SDK:

window app(1280, 600, "rs-capture"); ... rs2::frame depth = color_map(data.get_depth_frame()); rs2::frame color = data.get_color_frame(); depth_image.render(depth, {0, 0, app.width()/2, app.height() }); color_image.render(color, { app.width()/2, app.width()/2, app.height() });

How do I replicate this but on my own GLFWwindow* window declaration? I am finding it difficult to understand how to render these rs2::frames..

Thank you for helping!

HippoEug avatar Oct 10 '18 09:10 HippoEug

Hi @HippoEug Have you looked at example.hpp implementation? Once you have your GLFW window set up, you need to create OpenGL texture object, bind it and upload pixel values to it on every camera frame using glTexImage2D. Then on every application frame, you want to render 2D quad with this texture (we are using glBegin / glEnd but you can also do this with vertex buffers and other ways)

dorodnic avatar Oct 10 '18 12:10 dorodnic

Hi Dorodnic, I am stuck on a even simpler step before the points you mentioned. My issue is more of a general C++ programming one + OpenGL rather than the Realsense SDK issue. Have never used OpenGL, so am not familiar with it

image Here is what I am trying to do. Create the GLFW window in say a .cpp file on its own, main.cpp in this case. Upon calling it, I want to pass this GLFW window object to another .cpp file for rendering.. is this possible? If it is not a easy solution, I think I am going to put the Realsense Libraries and the OpenGL/GLFW libraries together in a .cpp file and do it from there. (ie making the GLFW window in a .cpp file and then rendering it on the same file without passing anything).

NOTE: in the screenshot you see, texture_s and render_s is a exact copy of texture and render from example.hpp

Thank you so so much for your help :)

HippoEug avatar Oct 11 '18 09:10 HippoEug

With GLFW you can't really access the content of objects. To get width and height of the window, you just call glfwGetWindowSize(window, &_width, &_height); Please take a look at old cpp-capture.cpp. The calls to RealSense API are slightly different, but it puts much more emphasis on inlining all the OpenGL stuff into a single tutorial.

dorodnic avatar Oct 11 '18 10:10 dorodnic

With GLFW you can't really access the content of objects. To get width and height of the window, you just call glfwGetWindowSize(window, &_width, &_height); Please take a look at old cpp-capture.cpp. The calls to RealSense API are slightly different, but it puts much more emphasis on inlining all the OpenGL stuff into a single tutorial.

Hi Dorodnic, the example is pretty helpful. Thank you very much and have a great weekend!

HippoEug avatar Oct 12 '18 08:10 HippoEug

image

Yay! I somehow managed to do it, still need lots of work on it though..

HippoEug avatar Oct 16 '18 07:10 HippoEug

[Realsense Customer Engineering Team Comment] Hi HippoEug,

Do you still need help on this or we can close it?

Thanks!

You can close this, thanks!

HippoEug avatar Oct 23 '18 04:10 HippoEug