APIdia Launch Partner
Top Description Inners Methods
com.badlogic.gdx

public Interface Graphics

Known Direct Implementers
com.badlogic.gdx.AbstractGraphics
Imports
com.badlogic.gdx.graphics.Cursor, .Cursor.SystemCursor, .GL20, .GL30, .GL31, .GL32, .Mesh, .Pixmap, com.badlogic.gdx.graphics.g2d.Batch, .BitmapFont, com.badlogic.gdx.graphics.glutils.FrameBuffer, .GLVersion, .IndexBufferObject, .ShaderProgram, .VertexArray, .VertexBufferObject

This interface encapsulates communication with the graphics processor. Depending on the available hardware and the current Application configuration, access to GL20 and GL30 are provided here.

If supported by the backend, this interface lets you query the available display modes (graphics resolution and color depth) and change it.

This interface can be used to switch between continuous and non-continuous rendering (see setContinuousRendering(boolean)), and to explicitly requestRendering().

There are many more utility classes that are not directly generated by the Graphics interfaces. See VertexArray , VertexBufferObject, IndexBufferObject, Mesh, ShaderProgram and FrameBuffer, BitmapFont, Batch and so on. All these classes are managed, meaning they don't need to be reloaded on a context loss. Explore the com.badlogic.gdx.graphics package for more classes that might come in handy.

Author
mzechner

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Graphics.BufferFormat

Class describing the bits per pixel, depth buffer precision, stencil precision and number of MSAA samples.

public static class
Graphics.DisplayMode

Describe a fullscreen display mode

public static enum
Graphics.GraphicsType

Enumeration describing different types of Graphics implementations.

public static class
Graphics.Monitor

Describes a monitor

Method Summary

Modifier and TypeMethod and Description
public int
getBackBufferHeight()

Returns: the height of the framebuffer in physical pixels

public float
getBackBufferScale()

Returns: amount of pixels per logical pixel (point)

public int
getBackBufferWidth()

Returns: the width of the framebuffer in physical pixels

public Graphics.BufferFormat
getBufferFormat()

Returns: the format of the color, depth and stencil buffer in a BufferFormat instance

public float
getDeltaTime()

Returns: the time span between the current frame and the last frame in seconds.

public float

Returns:

the Density Independent Pixel factor of the display.
getDensity
()

This is a scaling factor for the Density Independent Pixel unit, following the same conventions as android.util.DisplayMetrics#density, where one DIP is one pixel on an approximately 160 dpi screen.

public Graphics.DisplayMode
getDisplayMode()

Returns: the current DisplayMode of the monitor the window is on.

public Graphics.DisplayMode
getDisplayMode(Graphics.Monitor monitor)

Returns: the current DisplayMode of the given Monitor

public Graphics.DisplayMode[]
getDisplayModes()

Returns: the supported fullscreen DisplayMode(s) of the monitor the window is on

public Graphics.DisplayMode[]
getDisplayModes(Graphics.Monitor monitor)

Returns: the supported fullscreen DisplayModes of the given Monitor

public long

Returns:

the id of the current frame
getFrameId
()

Returns the id of the current frame.

public int
getFramesPerSecond()

Returns: the average number of frames per second

public GL20
getGL20()

Returns: the GL20 instance

public GL30
getGL30()

Returns: the GL30 instance or null if not supported

public GL31
getGL31()

Returns: the GL31 instance or null if not supported

public GL32
getGL32()

Returns: the GL32 instance or null if not supported

public GLVersion
getGLVersion()

Returns: the GLVersion of this Graphics instance

public int
getHeight()

Returns: the height of the client area in logical pixels

public Graphics.Monitor
getMonitor()

Returns: the monitor the application's window is located on

public Graphics.Monitor[]
getMonitors()

Returns: the currently connected Monitors

public float
getPpcX()

Returns: the pixels per centimeter on the x-axis

public float
getPpcY()

Returns: the pixels per centimeter on the y-axis.

public float
getPpiX()

Returns: the pixels per inch on the x-axis

public float
getPpiY()

Returns: the pixels per inch on the y-axis

public Graphics.Monitor
getPrimaryMonitor()

Returns: the primary monitor

public float
getRawDeltaTime()
Deprecated use getDeltaTime() instead.

Returns: the time span between the current frame and the last frame in seconds, without smoothing

public int
getSafeInsetBottom()

Returns: the inset from the bottom which avoids display cutouts or floating gesture bars, in logical pixels

public int
getSafeInsetLeft()

Returns: the inset from the left which avoids display cutouts in logical pixels

public int
getSafeInsetRight()

Returns: the inset from the right which avoids display cutouts in logical pixels

public int
getSafeInsetTop()

Returns: the inset from the top which avoids display cutouts in logical pixels

public Graphics.GraphicsType
getType()

Returns: the GraphicsType of this Graphics instance

public int
getWidth()

Returns: the width of the client area in logical pixels.

public boolean
isContinuousRendering()

Returns: whether rendering is continuous.

public boolean
isFullscreen()

Whether the app is fullscreen or not

public boolean

Returns:

whether OpenGL ES 3.0 is available
isGL30Available
()

Returns whether OpenGL ES 3.0 is available.

public boolean

Returns:

whether OpenGL ES 3.1 is available
isGL31Available
()

Returns whether OpenGL ES 3.1 is available.

public boolean

Returns:

whether OpenGL ES 3.2 is available
isGL32Available
()

Returns whether OpenGL ES 3.2 is available.

public Cursor

Returns:

a cursor object that can be used by calling setCursor(Cursor) or null if not supported
newCursor
(Pixmap
the mouse cursor image as a com.badlogic.gdx.graphics.Pixmap
pixmap
,
int
the x location of the hotspot pixel within the cursor image (origin top-left corner)
xHotspot
,
int
the y location of the hotspot pixel within the cursor image (origin top-left corner)
yHotspot
)

Create a new cursor represented by the com.badlogic.gdx.graphics.Pixmap.

public void
requestRendering()

Requests a new frame to be rendered if the rendering mode is non-continuous.

public void
setContinuousRendering(boolean
whether the rendering should be continuous or not.
isContinuous
)

Sets whether to render continuously.

public void
setCursor(Cursor
the mouse cursor as a com.badlogic.gdx.graphics.Cursor
cursor
)

Only viable on the lwjgl-backend and on the gwt-backend.

public void
setForegroundFPS(int
the targeted fps; default differs by platform
fps
)

Sets the target framerate for the application when using continuous rendering.

public boolean

Returns:

whether the operation succeeded.
setFullscreenMode
(Graphics.DisplayMode
the display mode.
displayMode
)

Sets the window to full-screen mode.

public void
setGL20(GL20 gl20)

Set the GL20 instance

public void
setGL30(GL30 gl30)

Set the GL30 instance

public void
setGL31(GL31 gl31)

Set the GL31 instance

public void
setGL32(GL32 gl32)

Set the GL32 instance

public void
setResizable(boolean resizable)

Sets whether or not the window should be resizable.

public void
setSystemCursor(Cursor.SystemCursor systemCursor)

Sets one of the predefined SystemCursors

public void
setTitle(String
the title.
title
)

Sets the title of the window.

public void
setUndecorated(boolean
true if the window border or status bar should be hidden. false otherwise.
undecorated
)

Sets the window decoration as enabled or disabled.

public void
setVSync(boolean
vsync enabled or not.
vsync
)

Enable/Disable vsynching.

public boolean

Returns:

whether the operation succeeded
setWindowedMode
(int
the width in pixels
width
,
int
the height in pixels
height
)

Sets the window to windowed mode.

public boolean

Returns:

whether display mode changes are supported or not.
supportsDisplayModeChange
()

Whether the given backend supports a display mode change via calling Graphics#setFullscreenMode(DisplayMode)

public boolean
supportsExtension(String
the extension name
extension
)

Returns: whether the extension is supported

Method Detail

getBackBufferHeightback to summary
public int getBackBufferHeight()
Returns:int

the height of the framebuffer in physical pixels

getBackBufferScaleback to summary
public float getBackBufferScale()
Returns:float

amount of pixels per logical pixel (point)

getBackBufferWidthback to summary
public int getBackBufferWidth()
Returns:int

the width of the framebuffer in physical pixels

getBufferFormatback to summary
public Graphics.BufferFormat getBufferFormat()
Returns:Graphics.BufferFormat

the format of the color, depth and stencil buffer in a BufferFormat instance

getDeltaTimeback to summary
public float getDeltaTime()
Returns:float

the time span between the current frame and the last frame in seconds.

getDensityback to summary
public float getDensity()

This is a scaling factor for the Density Independent Pixel unit, following the same conventions as android.util.DisplayMetrics#density, where one DIP is one pixel on an approximately 160 dpi screen. Thus on a 160dpi screen this density value will be 1; on a 120 dpi screen it would be .75; etc. If the density could not be determined, this returns a default value of 1. Depending on the underlying platform implementation this might be a relatively expensive operation. Therefore it should not be called continously on each frame.

Returns:float

the Density Independent Pixel factor of the display.

getDisplayModeback to summary
public Graphics.DisplayMode getDisplayMode()
Returns:Graphics.DisplayMode

the current DisplayMode of the monitor the window is on.

getDisplayModeback to summary
public Graphics.DisplayMode getDisplayMode(Graphics.Monitor monitor)
Returns:Graphics.DisplayMode

the current DisplayMode of the given Monitor

getDisplayModesback to summary
public Graphics.DisplayMode[] getDisplayModes()
Returns:Graphics.DisplayMode[]

the supported fullscreen DisplayMode(s) of the monitor the window is on

getDisplayModesback to summary
public Graphics.DisplayMode[] getDisplayModes(Graphics.Monitor monitor)
Returns:Graphics.DisplayMode[]

the supported fullscreen DisplayModes of the given Monitor

getFrameIdback to summary
public long getFrameId()

Returns the id of the current frame. The general contract of this method is that the id is incremented only when the application is in the running state right before calling the ApplicationListener#render() method. Also, the id of the first frame is 0; the id of subsequent frames is guaranteed to take increasing values for 263-1 rendering cycles.

Returns:long

the id of the current frame

getFramesPerSecondback to summary
public int getFramesPerSecond()
Returns:int

the average number of frames per second

getGL20back to summary
public GL20 getGL20()
Returns:GL20

the GL20 instance

getGL30back to summary
public GL30 getGL30()
Returns:GL30

the GL30 instance or null if not supported

getGL31back to summary
public GL31 getGL31()
Returns:GL31

the GL31 instance or null if not supported

getGL32back to summary
public GL32 getGL32()
Returns:GL32

the GL32 instance or null if not supported

getGLVersionback to summary
public GLVersion getGLVersion()
Returns:GLVersion

the GLVersion of this Graphics instance

getHeightback to summary
public int getHeight()
Returns:int

the height of the client area in logical pixels

getMonitorback to summary
public Graphics.Monitor getMonitor()
Returns:Graphics.Monitor

the monitor the application's window is located on

getMonitorsback to summary
public Graphics.Monitor[] getMonitors()
Returns:Graphics.Monitor[]

the currently connected Monitors

getPpcXback to summary
public float getPpcX()
Returns:float

the pixels per centimeter on the x-axis

getPpcYback to summary
public float getPpcY()
Returns:float

the pixels per centimeter on the y-axis.

getPpiXback to summary
public float getPpiX()
Returns:float

the pixels per inch on the x-axis

getPpiYback to summary
public float getPpiY()
Returns:float

