Switching TPad from<->to opengl

Dear all,
I have some troubles in using the opengl visualization inside the Pad: I would like to enable users to switch from an opengl-based view to a “normal”-one and viceversa, from within a gui program.

Here is a “minimal” example macro:

TCanvas *c=NULL;
TH2F *h2=NULL;

void draw(int use_ogl)
{
  printf("USE_OGL=%d\n", use_ogl);
  if(use_ogl)
    {
      gStyle->SetCanvasPreferGL(kTRUE);
      h2->Draw("gl surf1z");
    }
  else
    {
      gStyle->SetCanvasPreferGL(kFALSE);
      h2->Draw("surf1z");
    }
  c->Modified();
  c->Update();
}


void test_ogl()
{ 

  gStyle->SetCanvasPreferGL(kTRUE); // try also commenting this out


  c=new TCanvas("c","c");
  h2=new TH2F("h2","h2",10,-3,3,10,-3,3);
  h2->FillRandom("gaus",10000);

  TControlBar* myeditor = new TControlBar("vertical","");
  myeditor->AddButton("Draw without using opengl","draw(0)");
  myeditor->AddButton("Draw using opengl","draw(1)");
  myeditor->Show();
}

As you see this does not work: it seems that the canvas ignores any change of gStyle->SetCanvasPreferGL after its creation.

Is it true? Do you have any suggestion?
Best regards!
Luigi

Hi,

Sorry, but this feature is not yet implemented. The OpenGL/Standard selection is done at the creation time of the canvas. But I agree, this would be nice to have. It’s on our todo list.

Cheers, Bertrand.

Hi Bertrand,
thank you for the reply… before giving up 8) , do you know if playing with HistoPainter(s) can solve the problem?
something like: I manually create two HistoPainters, one opengl-based and one not and then I force the pad in using one or the other?

As an alternative: can I have two TCanvases, one ogl-enabled and the other not?

Regards!
Luigi

The GL in pad in still under development. We know this toggle between the 2 modes should be implemented. Playing with the histpainters will not help. Bertrand made a small macro reproducing your problem we will investigate.

Ok, thanks! :smiley:

Let me know how it goes :wink:

Luigi

[quote]
do you know if playing with HistoPainter(s) can solve the problem?
something like: I manually create two HistoPainters, one opengl-based and one not and then I force the pad in using one or the other?

As an alternative: can I have two TCanvases, one ogl-enabled and the other not?

Regards!
Luigi[/quote]

The problem is that hist-painter is in fact a part of hist after your call Draw (Paint) -
not directly, but via pointer and it’s created one time. So, it’s clear, that if you mix gl/non-gl canvases (and hist options) sooner or later you have a confclict
(for example, you have a gl-painter and canvas, which does not support opengl, or non-gl painter, and canvas, which supports opengl).