Re: canvas not filling frame
Posted by
farrellf on
Nov 09, 2019; 2:59am
URL: https://forum.jogamp.org/canvas-not-filling-frame-tp4040092p4040138.html
I found a workaround for this problem.
In your GLCanvas's resize() method, do this before the rest of your code:
GL2 gl = drawable.getGL().getGL2(); // change this as needed
double dpiScalingFactor = ((Graphics2D) getGraphics()).getTransform().getScaleX();
width = (int) (width * dpiScalingFactor);
height = (int) (height * dpiScalingFactor);
gl.glViewport(0, 0, width, height);
// then put the rest of your code here...
This fixes the problem for me. Tested with AdoptOpenJDK's Java 13 in Windows 10. And it does not seem to break backwards compatibility with Java 8 either, since dpiScalingFactor would always be 1.0 in that case.
Some notes:
If you use MouseListeners, you also need to scale the mouse location. So make dpiScalingFactor a global, and then do "int mouseX = (int) (mouseEvent.getX() * dpiScalingFactor);" etc. in your event handler. I found no way to get the mouse location in true pixels, so you lose some precision, but at least it works. If anyone knows a better way, please share.
I found that "((Graphics2D) getGraphics()).getTransform().getScaleY()" always returns 0.0, so I just assume square pixels. Do any currently used displays have non-square pixels?
I have not tested my workaround on Linux or macOS.
My workaround is based on this info I found:
https://stackoverflow.com/questions/43057457/jdk-9-high-dpi-disable-for-specific-panel-Farrell