Utilities for taking screenshots of OpenGL applications.
readToBufferedImage
public static BufferedImage readToBufferedImage(int width,
int height)
throws GLException
Takes a screenshot of the current OpenGL drawable to a
BufferedImage. Requires the OpenGL context for the desired
drawable to be current. Takes the screenshot from the last
assigned read buffer, or the OpenGL default read buffer if none
has been specified by the user (GL_FRONT for single-buffered
configurations and GL_BACK for double-buffered configurations).
Note that the scanlines of the resulting image are flipped
vertically in order to correctly match the OpenGL contents, which
takes time and is therefore not as fast as the Targa screenshot
function.
No alpha channel is read back with this variant.
width
- the width of the current drawableheight
- the height of the current drawable
GLException
- if an OpenGL context was not current or
another OpenGL-related error occurred
readToBufferedImage
public static BufferedImage readToBufferedImage(int width,
int height,
boolean alpha)
throws GLException
Takes a screenshot of the current OpenGL drawable to a
BufferedImage. Requires the OpenGL context for the desired
drawable to be current. Takes the screenshot from the last
assigned read buffer, or the OpenGL default read buffer if none
has been specified by the user (GL_FRONT for single-buffered
configurations and GL_BACK for double-buffered configurations).
Note that the scanlines of the resulting image are flipped
vertically in order to correctly match the OpenGL contents, which
takes time and is therefore not as fast as the Targa screenshot
function.
width
- the width of the current drawableheight
- the height of the current drawablealpha
- whether the alpha channel should be read back. If
true, requires GL_EXT_abgr extension to be present.
GLException
- if an OpenGL context was not current or
another OpenGL-related error occurred
readToBufferedImage
public static BufferedImage readToBufferedImage(int x,
int y,
int width,
int height,
boolean alpha)
throws GLException
Takes a screenshot of the current OpenGL drawable to a
BufferedImage. Requires the OpenGL context for the desired
drawable to be current. Takes the screenshot from the last
assigned read buffer, or the OpenGL default read buffer if none
has been specified by the user (GL_FRONT for single-buffered
configurations and GL_BACK for double-buffered configurations).
Note that the scanlines of the resulting image are flipped
vertically in order to correctly match the OpenGL contents, which
takes time and is therefore not as fast as the Targa screenshot
function.
x
- the starting x coordinate of the screenshot, measured from the lower-lefty
- the starting y coordinate of the screenshot, measured from the lower-leftwidth
- the width of the desired screenshot areaheight
- the height of the desired screenshot areaalpha
- whether the alpha channel should be read back. If
true, requires GL_EXT_abgr extension to be present.
GLException
- if an OpenGL context was not current or
another OpenGL-related error occurred
writeToFile
public static void writeToFile(File file,
int width,
int height)
throws IOException,
GLException
Takes a screenshot of the current OpenGL drawable to the
specified file on disk using the ImageIO package. Requires the
OpenGL context for the desired drawable to be current. Takes the
screenshot from the last assigned read buffer, or the OpenGL
default read buffer if none has been specified by the user
(GL_FRONT for single-buffered configurations and GL_BACK for
double-buffered configurations). This is not the fastest
mechanism for taking a screenshot but may be more convenient than
others for getting images for consumption by other packages. The
file format is inferred from the suffix of the given file.
No alpha channel is saved with this variant.
file
- the file to write containing the screenshotwidth
- the width of the current drawableheight
- the height of the current drawable
GLException
- if an OpenGL context was not current or
another OpenGL-related error occurred
writeToFile
public static void writeToFile(File file,
int width,
int height,
boolean alpha)
throws IOException,
GLException
Takes a screenshot of the current OpenGL drawable to the
specified file on disk using the ImageIO package. Requires the
OpenGL context for the desired drawable to be current. Takes the
screenshot from the last assigned read buffer, or the OpenGL
default read buffer if none has been specified by the user
(GL_FRONT for single-buffered configurations and GL_BACK for
double-buffered configurations). This is not the fastest
mechanism for taking a screenshot but may be more convenient than
others for getting images for consumption by other packages. The
file format is inferred from the suffix of the given file.
Note that some file formats, in particular JPEG, can not handle
an alpha channel properly. If the "alpha" argument is specified
as true for such a file format it will be silently ignored.
file
- the file to write containing the screenshotwidth
- the width of the current drawableheight
- the height of the current drawablealpha
- whether an alpha channel should be saved. If true,
requires GL_EXT_abgr extension to be present.
GLException
- if an OpenGL context was not current or
another OpenGL-related error occurred
writeToFile
public static void writeToFile(File file,
int x,
int y,
int width,
int height,
boolean alpha)
throws IOException,
GLException
Takes a screenshot of the current OpenGL drawable to the
specified file on disk using the ImageIO package. Requires the
OpenGL context for the desired drawable to be current. Takes the
screenshot from the last assigned read buffer, or the OpenGL
default read buffer if none has been specified by the user
(GL_FRONT for single-buffered configurations and GL_BACK for
double-buffered configurations). This is not the fastest
mechanism for taking a screenshot but may be more convenient than
others for getting images for consumption by other packages. The
file format is inferred from the suffix of the given file.
Note that some file formats, in particular JPEG, can not handle
an alpha channel properly. If the "alpha" argument is specified
as true for such a file format it will be silently ignored.
file
- the file to write containing the screenshotx
- the starting x coordinate of the screenshot, measured from the lower-lefty
- the starting y coordinate of the screenshot, measured from the lower-leftwidth
- the width of the current drawableheight
- the height of the current drawablealpha
- whether an alpha channel should be saved. If true,
requires GL_EXT_abgr extension to be present.
GLException
- if an OpenGL context was not current or
another OpenGL-related error occurred
writeToTargaFile
public static void writeToTargaFile(File file,
int width,
int height)
throws GLException,
IOException
Takes a fast screenshot of the current OpenGL drawable to a Targa
file. Requires the OpenGL context for the desired drawable to be
current. Takes the screenshot from the last assigned read buffer,
or the OpenGL default read buffer if none has been specified by
the user (GL_FRONT for single-buffered configurations and GL_BACK
for double-buffered configurations). This is the fastest
mechanism for taking a screenshot of an application. Contributed
by Carsten Weisse of Bytonic Software (http://bytonic.de/).
No alpha channel is written with this variant.
file
- the file to write containing the screenshotwidth
- the width of the current drawableheight
- the height of the current drawable
GLException
- if an OpenGL context was not current or
another OpenGL-related error occurred
writeToTargaFile
public static void writeToTargaFile(File file,
int width,
int height,
boolean alpha)
throws GLException,
IOException
Takes a fast screenshot of the current OpenGL drawable to a Targa
file. Requires the OpenGL context for the desired drawable to be
current. Takes the screenshot from the last assigned read buffer,
or the OpenGL default read buffer if none has been specified by
the user (GL_FRONT for single-buffered configurations and GL_BACK
for double-buffered configurations). This is the fastest
mechanism for taking a screenshot of an application. Contributed
by Carsten Weisse of Bytonic Software (http://bytonic.de/).
file
- the file to write containing the screenshotwidth
- the width of the current drawableheight
- the height of the current drawablealpha
- whether the alpha channel should be saved. If true,
requires GL_EXT_abgr extension to be present.
GLException
- if an OpenGL context was not current or
another OpenGL-related error occurred
writeToTargaFile
public static void writeToTargaFile(File file,
int x,
int y,
int width,
int height,
boolean alpha)
throws GLException,
IOException
Takes a fast screenshot of the current OpenGL drawable to a Targa
file. Requires the OpenGL context for the desired drawable to be
current. Takes the screenshot from the last assigned read buffer,
or the OpenGL default read buffer if none has been specified by
the user (GL_FRONT for single-buffered configurations and GL_BACK
for double-buffered configurations). This is the fastest
mechanism for taking a screenshot of an application. Contributed
by Carsten Weisse of Bytonic Software (http://bytonic.de/).
file
- the file to write containing the screenshotx
- the starting x coordinate of the screenshot, measured from the lower-lefty
- the starting y coordinate of the screenshot, measured from the lower-leftwidth
- the width of the desired screenshot areaheight
- the height of the desired screenshot areaalpha
- whether the alpha channel should be saved. If true,
requires GL_EXT_abgr extension to be present.
GLException
- if an OpenGL context was not current or
another OpenGL-related error occurred