the pixels per inch on the y-axis

getPrimaryMonitorback to summary
public Graphics.Monitor getPrimaryMonitor()
Returns:Graphics.Monitor

the primary monitor

getRawDeltaTimeback to summary
public float getRawDeltaTime()

Deprecated

use getDeltaTime() instead.

Returns:float

the time span between the current frame and the last frame in seconds, without smoothing

Annotations
@Deprecated
getSafeInsetBottomback to summary
public int getSafeInsetBottom()
Returns:int

the inset from the bottom which avoids display cutouts or floating gesture bars, in logical pixels

getSafeInsetLeftback to summary
public int getSafeInsetLeft()
Returns:int

the inset from the left which avoids display cutouts in logical pixels

getSafeInsetRightback to summary
public int getSafeInsetRight()
Returns:int

the inset from the right which avoids display cutouts in logical pixels

getSafeInsetTopback to summary
public int getSafeInsetTop()
Returns:int

the inset from the top which avoids display cutouts in logical pixels

getTypeback to summary
public Graphics.GraphicsType getType()
Returns:Graphics.GraphicsType

the GraphicsType of this Graphics instance

getWidthback to summary
public int getWidth()
Returns:int

the width of the client area in logical pixels.

isContinuousRenderingback to summary
public boolean isContinuousRendering()
Returns:boolean

whether rendering is continuous.

isFullscreenback to summary
public boolean isFullscreen()

Whether the app is fullscreen or not

isGL30Availableback to summary
public boolean isGL30Available()

Returns whether OpenGL ES 3.0 is available. If it is you can get an instance of GL30 via getGL30() to access OpenGL ES 3.0 functionality. Note that this functionality will only be available if you instructed the Application instance to use OpenGL ES 3.0!

Returns:boolean

whether OpenGL ES 3.0 is available

isGL31Availableback to summary
public boolean isGL31Available()

Returns whether OpenGL ES 3.1 is available. If it is you can get an instance of GL31 via getGL31() to access OpenGL ES 3.1 functionality. Note that this functionality will only be available if you instructed the Application instance to use OpenGL ES 3.1!

Returns:boolean

whether OpenGL ES 3.1 is available

isGL32Availableback to summary
public boolean isGL32Available()

Returns whether OpenGL ES 3.2 is available. If it is you can get an instance of GL32 via getGL32() to access OpenGL ES 3.2 functionality. Note that this functionality will only be available if you instructed the Application instance to use OpenGL ES 3.2!

Returns:boolean

whether OpenGL ES 3.2 is available

newCursorback to summary
public Cursor newCursor(Pixmap pixmap, int xHotspot, int yHotspot)

Create a new cursor represented by the com.badlogic.gdx.graphics.Pixmap. The Pixmap must be in RGBA8888 format, width & height must be powers-of-two greater than zero (not necessarily equal) and of a certain minimum size (32x32 is a safe bet), and alpha transparency must be single-bit (i.e., 0x00 or 0xFF only). This function returns a Cursor object that can be set as the system cursor by calling setCursor(Cursor) .

Parameters
pixmap:Pixmap

the mouse cursor image as a com.badlogic.gdx.graphics.Pixmap

xHotspot:int

the x location of the hotspot pixel within the cursor image (origin top-left corner)

yHotspot:int

the y location of the hotspot pixel within the cursor image (origin top-left corner)

Returns:Cursor

a cursor object that can be used by calling setCursor(Cursor) or null if not supported

requestRenderingback to summary
public void requestRendering()

Requests a new frame to be rendered if the rendering mode is non-continuous. This method can be called from any thread.

setContinuousRenderingback to summary
public void setContinuousRendering(boolean isContinuous)

