Class HdpiUtils
- java.lang.Object
-
- com.badlogic.gdx.graphics.glutils.HdpiUtils
-
public class HdpiUtils extends java.lang.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 HdpiUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
glScissor(int x, int y, int width, int height)
CallsGL20.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)
CallsGL20.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
setMode(HdpiMode mode)
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)
Converts an y-coordinate given in logical screen coordinates to backbuffer coordinates.static int
toLogicalX(int backBufferX)
Converts an x-coordinate given in backbuffer coordinates to logical screen coordinates.static int
toLogicalY(int backBufferY)
Converts an y-coordinate given in backbuffer coordinates to logical screen coordinates.
-
-
-
Method Detail
-
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)
CallsGL20.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)
CallsGL20.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)
Converts 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)
Converts an y-coordinate given in logical screen coordinates to backbuffer coordinates.
-
-