mirror of
https://gitlab.com/2009scape/rt4-client.git
synced 2026-08-01 14:39:16 -06:00
Simplified the screenshot capturing
We don't actually need to capture the OpenGL buffer itself, this is fine. Also it simplifies the code a fair bit too, and as an added benefit we can also capture the entire window including the border/decorations etc.
This commit is contained in:
parent
ec65b9e947
commit
40b1fc47a6
1 changed files with 7 additions and 39 deletions
|
|
@ -535,40 +535,8 @@ public final class client extends GameShell {
|
|||
if (!outputFolder.exists()){
|
||||
outputFolder.mkdirs();
|
||||
}
|
||||
int width = client.canvasWidth;
|
||||
int height = client.canvasHeight;
|
||||
if (GlRenderer.enabled) {
|
||||
try {
|
||||
GL2 gl = GlRenderer.gl;
|
||||
// Create a buffer to hold the pixels
|
||||
ByteBuffer buffer = ByteBuffer.allocateDirect(width * height * 4);
|
||||
buffer.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
// Read the pixels from the buffer
|
||||
gl.glReadPixels(0, 0, width, height, GL2.GL_RGBA, GL2.GL_UNSIGNED_BYTE, buffer);
|
||||
buffer.rewind();
|
||||
|
||||
// Create a BufferedImage and set its pixels
|
||||
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
|
||||
for (int h = 0; h < height; h++) {
|
||||
for (int w = 0; w < width; w++) {
|
||||
int b = buffer.get() & 0xFF; // Blue component
|
||||
int g = buffer.get() & 0xFF; // Green component
|
||||
int r = buffer.get() & 0xFF; // Red component
|
||||
int a = buffer.get() & 0xFF; // Alpha component
|
||||
int pixel = (a << 24) | (b << 16) | (g << 8) | r;
|
||||
image.setRGB(w, height - h - 1, pixel);
|
||||
}
|
||||
}
|
||||
|
||||
// Save the BufferedImage
|
||||
File outputFile = new File(outputFolder, filename);
|
||||
ImageIO.write(image, "png", outputFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
|
||||
try {
|
||||
Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
|
||||
Point point = window.getLocationOnScreen();
|
||||
int x = (int) point.getX();
|
||||
|
|
@ -582,12 +550,12 @@ public final class client extends GameShell {
|
|||
// Save the BufferedImage
|
||||
File outputFile = new File(outputFolder, filename);
|
||||
ImageIO.write(image, "png", outputFile);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (AWTException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (AWTException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@OriginalMember(owner = "client!lb", name = "a", descriptor = "(Z)V")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue