APIdia Launch Partner
Top Description Fields Constructors Methods
com.badlogic.gdx.graphics.glutils

public Class HdpiUtils

extends Object
Class Inheritance
Imports
com.badlogic.gdx.Gdx, com.badlogic.gdx.graphics.GL20

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.
Author
badlogic

Field Summary

Modifier and TypeField and Description
private static HdpiMode

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
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.

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.

public static void
setMode(HdpiMode
set to HdpiMode.Pixels to ignore HDPI conversion for glViewport and glScissor functions
mode
)

Allows applications to override HDPI coordinate conversion for glViewport and glScissor calls.

public static int
toBackBufferX(int logicalX)

Converts an x-coordinate given in logical screen coordinates to backbuffer coordinates.

public static int
toBackBufferY(int logicalY)

Converts an y-coordinate given in logical screen coordinates to backbuffer coordinates.

public static int
toLogicalX(int backBufferX)

Converts an x-coordinate given in backbuffer coordinates to logical screen coordinates.

public static int
toLogicalY(int backBufferY)

Converts an y-coordinate given in backbuffer coordinates to logical screen coordinates.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

modeback to summary
private static HdpiMode mode

Constructor Detail

HdpiUtilsback to summary
public HdpiUtils()

Method Detail

glScissorback to summary
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.

glViewportback to summary
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.

setModeback to summary
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:HdpiMode

set to HdpiMode.Pixels to ignore HDPI conversion for glViewport and glScissor functions

toBackBufferXback to summary
public static int toBackBufferX(int logicalX)

Converts an x-coordinate given in logical screen coordinates to backbuffer coordinates.

toBackBufferYback to summary
public static int toBackBufferY(int logicalY)

Converts an y-coordinate given in logical screen coordinates to backbuffer coordinates.

toLogicalXback to summary
public static int toLogicalX(int backBufferX)

Converts an x-coordinate given in backbuffer coordinates to logical screen coordinates.

toLogicalYback to summary
public static int toLogicalY(int backBufferY)

Converts an y-coordinate given in backbuffer coordinates to logical screen coordinates.