Class HdpiUtils

java.lang.Object
arc.graphics.gl.HdpiUtils

public class HdpiUtils extends Object
To deal with HDPI monitors properly, use the glViewport and glScissor functions of this class instead of directly calling OpenGL yourself. The logical coordinate system provided by the operating system may not have the same resolution as the actual drawing surface to which OpenGL draws, also known as the backbuffer. This class will ensure, that you pass the correct values to OpenGL for any function that expects backbuffer coordinates instead of logical coordinates.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    glScissor(int x, int y, int width, int height)
    Calls GL20.glScissor(int, int, int, int), expecting the coordinates and sizes given in logical coordinates and automatically converts them to backbuffer coordinates, which may be bigger on HDPI screens.
    static void
    glViewport(int x, int y, int width, int height)
    Calls GL20.glViewport(int, int, int, int), expecting the coordinates and sizes given in logical coordinates and automatically converts them to backbuffer coordinates, which may be bigger on HDPI screens.
    static void
    Allows applications to override HDPI coordinate conversion for glViewport and glScissor calls.
    static int
    toBackBufferX(int logicalX)
    Converts an x-coordinate given in logical screen coordinates to backbuffer coordinates.
    static int
    toBackBufferY(int logicalY)
    Convers an y-coordinate given in backbuffer coordinates to logical screen coordinates
    static int
    toLogicalX(int backBufferX)
    Converts an x-coordinate given in backbuffer coordinates to logical screen coordinates.
    static int
    toLogicalY(int backBufferY)
    Convers an y-coordinate given in backbuffer coordinates to logical screen coordinates

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HdpiUtils

      public HdpiUtils()
  • Method Details

    • setMode

      public static void setMode(HdpiMode mode)
      Allows applications to override HDPI coordinate conversion for glViewport and glScissor calls.

      This function can be used to ignore the default behavior, for example when rendering a UI stage to an off-screen framebuffer:

       HdpiUtils.setMode(HdpiMode.Pixels);
       fb.begin();
       stage.draw();
       fb.end();
       HdpiUtils.setMode(HdpiMode.Logical);
       
      Parameters:
      mode - set to HdpiMode.Pixels to ignore HDPI conversion for glViewport and glScissor functions
    • glScissor

      public static void glScissor(int x, int y, int width, int height)
      Calls GL20.glScissor(int, int, int, int), expecting the coordinates and sizes given in logical coordinates and automatically converts them to backbuffer coordinates, which may be bigger on HDPI screens.
    • glViewport

      public static void glViewport(int x, int y, int width, int height)
      Calls GL20.glViewport(int, int, int, int), expecting the coordinates and sizes given in logical coordinates and automatically converts them to backbuffer coordinates, which may be bigger on HDPI screens.
    • toLogicalX

      public static int toLogicalX(int backBufferX)
      Converts an x-coordinate given in backbuffer coordinates to logical screen coordinates.
    • toLogicalY

      public static int toLogicalY(int backBufferY)
      Convers an y-coordinate given in backbuffer coordinates to logical screen coordinates
    • toBackBufferX

      public static int toBackBufferX(int logicalX)
      Converts an x-coordinate given in logical screen coordinates to backbuffer coordinates.
    • toBackBufferY

      public static int toBackBufferY(int logicalY)
      Convers an y-coordinate given in backbuffer coordinates to logical screen coordinates