From 5e7e122b3da4ad96790411e067c2560df23edfbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B9=D0=BB=D0=BE=20=D0=93=D1=80?= =?UTF-8?q?=D0=BE=D1=88=D0=B5=D0=B2=D0=B8=D0=B9?= Date: Sun, 15 Dec 2024 15:56:29 +0100 Subject: [PATCH] Fix window resizing on macOS by considering current screen scale factor --- src/org/lwjgl/opengl/awt/PlatformMacOSXGLCanvas.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/org/lwjgl/opengl/awt/PlatformMacOSXGLCanvas.java b/src/org/lwjgl/opengl/awt/PlatformMacOSXGLCanvas.java index 28bd426..6cd7d25 100644 --- a/src/org/lwjgl/opengl/awt/PlatformMacOSXGLCanvas.java +++ b/src/org/lwjgl/opengl/awt/PlatformMacOSXGLCanvas.java @@ -14,6 +14,7 @@ import javax.swing.*; import java.awt.*; import java.awt.event.HierarchyEvent; +import java.awt.geom.AffineTransform; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.DoubleBuffer; @@ -88,6 +89,7 @@ public class PlatformMacOSXGLCanvas implements PlatformGLCanvas { } public JAWTDrawingSurface ds; + private Canvas canvas; private long view; private int width; private int height; @@ -95,6 +97,7 @@ public class PlatformMacOSXGLCanvas implements PlatformGLCanvas { @Override public long create(Canvas canvas, GLData attribs, GLData effective) throws AWTException { this.ds = JAWT_GetDrawingSurface(canvas, awt.GetDrawingSurface()); + this.canvas = canvas; canvas.addHierarchyListener(e -> { // if the canvas, or a parent component is hidden/shown, we must update the hidden state of the layer if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) > 0) { @@ -356,7 +359,10 @@ public boolean makeCurrent(long context) { int height = dsi.bounds().height(); if (width != this.width || height != this.height) { // [NSOpenGLCotext update] seems bugged. Updating renderer context with CGL works. - CGLSetParameter(context, kCGLCPSurfaceBackingSize, new int[]{width, height}); + AffineTransform transform = canvas.getGraphicsConfiguration().getDefaultTransform(); + int backingWidth = (int) (width * transform.getScaleX()); + int backingHeight = (int) (height * transform.getScaleY()); + CGLSetParameter(context, kCGLCPSurfaceBackingSize, new int[]{backingWidth, backingHeight}); CGLEnable(context, kCGLCESurfaceBackingSize); this.width = width; this.height = height;