Class ScreenUtils


  • public final class ScreenUtils
    extends java.lang.Object
    Class with static helper methods related to currently bound OpenGL frame buffer, including access to the current OpenGL FrameBuffer. These methods can be used to get the entire screen content or a portion thereof.
    • Constructor Summary

      Constructors 
      Constructor Description
      ScreenUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static void clear​(float r, float g, float b, float a)
      Clears the color buffers with the specified color.
      static void clear​(float r, float g, float b, float a, boolean clearDepth)
      Clears the color buffers and optionally the depth buffer.
      static void clear​(Color color)
      Clears the color buffers with the specified Color.
      static void clear​(Color color, boolean clearDepth)
      Clears the color buffers and optionally the depth buffer.
      static byte[] getFrameBufferPixels​(boolean flipY)
      Returns the current framebuffer contents as a byte[] array with a length equal to screen width * height * 4.
      static byte[] getFrameBufferPixels​(int x, int y, int w, int h, boolean flipY)
      Returns a portion of the current framebuffer contents specified by x, y, width and height, as a byte[] array with a length equal to the specified width * height * 4.
      static Pixmap getFrameBufferPixmap​(int x, int y, int w, int h)
      static TextureRegion getFrameBufferTexture()
      Returns the current framebuffer contents as a TextureRegion with a width and height equal to the current screen size.
      static TextureRegion getFrameBufferTexture​(int x, int y, int w, int h)
      Returns a portion of the current framebuffer contents specified by x, y, width and height as a TextureRegion with the same dimensions.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ScreenUtils

        public ScreenUtils()
    • Method Detail

      • clear

        public static void clear​(Color color)
        Clears the color buffers with the specified Color.
        Parameters:
        color - Color to clear the color buffers with.
      • clear

        public static void clear​(float r,
                                 float g,
                                 float b,
                                 float a)
        Clears the color buffers with the specified color.
      • clear

        public static void clear​(Color color,
                                 boolean clearDepth)
        Clears the color buffers and optionally the depth buffer.
        Parameters:
        color - Color to clear the color buffers with.
        clearDepth - Clears the depth buffer if true.
      • clear

        public static void clear​(float r,
                                 float g,
                                 float b,
                                 float a,
                                 boolean clearDepth)
        Clears the color buffers and optionally the depth buffer.
        Parameters:
        clearDepth - Clears the depth buffer if true.
      • getFrameBufferTexture

        public static TextureRegion getFrameBufferTexture​(int x,
                                                          int y,
                                                          int w,
                                                          int h)
        Returns a portion of the current framebuffer contents specified by x, y, width and height as a TextureRegion with the same dimensions. The base Texture always has MathUtils.nextPowerOfTwo(int) dimensions and RGBA8888 Pixmap.Format. It can be accessed via TextureRegion.getTexture(). This texture is not managed and has to be reloaded manually on a context loss. If the width and height specified are larger than the framebuffer dimensions, the Texture will be padded accordingly. Pixels that fall outside of the current screen will have RGBA values of 0.
        Parameters:
        x - the x position of the framebuffer contents to capture
        y - the y position of the framebuffer contents to capture
        w - the width of the framebuffer contents to capture
        h - the height of the framebuffer contents to capture
      • getFrameBufferPixels

        public static byte[] getFrameBufferPixels​(boolean flipY)
        Returns the current framebuffer contents as a byte[] array with a length equal to screen width * height * 4. The byte[] will always contain RGBA8888 data. Because of differences in screen and image origins the framebuffer contents should be flipped along the Y axis if you intend save them to disk as a bitmap. Flipping is not a cheap operation, so use this functionality wisely.
        Parameters:
        flipY - whether to flip pixels along Y axis
      • getFrameBufferPixels

        public static byte[] getFrameBufferPixels​(int x,
                                                  int y,
                                                  int w,
                                                  int h,
                                                  boolean flipY)
        Returns a portion of the current framebuffer contents specified by x, y, width and height, as a byte[] array with a length equal to the specified width * height * 4. The byte[] will always contain RGBA8888 data. If the width and height specified are larger than the framebuffer dimensions, the Texture will be padded accordingly. Pixels that fall outside of the current screen will have RGBA values of 0. Because of differences in screen and image origins the framebuffer contents should be flipped along the Y axis if you intend save them to disk as a bitmap. Flipping is not a cheap operation, so use this functionality wisely.
        Parameters:
        flipY - whether to flip pixels along Y axis