Sets whether to render continuously. In case rendering is performed non-continuously, the following events will trigger a redraw:

  • A call to requestRendering()
  • Input events from the touch screen/mouse or keyboard
  • A Runnable is posted to the rendering thread via Application#postRunnable(Runnable). In the case of a multi-window app, all windows will request rendering if a runnable is posted to the application. To avoid this, post a runnable to the window instead.
Life-cycle events will also be reported as usual, see ApplicationListener. This method can be called from any thread.
Parameters
isContinuous:boolean

whether the rendering should be continuous or not.

setCursorback to summary
public void setCursor(Cursor cursor)

Only viable on the lwjgl-backend and on the gwt-backend. Browsers that support cursor:url() and support the png format (the pixmap is converted to a data-url of type image/png) should also support custom cursors. Will set the mouse cursor image to the image represented by the com.badlogic.gdx.graphics.Cursor. It is recommended to call this function in the main render thread, and maximum one time per frame.

Parameters
cursor:Cursor

the mouse cursor as a com.badlogic.gdx.graphics.Cursor

setForegroundFPSback to summary
public void setForegroundFPS(int fps)

Sets the target framerate for the application when using continuous rendering. Might not work on all platforms. Is not generally advised to be used on mobile platforms.

Parameters
fps:int

the targeted fps; default differs by platform

setFullscreenModeback to summary
public boolean setFullscreenMode(Graphics.DisplayMode displayMode)

Sets the window to full-screen mode.

Parameters
displayMode:Graphics.DisplayMode

the display mode.

Returns:boolean

whether the operation succeeded.

setGL20back to summary
public void setGL20(GL20 gl20)

Set the GL20 instance

setGL30back to summary
public void setGL30(GL30 gl30)

Set the GL30 instance

setGL31back to summary
public void setGL31(GL31 gl31)

Set the GL31 instance

setGL32back to summary
public void setGL32(GL32 gl32)

Set the GL32 instance

setResizableback to summary
public void setResizable(boolean resizable)

Sets whether or not the window should be resizable. Ignored on Android. Note that immediate behavior of this method may vary depending on the implementation. It may be necessary for the window to be recreated in order for the changes to take effect. Consult the documentation for the backend in use for more information. Supported on all GDX desktop backends.

setSystemCursorback to summary
public void setSystemCursor(Cursor.SystemCursor systemCursor)

Sets one of the predefined SystemCursors

setTitleback to summary
public void setTitle(String title)

Sets the title of the window. Ignored on Android.

Parameters
title:String

the title.

setUndecoratedback to summary
public void setUndecorated(boolean undecorated)

Sets the window decoration as enabled or disabled. On Android, this will enable/disable the menu bar. Note that immediate behavior of this method may vary depending on the implementation. It may be necessary for the window to be recreated in order for the changes to take effect. Consult the documentation for the backend in use for more information. Supported on all GDX desktop backends and on Android (to disable the menu bar).

Parameters
undecorated:boolean

true if the window border or status bar should be hidden. false otherwise.

setVSyncback to summary
public void setVSync(boolean vsync)

Enable/Disable vsynching. This is a best-effort attempt which might not work on all platforms.

Parameters
vsync:boolean

vsync enabled or not.

setWindowedModeback to summary
public boolean setWindowedMode(int width, int height)

Sets the window to windowed mode.

Parameters
width:int

the width in pixels

height:int

the height in pixels

Returns:boolean

whether the operation succeeded

supportsDisplayModeChangeback to summary
public boolean supportsDisplayModeChange()

Whether the given backend supports a display mode change via calling Graphics#setFullscreenMode(DisplayMode)

Returns:boolean

whether display mode changes are supported or not.

supportsExtensionback to summary
public boolean supportsExtension(String extension)
Parameters
extension:String

the extension name

Returns:boolean

whether the extension is supported

com.badlogic.gdx back to summary

public Class Graphics.BufferFormat

extends Object
Class Inheritance

Class describing the bits per pixel, depth buffer precision, stencil precision and number of MSAA samples.

Field Summary

Modifier and TypeField and Description
public final int
a

