Using OpenGL in a compiled program

Dear ROOT enthusiasts

I am very impressed by the OpenGL examples in the tutorials directory and want to include some of it in my application. However, I can’t find the right information to include ‘GL’ drawing options in a compiled program. For the sake of a concrete example, I tried to compile $ROOTSYS/tutorials/glbox.C, with a GUI around it (to be both interactive and compiled). The code is attached. When I compile it with

rootcint -f glboxDict.cxx -c glbox.h glboxLinkDef.h
g++ root-config --cflags --glibs -o glbox glbox.cxx glboxDict.cxx

I can draw 3D histograms with, for instance, the ‘box’ option, but not with the ‘glbox’ option. I have tried linking with -lRGL, -lGed, -lTreePlayer in various orders, to no avail. Do I need more #includes? Do I have to tell the TPad to accept GL drawing options? If yes, why would I have to do that only in compiled code? (It renders the tutorials less useful.)

Thanks for any help you can provide!

Thomas
glboxLinkDef.h (36 Bytes)
glbox.h (275 Bytes)
glbox.cxx (2.2 KB)

In MyMainFrame ctor (glbox.cxx) place the line

gStyle->SetCanvasPreferGL(true) before TRootCanvas creation.

That works - thank you very much!
But I don’t get the same functionality as in the CINT-called tutorial. For instance I cannot zoom into the plot. Is this normal?

Thomas

[quote]That works - thank you very much!
But I don’t get the same functionality as in the CINT-called tutorial. For instance I cannot zoom into the plot. Is this normal?
[/quote]
Yes, this is normal, or “normal” - that’s how TRootEmbeddedCanvas processes input, differently from TCanvas.

Ah, okay. So I am afraid OpenGL is not an option for my application where the user essentially stares at one big TRootEmbeddedCanvas. OpenGL and EmbeddedCanvas really don’t seem to go together very well: in my application, a GLBOX plot keeps reverting to the default scatter plot unless the user is busy rotating it with the mouse. It looks like if I want OpenGL, I’ll have to open up a separate viewer for that. (Unless somebody finds the time to make EmbeddedCanvas fit for OpenGL.)

Many thanks for your help,

Thomas

There are now important developments in the GL viewer. Our dev version in CVS supports GL in embedded canvas.
For more info, you may be interested to look at the presentations by Matevz Tadel at CHEP07

Rene

Thank you for pointing me to CHEP07. Once there, I found that Olivier Couet’s talk also contains a lot of information very relevant to this thread!

Thomas

[quote]Ah, okay. So I am afraid OpenGL is not an option for my application where the user essentially stares at one big TRootEmbeddedCanvas. OpenGL and EmbeddedCanvas really don’t seem to go together very well: in my application, a GLBOX plot keeps reverting to the default scatter plot unless the user is busy rotating it with the mouse. It looks like if I want OpenGL, I’ll have to open up a separate viewer for that. (Unless somebody finds the time to make EmbeddedCanvas fit for OpenGL.)

Many thanks for your help,

Thomas[/quote]

If you want, I can help you to tune your app to make gl able to work.

I think with the Qt-layer on you still can achieve what you need with ease. Qt-layer allows you to combine the ROOT graphics and third party Qt-widget. In your particular case, you can use, for example, QGLViewer. I have attached the fully working short example (There is a short README inside). The example shows the interactive Qt application that combines QGLViewer example:
artis.imag.fr/Members/Gilles.Deb … ation.html
and the ROOT TCanvas with 2D histogram in to represent the particles “speed vs position”. (ACliC can be usee also) (The small resolution image attached. See root.bnl.gov/QtRoot/pictures/HelloGlViewer.gif for better quality.) You can try it against of any not too old ROOT version.

To customize this example for your needs replace the method

void Particle::draw() { glColor3f(age_/(float)ageMax_, age_/(float)ageMax_, 1.0); glVertex3fv(pos_); }with your own OpenGL model. It should be trivial.
See nikhef.nl/acat07/parallel3.php for some details.


HelloGLViewer.tar.gz (3.83 KB)