Class Graphics
- All Implemented Interfaces:
Disposable
- Direct Known Subclasses:
AndroidGraphics
,IOSGraphics
,MockGraphics
,SdlGraphics
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
, Shader
and FrameBuffer
,
Font
, Batch
and so on. All these classes are managed, meaning they don't need to be reloaded on a context
loss. Explore the arc.graphics package for more classes that might come in handy.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Class describing the bits per pixel, depth buffer precision, stencil precision and number of MSAA samples.static interface
Represents a mouse cursor. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear
(float r, float g, float b, float a) Clears the color buffer using the specified color.void
Clears the color buffer using the specified color.void
cursor
(Graphics.Cursor cursor) Sets the display cursor.void
dispose()
Releases all resources of this object.float
abstract int
abstract int
abstract Graphics.BufferFormat
abstract float
abstract float
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.abstract long
Returns the id of the current frame.abstract int
abstract GL20
getGL20()
abstract GL30
getGL30()
abstract GLVersion
abstract int
abstract float
getPpcX()
abstract float
getPpcY()
abstract float
getPpiX()
abstract float
getPpiY()
int[]
abstract int
getWidth()
abstract boolean
abstract boolean
Whether the app is fullscreen or notboolean
Returns whether OpenGL ES 3.0 is available.boolean
isHidden()
boolean
Returns whether this application is probably in portrait mode, e.g.abstract Graphics.Cursor
Create a new cursor represented by thePixmap
.Creates a new cursor by scaling a pixmap and adding an outline.Creates a new cursor by file name.Creates a new cursor by file name.Creates a new cursor by file name.abstract void
Requests a new frame to be rendered if the rendering mode is non-continuous.void
Sets the cursor to the default value, e.g.abstract void
setBorderless
(boolean undecorated) Sets the window decoration as enabled or disabled.abstract void
setContinuousRendering
(boolean isContinuous) Sets whether to render continuously.protected abstract void
setCursor
(Graphics.Cursor cursor) Only viable on desktop and web.boolean
Sets the window to full-screen mode.abstract void
Set the GL20 instanceabstract void
Set the GL30 instanceabstract void
setResizable
(boolean resizable) Sets whether or not the window should be resizable.protected abstract void
setSystemCursor
(Graphics.Cursor.SystemCursor systemCursor) Sets one of the predefinedGraphics.Cursor.SystemCursor
s.abstract void
Sets the title of the window.abstract void
setVSync
(boolean vsync) Enable/Disable vsynching.abstract boolean
setWindowedMode
(int width, int height) Sets the window to windowed mode.abstract boolean
supportsExtension
(String extension) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface arc.util.Disposable
isDisposed
-
Constructor Details
-
Graphics
public Graphics()
-
-
Method Details
-
isGL30Available
public boolean isGL30Available()Returns whether OpenGL ES 3.0 is available. If it is you can get an instance ofGL30
viagetGL30()
to access OpenGL ES 3.0 functionality. Note that this functionality will only be available if you instructed theApplication
instance to use OpenGL ES 3.0!- Returns:
- whether OpenGL ES 3.0 is available
-
getGL20
- Returns:
- the
GL20
instance
-
setGL20
Set the GL20 instance -
getGL30
- Returns:
- the
GL30
instance or null if not supported
-
setGL30
Set the GL30 instance -
clear
public void clear(float r, float g, float b, float a) Clears the color buffer using the specified color. -
clear
Clears the color buffer using the specified color. -
isPortrait
public boolean isPortrait()Returns whether this application is probably in portrait mode, e.g. if width < height. -
getWidth
public abstract int getWidth()- Returns:
- the width of the client area in logical pixels.
-
getHeight
public abstract int getHeight()- Returns:
- the height of the client area in logical pixels
-
getAspect
public float getAspect()- Returns:
- the aspect ratio, e.g. width/height
-
isHidden
public boolean isHidden()- Returns:
- whether the window is 'hidden', e.g. whether width or height of the window is less than 2. This is due to Windows reporting window size as 0 or 1 when minimized. This causes framebuffers to crash if resized.
-
getBackBufferWidth
public abstract int getBackBufferWidth()- Returns:
- the width of the framebuffer in physical pixels
-
getBackBufferHeight
public abstract int getBackBufferHeight()- Returns:
- the height of the framebuffer in physical pixels
-
getSafeInsets
public int[] getSafeInsets()- Returns:
- the safe area insets, in the order left-right-top-bottom.
-
getFrameId
public abstract 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.update()
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
public abstract float getDeltaTime()- Returns:
- the time span between the current frame and the last frame in seconds. Might be smoothed over n frames.
-
getFramesPerSecond
public abstract int getFramesPerSecond()- Returns:
- the average number of frames per second
-
getGLVersion
- Returns:
- the
GLVersion
of this Graphics instance
-
getPpiX
public abstract float getPpiX()- Returns:
- the pixels per inch on the x-axis
-
getPpiY
public abstract float getPpiY()- Returns:
- the pixels per inch on the y-axis
-
getPpcX
public abstract float getPpcX()- Returns:
- the pixels per centimeter on the x-axis
-
getPpcY
public abstract float getPpcY()- Returns:
- the pixels per centimeter on the y-axis.
-
getDensity
public abstract 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.- Returns:
- the logical density of the Display.
-
setFullscreen
public boolean setFullscreen()Sets the window to full-screen mode.- Returns:
- whether the operation succeeded.
-
setWindowedMode
public abstract 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
Sets the title of the window. Ignored on Android.- Parameters:
title
- the title.
-
setBorderless
public abstract void setBorderless(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 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
public abstract 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 desktop backends.
-
setVSync
public abstract 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.
-
getBufferFormat
- Returns:
- the format of the color, depth and stencil buffer in a
Graphics.BufferFormat
instance
-
supportsExtension
- Parameters:
extension
- the extension name- Returns:
- whether the extension is supported
-
isContinuousRendering
public abstract boolean isContinuousRendering()- Returns:
- whether rendering is continuous.
-
setContinuousRendering
public abstract 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 viaApplication.post(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
- whether the rendering should be continuous or not.
- A call to
-
requestRendering
public abstract 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
public abstract boolean isFullscreen()Whether the app is fullscreen or not -
newCursor
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 aPixmap
xHotspot
- 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
-
newCursor
public Graphics.Cursor newCursor(Pixmap pixmap, int scaling, Color outlineColor, int outlineThickness) Creates a new cursor by scaling a pixmap and adding an outline.- Parameters:
pixmap
- The base pixmap. Unscaled.scaling
- The factor by which to scale the base pixmap.outlineColor
- The color of the cursor's outline.
-
newCursor
Creates a new cursor by file name.- Parameters:
filename
- the name of the cursor .png file, found in the internal file "cursors/{name}.png"
-
newCursor
Creates a new cursor by file name.- Parameters:
filename
- the name of the cursor .png file, found in the internal file "cursors/{name}.png"
-
newCursor
public Graphics.Cursor newCursor(String filename, int scaling, Color outlineColor, int outlineScaling) Creates a new cursor by file name.- Parameters:
filename
- the name of the cursor .png file, found in the internal file "cursors/{name}.png"
-
restoreCursor
public void restoreCursor()Sets the cursor to the default value, e.g.Graphics.Cursor.SystemCursor.arrow
. -
cursor
Sets the display cursor. -
setCursor
Only viable on desktop and web. 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 theGraphics.Cursor
. It is recommended to call this function in the main render thread, and maximum one time per frame. Internal use only!- Parameters:
cursor
- the mouse cursor as aGraphics.Cursor
-
setSystemCursor
Sets one of the predefinedGraphics.Cursor.SystemCursor
s. Internal use only! -
dispose
public void dispose()Description copied from interface:Disposable
Releases all resources of this object.- Specified by:
dispose
in interfaceDisposable
-