Problem viewing GL TH3F in TFile (openGL, glbox.C example)

Dear all,

I’m able to view all GL examples on $ROOTSYS/tutorials/gl, when I run them interactively on root, i.e. with

.x macroname.C

Problems arise when I attempt viewing a written canvas to a root file. For instance, when I modify the macro glbox.C the following way:

a) on the very first line (within curly brackets):
TFile *file = new TFile(“file.root”,“RECREATE”);

b) on the very last line:
c->Write();

Then, I open the file and the canvas: Only the title “glbox …” is displayed. No histograms. Moving the cursor across the canvas, and the following error message is printed to the screen:

Error in TGLHistPainter::DistancetoPrimitive: Attempt to use TGLHistPainter, while the current pad (gPad) does not support gl

root version: 5.32.04

Many thanks in advance for any hints.

Gustavo

[quote=“gkert”]Then, I open the file and the canvas: Only the title “glbox …” is displayed. No histograms. Moving the cursor across the canvas, and the following error message is printed to the screen:

Error in TGLHistPainter::DistancetoPrimitive: Attempt to use TGLHistPainter, while the current pad (gPad) does not support gl

root version: 5.32.04

Many thanks in advance for any hints.

Gustavo[/quote]

Hi.

To enable opengl in a pad you have to call gStyle->SetCanvasPreferGL(kTRUE) before a canvas created.
Obviously, this line of code from any tutorial macro is not saved in your file. Can you try to execute gStyle->SetCanvasPreferGL(kTRUE) before you draw any object from the file? (btw I did not expect “glxxx” option to be saved either).

Hello,

Thank you so much for your quick reply!

Well, in the example script, gStyle->SetCanvasPreferGL(kTRUE) is called prior to creating the canvas. I have attached a copy of the example file (glbox.C) with my two added lines.

I tried the following: (a) executing the script (.x glbox.C), (b) calling gStyle->SetCanvasPreferGL(kTRUE), © opening TBrowser and viewing the canvas. However, the same problem persists.

Am I following your suggestions?
glbox.C (1017 Bytes)

[quote=“gkert”]
Am I following your suggestions?[/quote]

Yes you are. I see the problem now, gStyle’s global setting is somehow ignored when canvas is recreated from the file, I’ll check this.

[quote=“gkert”]I tried the following: (a) executing the script (.x glbox.C), (b) calling gStyle->SetCanvasPreferGL(kTRUE), © opening TBrowser and viewing the canvas. However, the same problem persists.
[/quote]

I have committed a fix into the 5-34-00-patches branch.