Interface Graphics

  • All Known Implementing Classes:
    AbstractGraphics

    public interface Graphics
    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.

    • Method Detail

      • isGL30Available

        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
      • isGL31Available

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

        GL20 getGL20()
        Returns:
        the GL20 instance
      • getGL30

        GL30 getGL30()
        Returns:
        the GL30 instance or null if not supported
      • getGL31

        GL31 getGL31()
        Returns:
        the GL31 instance or null if not supported
      • getGL32

        GL32 getGL32()
        Returns:
        the GL32 instance or null if not supported
      • 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 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:
        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.
        use getDeltaTime() 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
      • 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 calling setFullscreenMode(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
      • 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 pixels
        height - 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
      • 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 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 - whether the rendering should be continuous or not.
      • 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 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
      • 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 the Cursor. It is recommended to call this function in the main render thread, and maximum one time per frame.
        Parameters:
        cursor - the mouse cursor as a Cursor