public final int
b

public final boolean
coverageSampling

whether coverage sampling anti-aliasing is used.

public final int
public final int
g

public final int
r

public final int
samples

number of samples for multi-sample anti-aliasing (MSAA)

public final int

Constructor Summary

AccessConstructor and Description
public
BufferFormat(int r, int g, int b, int a, int depth, int stencil, int samples, boolean coverageSampling)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

aback to summary
public final int a
bback to summary
public final int b
coverageSamplingback to summary
public final boolean coverageSampling

whether coverage sampling anti-aliasing is used. in that case you have to clear the coverage buffer as well!

depthback to summary
public final int depth
gback to summary
public final int g
rback to summary
public final int r
samplesback to summary
public final int samples

number of samples for multi-sample anti-aliasing (MSAA)

stencilback to summary
public final int stencil

Constructor Detail

BufferFormatback to summary
public BufferFormat(int r, int g, int b, int a, int depth, int stencil, int samples, boolean coverageSampling)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

com.badlogic.gdx back to summary

public Class Graphics.DisplayMode

extends Object
Class Inheritance

Describe a fullscreen display mode
Author
mzechner

Field Summary

Modifier and TypeField and Description
public final int
bitsPerPixel

the number of bits per pixel, may exclude alpha

public final int
height

the height in physical pixels

public final int
refreshRate

the refresh rate in Hertz

public final int
width

the width in physical pixels

Constructor Summary

AccessConstructor and Description
protected
DisplayMode(int width, int height, int refreshRate, int bitsPerPixel)

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

bitsPerPixelback to summary
public final int bitsPerPixel

the number of bits per pixel, may exclude alpha

heightback to summary
public final int height

the height in physical pixels

refreshRateback to summary
public final int refreshRate

the refresh rate in Hertz

widthback to summary
public final int width

the width in physical pixels

Constructor Detail

DisplayModeback to summary
protected DisplayMode(int width, int height, int refreshRate, int bitsPerPixel)

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

com.badlogic.gdx back to summary

public final Enum Graphics.GraphicsType

extends Enum<Graphics.GraphicsType>
Class Inheritance

Enumeration describing different types of Graphics implementations.
Author
mzechner

Field Summary

Modifier and TypeField and Description
public static final Graphics.GraphicsType
public static final Graphics.GraphicsType
public static final Graphics.GraphicsType
public static final Graphics.GraphicsType
public static final Graphics.GraphicsType
public static final Graphics.GraphicsType
public static final Graphics.GraphicsType

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Graphics.GraphicsType
public static Graphics.GraphicsType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

AndroidGLback to summary
public static final Graphics.GraphicsType AndroidGL
iOSGLback to summary
public static final Graphics.GraphicsType iOSGL
JGLFWback to summary
public static final Graphics.GraphicsType JGLFW
LWJGLback to summary
public static final Graphics.GraphicsType LWJGL
LWJGL3back to summary
public static final Graphics.GraphicsType LWJGL3
Mockback to summary
public static final Graphics.GraphicsType Mock
WebGLback to summary
public static final Graphics.GraphicsType WebGL

Constructor Detail

GraphicsTypeback to summary
private GraphicsType()

Method Detail

valueOfback to summary
public static Graphics.GraphicsType valueOf(String name)
valuesback to summary
public static Graphics.GraphicsType[] values()
com.badlogic.gdx back to summary

public Class Graphics.Monitor

extends Object
Class Inheritance

Describes a monitor
Author
badlogic

Field Summary

Modifier and TypeField and Description
public final String
public final int
public final int

Constructor Summary

AccessConstructor and Description
protected
Monitor(int virtualX, int virtualY, String name)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

nameback to summary
public final String name
virtualXback to summary
public final int virtualX
virtualYback to summary
public final int virtualY

Constructor Detail

Monitorback to summary
protected Monitor(int virtualX, int virtualY, String name)