I was trying to draw a histogram with a transparent box on top of it and noticed that whenever I set CanvasPreferGL to true, it messes up my canvas. Here is a reproducer:
void transpar()
{
gStyle->SetCanvasPreferGL(false);
TH2F *h = new TH2F("h", "h;X;Y;Z", 10, 0., 10., 10, 0., 10.);
h->Draw();
TMarker *m = new TMarker(4., 7., 8);
m->Draw();
TBox *b = new TBox(1., 1., 8., 8.);
printf("CanvasPreferGL is set to %s\n", gStyle->GetCanvasPreferGL() ? "true, the red box is expected to be transparent":"false, the red box is expected to be non-transparent");
b->SetFillColorAlpha(kRed, 0.2);
b->Draw();
}
The box is now transparent, which is good, but there is too much empty space above the histogram name (“h”) and the X-axis title is now cut off. Is there a way to make my box transparent and keep everything else where it was before?
Please note I’m using the -n option when running transpar.cxx, so it’s not due to something I have in my style file.
I do not see this effect with the latest ROOT on Mac.
The geometry of the canavs is the same independly of the fact I am using gStyle->SetCanvasPreferGL(true) or gStyle->SetCanvasPreferGL(false);
Just for information that’s what I get on Mac (transparency works even without GL on mac). On the left, it is the canvas with GL, and on the right without.
-bash-4.2$ root transpar.C
------------------------------------------------------------------
| Welcome to ROOT 6.24/08 https://root.cern |
| (c) 1995-2021, The ROOT Team; conception: R. Brun, F. Rademakers |
| Built for linuxx8664gcc on Sep 29 2022, 13:04:57 |
| From tags/v6-24-08@v6-24-08 |
| With c++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44) |
| Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
------------------------------------------------------------------
root [0]
Processing transpar.C...
Fontconfig warning: ignoring UTF-8: not a valid region tag
Error in <TX11GLManager::CreateContext>: glXCreateContext failed
Error in <TRootCanvas::CreateCanvas>: GL context creation failed.
Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
CanvasPreferGL is set to true, the red box is expected to be transparent
root [1]
Do you have the possibility to try on a Linux box without ssh ? (to make sure it is really ssh the problem).
Note also I am not sure which OpenGl is installed on lxplus…
Also are you able to change the top Margin of the canvas and see if it has effects in the GL case or not?