Package arc

Class Graphics

java.lang.Object
arc.Graphics
All Implemented Interfaces:
Disposable
Direct Known Subclasses:
AndroidGraphics, IOSGraphics, MockGraphics, SdlGraphics

public abstract class Graphics extends Object implements Disposable
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, 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.

  • 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 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:
      whether OpenGL ES 3.0 is available
    • getGL20

      public abstract GL20 getGL20()
      Returns:
      the GL20 instance
    • setGL20

      public abstract void setGL20(GL20 gl20)
      Set the GL20 instance
    • getGL30

      public abstract GL30 getGL30()
      Returns:
      the GL30 instance or null if not supported
    • setGL30

      public abstract void setGL30(GL30 gl30)
      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

      public void clear(Color color)
      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 the ApplicationListener.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

      public abstract GLVersion 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 pixels
      height - the height in pixels
      Returns:
      whether the operation succeeded
    • setTitle

      public abstract void setTitle(String title)
      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

      public abstract Graphics.BufferFormat getBufferFormat()
      Returns:
      the format of the color, depth and stencil buffer in a Graphics.BufferFormat instance
    • supportsExtension

      public abstract boolean supportsExtension(String extension)
      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 via Application.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.
    • 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

      public abstract Graphics.Cursor newCursor(Pixmap pixmap, int xHotspot, int yHotspot)
      Create a new cursor represented by the 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 - the mouse cursor image as a Pixmap
      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

      public Graphics.Cursor newCursor(String filename, int scale)
      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)
      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

      public void cursor(Graphics.Cursor cursor)
      Sets the display cursor.
    • setCursor

      protected abstract void setCursor(Graphics.Cursor cursor)
      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 the Graphics.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 a Graphics.Cursor
    • setSystemCursor

      protected abstract void setSystemCursor(Graphics.Cursor.SystemCursor systemCursor)
      Sets one of the predefined Graphics.Cursor.SystemCursors. Internal use only!
    • dispose

      public void dispose()
      Description copied from interface: Disposable
      Releases all resources of this object.
      Specified by:
      dispose in interface Disposable