jzy3d / jogl

Mirror of https://jogamp.org/cgit/jogl.git/
Other
6 stars 2 forks source link

HiDPI not supported - Win10 + GLCanvas + JDK11 + JOGL2.4 #8

Open jzy3d opened 2 years ago

jzy3d commented 2 years ago

GL viewport do not occupy the whole panel in this configuration. Similar to a known bug with 2.3.2.

Another JOGL user reported a similar problem with Newt and suggested a workaround with a sample code.

doquang commented 2 years ago

@jzy3d - Do you have any workaround solution for AWT? I saw a post about it, https://forum.jogamp.org/canvas-not-filling-frame-td4040092.html#a4040138

jzy3d commented 2 years ago

Hi @doquang , I am currently working on it but at Jzy3D level, not solving the underlying JOGL bug on Win10. The fix I am evaluating is more or less what is discussed by Farelff, with an ability to avoid stretching if HiDPI is actually supported.

I am a bit surprised by the fix suggested by Karl-Heinz, that may mean there is a mess between current and requested pixel ratio, the former being overrided by the maximum pixel ratio. Doing this properly would require to better undestand the whole pixel ratio management. But it's a very interesting direction thanks, for pointing this.

jzy3d commented 2 years ago

Another workaround suggested by @doquang

setLayout(new BorderLayout() {
          @Override
          public void layoutContainer(Container target) {
              synchronized (target.getTreeLock()) {
                  Insets insets = target.getInsets();
                  int top = insets.top;
                  int bottom = target.getHeight() - insets.bottom;
                  int left = insets.left;
                  int right = target.getWidth() - insets.right;

                  Graphics graphics = getGraphics();
                  AffineTransform transform = ((Graphics2D) graphics).getTransform();
                  double scaleX = transform.getScaleX();
                  double scaleY = transform.getScaleY();

                  int width = right - left;
                  int height = bottom - top;
                  width *= scaleX;
                  height *= scaleY;

                  renWin.setBounds(left, top, width, height);
              }
          }
      });