diff --git a/src/java/org/lwjgl/opengl/Display.java b/src/java/org/lwjgl/opengl/Display.java index 79b6cb48..42aa4496 100644 --- a/src/java/org/lwjgl/opengl/Display.java +++ b/src/java/org/lwjgl/opengl/Display.java @@ -1348,4 +1348,27 @@ public final class Display { return height; } + + /** + * @return this method will return the pixel scale factor of the Display window. + * + * This method should be used when running in high DPI mode. In such modes Operating + * Systems will scale the Display window to avoid the window shrinking due to high + * resolutions. The OpenGL frame buffer will however use the higher resolution and + * not be scaled to match the Display window size. + * + * OpenGL methods that require pixel dependent values e.g. glViewport, glTexImage2D, + * glReadPixels, etc can convert the scaled Display and Mouse coordinates to the + * correct high resolution value by multiplying them by the pixel scale factor. + * + * e.g. Display.getWidth() * Display.getPixelScaleFactor() will return the high DPI + * width of the OpenGL frame buffer. Whereas Display.getWidth() will be the same as + * the OpenGL frame buffer in non high DPI mode. + * + * Where high DPI mode is not available this method will just return 1.0f therefore + * not have any effect on values that are multiplied by it. + */ + public static float getPixelScaleFactor() { + return display_impl.getPixelScaleFactor(); + } } diff --git a/src/java/org/lwjgl/opengl/DisplayImplementation.java b/src/java/org/lwjgl/opengl/DisplayImplementation.java index 73c8741c..7f76555f 100644 --- a/src/java/org/lwjgl/opengl/DisplayImplementation.java +++ b/src/java/org/lwjgl/opengl/DisplayImplementation.java @@ -192,4 +192,9 @@ interface DisplayImplementation extends InputImplementation { * @return this method will return the top-left y position of the Display window. */ int getY(); + + /** + * @return this method will return the pixel scale factor of the Display window useful for high resolution modes. + */ + float getPixelScaleFactor(); } diff --git a/src/java/org/lwjgl/opengl/LinuxDisplay.java b/src/java/org/lwjgl/opengl/LinuxDisplay.java index 57014175..d7bc6b1e 100644 --- a/src/java/org/lwjgl/opengl/LinuxDisplay.java +++ b/src/java/org/lwjgl/opengl/LinuxDisplay.java @@ -1459,6 +1459,10 @@ final class LinuxDisplay implements DisplayImplementation { return false; } + public float getPixelScaleFactor() { + return 1f; + } + /** * Helper class for managing Compiz's workarounds. We need this to enable Legacy * Fullscreen Support in Compiz, else we'll have trouble with fullscreen windows diff --git a/src/java/org/lwjgl/opengl/MacOSXDisplay.java b/src/java/org/lwjgl/opengl/MacOSXDisplay.java index 2bcf5a9b..831099b8 100644 --- a/src/java/org/lwjgl/opengl/MacOSXDisplay.java +++ b/src/java/org/lwjgl/opengl/MacOSXDisplay.java @@ -622,5 +622,9 @@ final class MacOSXDisplay implements DisplayImplementation { public boolean wasResized() { return nWasResized(window); } + + public float getPixelScaleFactor() { + return 1f; + } } diff --git a/src/java/org/lwjgl/opengl/WindowsDisplay.java b/src/java/org/lwjgl/opengl/WindowsDisplay.java index 05158cb0..7a2dbeef 100644 --- a/src/java/org/lwjgl/opengl/WindowsDisplay.java +++ b/src/java/org/lwjgl/opengl/WindowsDisplay.java @@ -1191,6 +1191,10 @@ final class WindowsDisplay implements DisplayImplementation { } return false; } + + public float getPixelScaleFactor() { + return 1f; + } private static final class Rect { public int top;