Package com.badlogic.gdx.utils
Class ScreenUtils
- java.lang.Object
-
- com.badlogic.gdx.utils.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)
Deprecated.usePixmap.createFromFrameBuffer(int, int, int, int)
instead.static TextureRegion
getFrameBufferTexture()
Returns the current framebuffer contents as aTextureRegion
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 aTextureRegion
with the same dimensions.
-
-
-
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()
Returns the current framebuffer contents as aTextureRegion
with a width and height equal to the current screen size. The baseTexture
always hasMathUtils.nextPowerOfTwo(int)
dimensions and RGBA8888Pixmap.Format
. It can be accessed viaTextureRegion.getTexture()
. The texture is not managed and has to be reloaded manually on a context loss. The returned TextureRegion is flipped along the Y axis by default.
-
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 aTextureRegion
with the same dimensions. The baseTexture
always hasMathUtils.nextPowerOfTwo(int)
dimensions and RGBA8888Pixmap.Format
. It can be accessed viaTextureRegion.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 capturey
- the y position of the framebuffer contents to capturew
- the width of the framebuffer contents to captureh
- the height of the framebuffer contents to capture
-
getFrameBufferPixmap
@Deprecated public static Pixmap getFrameBufferPixmap(int x, int y, int w, int h)
Deprecated.usePixmap.createFromFrameBuffer(int, int, int, int)
instead.
-
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
-
-