Skip to content

Commit ad03fa5

Browse files
authored
Capture ImGui in screenshots (scp-fs2open#7236)
* capture imgui in screenshots * revert buffer changes * request a screenshot for end of frame * full revert for cleanliness
1 parent 8e23ce8 commit ad03fa5

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

code/graphics/2d.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ color_gun Gr_t_red, Gr_t_green, Gr_t_blue, Gr_t_alpha;
9898
color_gun Gr_ta_red, Gr_ta_green, Gr_ta_blue, Gr_ta_alpha;
9999
color_gun *Gr_current_red, *Gr_current_green, *Gr_current_blue, *Gr_current_alpha;
100100

101+
static SCP_string Pending_screenshot_filename;
101102

102103
ubyte Gr_original_palette[768]; // The palette
103104
ubyte Gr_current_palette[768];
@@ -2943,13 +2944,25 @@ void gr_flip(bool execute_scripting)
29432944

29442945
TRACE_SCOPE(tracing::PageFlip);
29452946

2947+
if (!Pending_screenshot_filename.empty()) {
2948+
gr_print_screen(Pending_screenshot_filename.c_str());
2949+
Pending_screenshot_filename.clear();
2950+
}
2951+
29462952
//Prevent a real page flip if OpenXR is on and claims that that wasn't the full image yet
29472953
if (!gr_openxr_flip()) {
29482954
gr_screen.gf_flip();
29492955
gr_setup_frame();
29502956
}
29512957
}
29522958

2959+
void gr_request_screenshot(const char* filename)
2960+
{
2961+
if (Pending_screenshot_filename.empty()) {
2962+
Pending_screenshot_filename = filename;
2963+
}
2964+
}
2965+
29532966
void gr_print_timestamp(int x, int y, fix timestamp, int resize_mode)
29542967
{
29552968
int seconds = f2i(timestamp);

code/graphics/2d.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,6 +1074,8 @@ extern void gr_activate(int active);
10741074
#define gr_blob_screen GR_CALL(gr_screen.gf_blob_screen)
10751075
#define gr_dump_envmap GR_CALL(gr_screen.gf_dump_envmap)
10761076

1077+
void gr_request_screenshot(const char* filename);
1078+
10771079
//#define gr_flip GR_CALL(gr_screen.gf_flip)
10781080
void gr_flip(bool execute_scripting = true);
10791081

freespace2/freespace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4777,7 +4777,7 @@ int game_poll()
47774777
}
47784778

47794779
mprintf(( "Dumping screen to '%s'\n", tmp_name ));
4780-
gr_print_screen(tmp_name);
4780+
gr_request_screenshot(tmp_name);
47814781

47824782
os_config_write_uint(nullptr, "ScreenshotNum", counter);
47834783
}

0 commit comments

Comments
 (0)