APIdia Launch Partner
Top Description Constructors Methods
com.badlogic.gdx.utils

public final Class ScreenUtils

extends Object
Class Inheritance
Imports
java.nio.Buffer, .ByteBuffer, com.badlogic.gdx.Gdx, com.badlogic.gdx.graphics.Color, .GL20, .Pixmap, .Pixmap.Blending, .Pixmap.Format, .Texture, com.badlogic.gdx.graphics.g2d.TextureRegion, com.badlogic.gdx.math.MathUtils

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.
Author
espitz

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
clear(Color
Color to clear the color buffers with.
color
)

Clears the color buffers with the specified Color.

public static void
clear(float r, float g, float b, float a)

Clears the color buffers with the specified color.

public static void
clear(Color
Color to clear the color buffers with.
color
,
boolean
Clears the depth buffer if true.
clearDepth
)

Clears the color buffers and optionally the depth buffer.

public static void
clear(float r, float g, float b, float a, boolean
Clears the depth buffer if true.
clearDepth
)

Clears the color buffers and optionally the depth buffer.

public static void
clear(float r, float g, float b, float a, boolean
Clears the depth buffer if true.
clearDepth
,
boolean
applies multi-sampling for antialiasing if true.
applyAntialiasing
)

Clears the color buffers, optionally the depth buffer and whether to apply antialiasing (requires to set number of samples in the launcher class).

public static byte[]
getFrameBufferPixels(boolean
whether to flip pixels along Y axis
flipY
)

Returns the current framebuffer contents as a byte[] array with a length equal to screen width * height * 4.

public static byte[]
getFrameBufferPixels(int x, int y, int w, int h, boolean
whether to flip pixels along Y axis
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.

public static Pixmap
getFrameBufferPixmap(int x, int y, int w, int h)

public static TextureRegion
getFrameBufferTexture()

Returns the current framebuffer contents as a TextureRegion with a width and height equal to the current screen size.

public static TextureRegion
getFrameBufferTexture(int
the x position of the framebuffer contents to capture
x
,
int
the y position of the framebuffer contents to capture
y
,
int
the width of the framebuffer contents to capture
w
,
int
the height of the framebuffer contents to capture
h
)

Returns a portion of the current framebuffer contents specified by x, y, width and height as a TextureRegion with the same dimensions.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ScreenUtilsback to summary
public ScreenUtils()

Method Detail

clearback to summary
public static void clear(Color color)

Clears the color buffers with the specified Color.

Parameters
color:Color

Color to clear the color buffers with.

clearback to summary
public static void clear(float r, float g, float b, float a)

Clears the color buffers with the specified color.

clearback to summary
public static void clear(Color color, boolean clearDepth)

Clears the color buffers and optionally the depth buffer.

Parameters
color:Color

Color to clear the color buffers with.

clearDepth:boolean

Clears the depth buffer if true.

clearback to summary
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:boolean

Clears the depth buffer if true.

clearback to summary
public static void clear(float r, float g, float b, float a, boolean clearDepth, boolean applyAntialiasing)

Clears the color buffers, optionally the depth buffer and whether to apply antialiasing (requires to set number of samples in the launcher class).

Parameters
clearDepth:boolean

Clears the depth buffer if true.

applyAntialiasing:boolean

applies multi-sampling for antialiasing if true.

getFrameBufferPixelsback to summary
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:boolean

whether to flip pixels along Y axis

getFrameBufferPixelsback to summary
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:boolean

whether to flip pixels along Y axis

getFrameBufferPixmapback to summary
public static Pixmap getFrameBufferPixmap(int x, int y, int w, int h)
Annotations
@Deprecated
getFrameBufferTextureback to summary
public static TextureRegion getFrameBufferTexture()

Returns the current framebuffer contents as a TextureRegion with a width and height equal to the current screen size. The base Texture always has MathUtils#nextPowerOfTwo dimensions and RGBA8888 Format. It can be accessed via TextureRegion#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.

getFrameBufferTextureback to summary
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 dimensions and RGBA8888 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:int

the x position of the framebuffer contents to capture

y:int

the y position of the framebuffer contents to capture

w:int

the width of the framebuffer contents to capture

h:int

the height of the framebuffer contents to capture