Skip to content

Add F2 screenshot functionality#1262

Open
itsRevela wants to merge 1 commit intosmartcmd:mainfrom
itsRevela:feature/screenshots
Open

Add F2 screenshot functionality#1262
itsRevela wants to merge 1 commit intosmartcmd:mainfrom
itsRevela:feature/screenshots

Conversation

@itsRevela
Copy link

Description

- Adds in-game screenshot support using F2, matching Java Edition behavior (with local-only chat message). Screenshots are saved as PNG files to a `screenshots` folder in the game directory.

Changes

Previous Behavior

- There was no way to take in-game screenshots. To take a screenshot previously, you had to rely on Win+Shift+s or other something like the print screen button or other external tools.

Root Cause

- Screenshot functionality was never implemented in the LCE codebase. Didn't exist.

New Behavior

- Pressing F2 captures the current frame and saves it as a timestamped PNG file (ex: `2026-03-15_14.30.45.png`) in a `screenshots` directory, similar to how Java does it.

Fix Implementation

- Added `MINECRAFT_ACTION_SCREENSHOT` to `EControllerActions` in `App_enums.h`
- Mapped F2 to `KEY_SCREENSHOT` in `KeyboardMouseInput.h`
- Added screenshot capture logic in `Minecraft.cpp`:
    - `run_middle()` listens for the screenshot key press
    - `tick()` reads the framebuffer via `glReadPixels`, flips the image vertically, and writes it as PNG using `stb_image_write.h`
- Included `stb_image_write.h` (library by Sean Barrett) for PNG encoding

AI Use Disclosure

- No AI was used to write the code in this PR.

Related Issues

- None
Screenshot 2026-03-15 042632 Screenshot 2026-03-15 042716 Screenshot 2026-03-15 042727

@itsRevela itsRevela force-pushed the feature/screenshots branch 2 times, most recently from 3d76734 to c636d11 Compare March 15, 2026 10:28
@Patoke
Copy link

Patoke commented Mar 15, 2026

This functionality has existed within the game, the only difference is that it saves to the d: drive and uses a local index for the current screenshot instead of its date

This issue has been fixed in https://github.com/Patoke/4JLibs/ which is expected to be implemented into the main project soon

Unfortunately, this would make your commit unmergable as it's overlapping in functionality within the work plan of the project

What you could do is just commit a change that calls C4JRender::DoScreenGrabOnNextPresent() on F2 so that at least this can be merged and you can be added to the contributors list instead of being straight up closed, as well as keeping your other changes

If you need extra functionality for this, please let me know and I can add it to the 4JLibs repository, like a function that returns the name of the last created screenshot or ways to change the output directory

Thanks for your contribution!

@itsRevela itsRevela force-pushed the feature/screenshots branch from c636d11 to eb8c896 Compare March 16, 2026 04:19
@itsRevela
Copy link
Author

@Patoke Ah, I understand. I've updated the commit. Feel free to take a look!

- Updated `EControllerActions` to include `MINECRAFT_ACTION_SCREENSHOT`.
- Added conditional compilation for `stb_image_write.h` in `Minecraft.cpp`.
- Modified `run_middle()` to handle screenshot key press.
- Updated `tick()` to capture and save screenshots as PNG files.
- Introduced `KEY_SCREENSHOT` in `KeyboardMouseInput.h` mapped to F2.
- Added `stb_image_write.h` for image writing capabilities.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants