Friday, March 7, 2014

OpenGL drawing in ROS rviz

At work we have a bunch of legacy OpenGL code from the pre-ROS era. Fortunately for us, there is a way to reuse it in rviz. Here is a gist showing how to do it:

https://gist.github.com/bricerebsamen/7018215

Basically you setup your display to create a rendering queue and then push OpenGL code in it.

For instance, I had code that would create an OpenGL rendering list. I could use the exact same code to create the list, all I had to do was to let the rviz display use the list.

It's not super easy, mostly because the process is not well documented, but certainly easier than rewriting the whole thing in native OGRE code.The code provided in the gist definitely helps.

Besides, in that particular case, the OpenGL codes is stored in binary format (I guess it was created from some CAD drawing export tool).

2 comments:

  1. Hi Brice, we at i2r want to create a graphics software module that can real-timely display the data from on-board sensors of the vehicle, with the visualization effects just like in the google self-driving car. Can advise us on the beginning? Starting with OpenGL or OGRE like the ros rviz does? Thanks. Zhang Qun from i2r Singapore

    ReplyDelete
  2. Hi Zhang Qun. I suggest you use Ogre as much as possible. Keep this opengl code for when you have legacy opengl code only. It's a bit unstable and has lots of issues that are hard to debug. It sorts of work but not perfectly.

    Now there are 2 ways to use Ogre in rviz. You can use the rviz high level objects, or you can use low level Ogre code. For instance rviz provide shapes that are useful when you want to draw a couple of rectangles. But if you want to draw an occupancy map with 100,000 cells represented as cubes then it will be too slow to draw 100,000 rectangular shapes. In this case you should learn how to code in Ogre and use some lower level Ogre primitives. Ogre can be super fast when coded properly.

    ReplyDelete