Package com.badlogic.gdx
Interface Graphics
-
- All Known Implementing Classes:
AbstractGraphics
public interface GraphicsThis interface encapsulates communication with the graphics processor. Depending on the available hardware and the currentApplicationconfiguration, access toGL20andGL30are 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 explicitlyrequestRendering().There are many more utility classes that are not directly generated by the
Graphicsinterfaces. SeeVertexArray,VertexBufferObject,IndexBufferObject,Mesh,ShaderProgramandFrameBuffer,BitmapFont,Batchand 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classGraphics.BufferFormatClass describing the bits per pixel, depth buffer precision, stencil precision and number of MSAA samples.static classGraphics.DisplayModeDescribe a fullscreen display modestatic classGraphics.GraphicsTypeEnumeration describing different types ofGraphicsimplementations.static classGraphics.MonitorDescribes a monitor
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description intgetBackBufferHeight()floatgetBackBufferScale()intgetBackBufferWidth()Graphics.BufferFormatgetBufferFormat()floatgetDeltaTime()floatgetDensity()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.Graphics.DisplayModegetDisplayMode()Graphics.DisplayModegetDisplayMode(Graphics.Monitor monitor)Graphics.DisplayMode[]getDisplayModes()Graphics.DisplayMode[]getDisplayModes(Graphics.Monitor monitor)longgetFrameId()Returns the id of the current frame.intgetFramesPerSecond()GL20getGL20()GL30getGL30()GL31getGL31()GL32getGL32()GLVersiongetGLVersion()intgetHeight()Graphics.MonitorgetMonitor()Graphics.Monitor[]getMonitors()floatgetPpcX()floatgetPpcY()floatgetPpiX()floatgetPpiY()Graphics.MonitorgetPrimaryMonitor()floatgetRawDeltaTime()Deprecated.usegetDeltaTime()instead.intgetSafeInsetBottom()intgetSafeInsetLeft()intgetSafeInsetRight()intgetSafeInsetTop()Graphics.GraphicsTypegetType()intgetWidth()booleanisContinuousRendering()booleanisFullscreen()Whether the app is fullscreen or notbooleanisGL30Available()Returns whether OpenGL ES 3.0 is available.booleanisGL31Available()Returns whether OpenGL ES 3.1 is available.booleanisGL32Available()Returns whether OpenGL ES 3.2 is available.CursornewCursor(Pixmap pixmap, int xHotspot, int yHotspot)Create a new cursor represented by thePixmap.voidrequestRendering()Requests a new frame to be rendered if the rendering mode is non-continuous.voidsetContinuousRendering(boolean isContinuous)Sets whether to render continuously.voidsetCursor(Cursor cursor)Only viable on the lwjgl-backend and on the gwt-backend.voidsetForegroundFPS(int fps)Sets the target framerate for the application when using continuous rendering.booleansetFullscreenMode(Graphics.DisplayMode displayMode)Sets the window to full-screen mode.voidsetGL20(GL20 gl20)Set the GL20 instancevoidsetGL30(GL30 gl30)Set the GL30 instancevoidsetGL31(GL31 gl31)Set the GL31 instancevoidsetGL32(GL32 gl32)Set the GL32 instancevoidsetResizable(boolean resizable)Sets whether or not the window should be resizable.voidsetSystemCursor(Cursor.SystemCursor systemCursor)Sets one of the predefinedCursor.SystemCursorsvoidsetTitle(java.lang.String title)Sets the title of the window.voidsetUndecorated(boolean undecorated)Sets the window decoration as enabled or disabled.voidsetVSync(boolean vsync)Enable/Disable vsynching.booleansetWindowedMode(int width, int height)Sets the window to windowed mode.booleansupportsDisplayModeChange()Whether the given backend supports a display mode change via callingsetFullscreenMode(DisplayMode)booleansupportsExtension(java.lang.String extension)
-
-
-
Method Detail
-
isGL30Available
boolean isGL30Available()
Returns whether OpenGL ES 3.0 is available. If it is you can get an instance ofGL30viagetGL30()to access OpenGL ES 3.0 functionality. Note that this functionality will only be available if you instructed theApplicationinstance to use OpenGL ES 3.0!- Returns:
- whether OpenGL ES 3.0 is available
-
isGL31Available
boolean isGL31Available()
Returns whether OpenGL ES 3.1 is available. If it is you can get an instance ofGL31viagetGL31()to access OpenGL ES 3.1 functionality. Note that this functionality will only be available if you instructed theApplicationinstance to use OpenGL ES 3.1!- Returns:
- whether OpenGL ES 3.1 is available
-
isGL32Available
boolean isGL32Available()
Returns whether OpenGL ES 3.2 is available. If it is you can get an instance ofGL32viagetGL32()to access OpenGL ES 3.2 functionality. Note that this functionality will only be available if you instructed theApplicationinstance to use OpenGL ES 3.2!- Returns:
- whether OpenGL ES 3.2 is available
-
setGL20
void setGL20(GL20 gl20)
Set the GL20 instance
-
setGL30
void setGL30(GL30 gl30)
Set the GL30 instance
-
setGL31
void setGL31(GL31 gl31)
Set the GL31 instance
-
setGL32
void setGL32(GL32 gl32)
Set the GL32 instance
-
getWidth
int getWidth()
- Returns:
- the width of the client area in logical pixels.
-
getHeight
int getHeight()
- Returns:
- the height of the client area in logical pixels
-
getBackBufferWidth
int getBackBufferWidth()
- Returns:
- the width of the framebuffer in physical pixels
-
getBackBufferHeight
int getBackBufferHeight()
- Returns:
- the height of the framebuffer in physical pixels
-
getBackBufferScale
float getBackBufferScale()
- Returns:
- amount of pixels per logical pixel (point)
-
getSafeInsetLeft
int getSafeInsetLeft()
- Returns:
- the inset from the left which avoids display cutouts in logical pixels
-
getSafeInsetTop
int getSafeInsetTop()
- Returns:
- the inset from the top which avoids display cutouts in logical pixels
-
getSafeInsetBottom
int getSafeInsetBottom()
- Returns:
- the inset from the bottom which avoids display cutouts or floating gesture bars, in logical pixels
-
getSafeInsetRight
int getSafeInsetRight()
- Returns:
- the inset from the right which avoids display cutouts in logical pixels
-
getFrameId
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 theApplicationListener.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:
- the id of the current frame
-
getDeltaTime
float getDeltaTime()
- Returns:
- the time span between the current frame and the last frame in seconds.
-
getRawDeltaTime
@Deprecated float getRawDeltaTime()
Deprecated.usegetDeltaTime()instead.- Returns:
- the time span between the current frame and the last frame in seconds, without smoothing
-
getFramesPerSecond
int getFramesPerSecond()
- Returns:
- the average number of frames per second
-
getType
Graphics.GraphicsType getType()
- Returns:
- the
Graphics.GraphicsTypeof this Graphics instance
-
getPpiX
float getPpiX()
- Returns:
- the pixels per inch on the x-axis
-
getPpiY
float getPpiY()
- Returns:
- the pixels per inch on the y-axis
-
getPpcX
float getPpcX()
- Returns:
- the pixels per centimeter on the x-axis
-
getPpcY
float getPpcY()
- Returns:
- the pixels per centimeter on the y-axis.
-
getDensity
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:
- the Density Independent Pixel factor of the display.
-
supportsDisplayModeChange
boolean supportsDisplayModeChange()
Whether the given backend supports a display mode change via callingsetFullscreenMode(DisplayMode)- Returns:
- whether display mode changes are supported or not.
-
getPrimaryMonitor
Graphics.Monitor getPrimaryMonitor()
- Returns:
- the primary monitor
-
getMonitor
Graphics.Monitor getMonitor()
- Returns:
- the monitor the application's window is located on
-
getMonitors
Graphics.Monitor[] getMonitors()
- Returns:
- the currently connected
Graphics.Monitors
-
getDisplayModes
Graphics.DisplayMode[] getDisplayModes()
- Returns:
- the supported fullscreen
Graphics.DisplayMode(s) of the monitor the window is on
-
getDisplayModes
Graphics.DisplayMode[] getDisplayModes(Graphics.Monitor monitor)
- Returns:
- the supported fullscreen
Graphics.DisplayModes of the givenGraphics.Monitor
-
getDisplayMode
Graphics.DisplayMode getDisplayMode()
- Returns:
- the current
Graphics.DisplayModeof the monitor the window is on.
-
getDisplayMode
Graphics.DisplayMode getDisplayMode(Graphics.Monitor monitor)
- Returns:
- the current
Graphics.DisplayModeof the givenGraphics.Monitor
-
setFullscreenMode
boolean setFullscreenMode(Graphics.DisplayMode displayMode)
Sets the window to full-screen mode.- Parameters:
displayMode- the display mode.- Returns:
- whether the operation succeeded.
-
setWindowedMode
boolean setWindowedMode(int width, int height)Sets the window to windowed mode.- Parameters:
width- the width in pixelsheight- the height in pixels- Returns:
- whether the operation succeeded
-
setTitle
void setTitle(java.lang.String title)
Sets the title of the window. Ignored on Android.- Parameters:
title- the title.
-
setUndecorated
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- true if the window border or status bar should be hidden. false otherwise.
-
setResizable
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.- Parameters:
resizable-
-
setVSync
void setVSync(boolean vsync)
Enable/Disable vsynching. This is a best-effort attempt which might not work on all platforms.- Parameters:
vsync- vsync enabled or not.
-
setForegroundFPS
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- the targeted fps; default differs by platform
-
getBufferFormat
Graphics.BufferFormat getBufferFormat()
- Returns:
- the format of the color, depth and stencil buffer in a
Graphics.BufferFormatinstance
-
supportsExtension
boolean supportsExtension(java.lang.String extension)
- Parameters:
extension- the extension name- Returns:
- whether the extension is supported
-
setContinuousRendering
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
Runnableis posted to the rendering thread viaApplication.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.
ApplicationListener. This method can be called from any thread.- Parameters:
isContinuous- whether the rendering should be continuous or not.
- A call to
-
isContinuousRendering
boolean isContinuousRendering()
- Returns:
- whether rendering is continuous.
-
requestRendering
void requestRendering()
Requests a new frame to be rendered if the rendering mode is non-continuous. This method can be called from any thread.
-
isFullscreen
boolean isFullscreen()
Whether the app is fullscreen or not
-
newCursor
Cursor newCursor(Pixmap pixmap, int xHotspot, int yHotspot)
Create a new cursor represented by thePixmap. 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 callingsetCursor(Cursor).- Parameters:
pixmap- the mouse cursor image as aPixmapxHotspot- the x location of the hotspot pixel within the cursor image (origin top-left corner)yHotspot- the y location of the hotspot pixel within the cursor image (origin top-left corner)- Returns:
- a cursor object that can be used by calling
setCursor(Cursor)or null if not supported
-
setCursor
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 theCursor. It is recommended to call this function in the main render thread, and maximum one time per frame.- Parameters:
cursor- the mouse cursor as aCursor
-
setSystemCursor
void setSystemCursor(Cursor.SystemCursor systemCursor)
Sets one of the predefinedCursor.SystemCursors
-
-