Extra vertical space on a canvas when CanvasPreferGL is set to true


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()

        TH2F *h = new TH2F("h", "h;X;Y;Z", 10, 0., 10., 10, 0., 10.);

        TMarker *m = new TMarker(4., 7., 8);

        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);


Now if I run this as

root -l -n transpar.cxx

I get the following:

(no transparency is expected, so it is all good).
But when I change false to true at the third line


and run again

root -l -n transpar.cxx

, I get

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.


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.22/06
Platform: CentOS 7
Compiler: Not Provided

Maybe @couet can take a look

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);

I ran this on lxplus7, can somebody please confirm they see the same on lxplus7?

Do you have a more recent version of ROOT there?
6.22 is quite old compared to the last stable 6.28.

Yes, I have just tried 6.28/00: the issue remains.

I confirm that I see the error with ROOT v6.22.08 on lxplus. @couet can you try via SSH?

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.

You can see small differences regarding the text font (there is not real control on that) but the geometry is ok.

Yes, same on Windows. The problem is with ssh

GL version does not work at all for me over ssh:

-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] 

OK, then @yus can you open a GitHub issue for this?

Yes, will do it in about half an hour.


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?

I ping @tpochep who is the author of this code. I might have some hints.

Done: issue #13016

Unfortunately not.

Yes, as I explained in the GitHub issue, this can be mitigated by adding something like

        if (gStyle->GetCanvasPreferGL())
                gPad->SetBottomMargin(gPad->GetBottomMargin() + 0.1);
                gPad->SetTopMargin(gPad->GetTopMargin() - 0.1);

at the end of my function. The box remains transparent.

Thanks Bertrand and Olivier!


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.