gazebosim / gz-rendering

C++ library designed to provide an abstraction for different rendering engines. It offers unified APIs for creating 3D graphics applications.
https://gazebosim.org
Apache License 2.0
50 stars 48 forks source link

Render to external window #757

Open Levi-Armstrong opened 1 year ago

Levi-Armstrong commented 1 year ago

How to render to external window? I was expecting if I set the winID to the QWidget window id that it would draw the content to this location. This works if I use ogre2 directly so not sure why this does not work here.

  std::map<std::string, std::string> params;
  params["winID"] = std::to_string(winId());
  auto* engine = ignition::rendering::engine("ogre2", params);
iche033 commented 1 year ago

This works if I use ogre2 directly

Maybe we're passing different params to ogre2 when creating the render window?

the params that are passed to ogre2 when creating the render window can be found here: https://github.com/gazebosim/gz-rendering/blob/gz-rendering7/ogre2/src/Ogre2RenderEngine.cc#L1022

you can see that we are setting the parentWindowHandle param to winID here: https://github.com/gazebosim/gz-rendering/blob/gz-rendering7/ogre2/src/Ogre2RenderEngine.cc#L1083

Levi-Armstrong commented 1 year ago

I did a simple demo using ogre2 directly with Qt, but setting the parentWindowHandle did not work either. Though if I set the externalWindowHandle to the winID it works. Do you know what the difference is between these two? I see that for different operating system it set the externalWindowHandle instead of the parrentWindowHandle

iche033 commented 1 year ago

Do you know what the difference is between these two?

The diff based on ogre's doc is that externalWindowHandle embeds ogre in existing window and parentWindowHandle embeds ogre in child of external window. I see that in the ogre wiki page on integrating Qt5, both are set.

One thing to try is modify this line in gz-rendering to create a window of proper size and see if it attaches to the external window that you have. Some additional details: In gazebo, we're currently just creating a 1x1 window for initializing ogre. Then we do a trick in gz-gui that tells Qt window to render the texture generated by the user camera we created in ogre.

Levi-Armstrong commented 1 year ago

One thing to try is modify this line in gz-rendering to create a window of proper size and see if it attaches to the external window that you have. Some additional details: In gazebo, we're currently just creating a 1x1 window for initializing ogre. Then we do a trick in gz-gui that tells Qt window to render the texture generated by the user camera we created in ogre.

This is ultimately what I want to do, but I am using QWidgets and have been unsuccessful in making this work using QOpenglWidget. Do you have or no of any examples where this has been used with QWidgets?

Levi-Armstrong commented 1 year ago

Here is my old post where I have a minimal example I was trying to get working. If I can get things working I would contribute back to this repository as an example similar to the gazebo qml example.

I have it partially working using the drawPixel command but once I add anything to the environment which has transparency it has issues. If the object with transparency is in view of the camera that color takes up the entire screen. If it goes out of view everything is normal. I will create a video and post.

azeey commented 1 month ago

Is this fixed by https://github.com/gazebosim/gz-rendering/pull/992?