LWJGLX / lwjgl3-awt

AWT support for LWJGL3
MIT License
115 stars 26 forks source link

Canvas width and height is not reported correctly for OpenGL Viewport #53

Open Pengiie opened 2 years ago

Pengiie commented 2 years ago

On Windows when I create an OpenGL Canvas. If Windows Display Scaling is not 100%, if you set glViewport to the canvas's width and height, it will be incorrect. Screenshot_3

I set the clear color to red to make it easier to see, this is when the scaling is set to 125% and the viewport is the reported canvas width and height. Screenshot_1

httpdigest commented 2 years ago

Thanks for reporting. Can reproduce. According to https://kynosarges.org/GuiDpiScaling.html a fix is to do the following:

java.awt.geom.AffineTransform t = canvas.getGraphicsConfiguration().getDefaultTransform();
float sx = (float) t.getScaleX(), sy = (float) t.getScaleY();
int viewportWidth = (int) (getWidth() * sx);
int viewportHeight = (int) (getHeight() * sy);

The default transform of the graphics configuration of the canvas will provide the scale factor. We could add a corresponding e.g. getFramebufferWidth/Height() to the GLCanvas which does this.

eduramiba commented 2 years ago

This bug happens with the latest snapshot, should it still happen?

Only on windows, in the same machine but linux works fine.

Thanks!! Eduardo

eduramiba commented 2 years ago

Sorry I was still using getWidth instead of getFramebufferWidth, it works perfect, thanks!

hageldave commented 2 years ago

This is not yet deployed to maven, the latest build on maven central is from January 2021. Is it possible to do a deployment with these changes included?

edit: oh, it is deployed as snapshot.