Skip to content

Commit

Permalink
Attempt to fix screenshots when external automap open
Browse files Browse the repository at this point in the history
  • Loading branch information
bradharding committed Nov 28, 2023
1 parent 1f49b00 commit 7b1bfb3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
23 changes: 12 additions & 11 deletions src/i_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ uint32_t amask;
uint32_t pixelformat;
int bpp = 0;

uint32_t maprmask;
uint32_t mapgmask;
uint32_t mapbmask;
uint32_t mapamask;
uint32_t mappixelformat;
int mapbpp = 0;

static int displaywidth;
static int displayheight;
static int displaycenterx;
Expand Down Expand Up @@ -968,12 +975,6 @@ static void GetDisplays(void)

bool I_CreateExternalAutomap(void)
{
uint32_t pixelformat;
uint32_t rmask;
uint32_t gmask;
uint32_t bmask;
uint32_t amask;
int bpp;
const char *displayname;

mapscreen = *screens;
Expand Down Expand Up @@ -1019,13 +1020,13 @@ bool I_CreateExternalAutomap(void)
if (!(mapsurface = SDL_CreateRGBSurface(0, MAPWIDTH, MAPHEIGHT, 8, 0, 0, 0, 0)))
I_SDLError("SDL_CreateRGBSurface", -1);

if ((pixelformat = SDL_GetWindowPixelFormat(mapwindow)) == SDL_PIXELFORMAT_UNKNOWN)
if ((mappixelformat = SDL_GetWindowPixelFormat(mapwindow)) == SDL_PIXELFORMAT_UNKNOWN)
I_SDLError("SDL_GetWindowPixelFormat", -1);

if (!SDL_PixelFormatEnumToMasks(pixelformat, &bpp, &rmask, &gmask, &bmask, &amask))
if (!SDL_PixelFormatEnumToMasks(mappixelformat, &mapbpp, &maprmask, &mapgmask, &mapbmask, &mapamask))
I_SDLError("SDL_PixelFormatEnumToMasks", -1);

if (!(mapbuffer = SDL_CreateRGBSurface(0, MAPWIDTH, MAPHEIGHT, bpp, rmask, gmask, bmask, amask)))
if (!(mapbuffer = SDL_CreateRGBSurface(0, MAPWIDTH, MAPHEIGHT, mapbpp, maprmask, mapgmask, mapbmask, mapamask)))
I_SDLError("SDL_CreateRGBSurface", -1);

mappitch = mapbuffer->pitch;
Expand All @@ -1036,15 +1037,15 @@ bool I_CreateExternalAutomap(void)
if (nearestlinear)
SDL_SetHintWithPriority(SDL_HINT_RENDER_SCALE_QUALITY, vid_scalefilter_nearest, SDL_HINT_OVERRIDE);

if (!(maptexture = SDL_CreateTexture(maprenderer, pixelformat, SDL_TEXTUREACCESS_STREAMING,
if (!(maptexture = SDL_CreateTexture(maprenderer, mappixelformat, SDL_TEXTUREACCESS_STREAMING,
MAPWIDTH, MAPHEIGHT)))
I_SDLError("SDL_CreateTexture", -2);

if (nearestlinear)
{
SDL_SetHintWithPriority(SDL_HINT_RENDER_SCALE_QUALITY, vid_scalefilter_linear, SDL_HINT_OVERRIDE);

if (!(maptexture_upscaled = SDL_CreateTexture(maprenderer, pixelformat,
if (!(maptexture_upscaled = SDL_CreateTexture(maprenderer, mappixelformat,
SDL_TEXTUREACCESS_TARGET, upscaledwidth * MAPWIDTH, upscaledheight * MAPHEIGHT)))
I_SDLError("SDL_CreateTexture", -2);

Expand Down
7 changes: 7 additions & 0 deletions src/i_video.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ extern uint32_t amask;
extern uint32_t pixelformat;
extern int bpp;

extern uint32_t maprmask;
extern uint32_t mapgmask;
extern uint32_t mapbmask;
extern uint32_t mapamask;
extern uint32_t mappixelformat;
extern int mapbpp;

extern bool usinggamecontroller;
extern bool usingmouse;
extern bool windowfocused;
Expand Down
11 changes: 6 additions & 5 deletions src/v_video.c
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,8 @@ char lbmname1[MAX_PATH];
char lbmpath1[MAX_PATH];
char lbmpath2[MAX_PATH];

static bool V_SavePNG(SDL_Window *sdlwindow, SDL_Renderer *sdlrenderer, const char *path)
static bool V_SavePNG(SDL_Window *sdlwindow, SDL_Renderer *sdlrenderer, int sdlpixelformat,
int sdlbpp, int sdlrmask, int sdlgmask, int sdlbmask, int sdlamask, const char *path)
{
bool result = false;
int width = 0;
Expand All @@ -1765,9 +1766,9 @@ static bool V_SavePNG(SDL_Window *sdlwindow, SDL_Renderer *sdlrenderer, const ch
SDL_GetWindowSize(sdlwindow, &width, &height);

if (width && height && (screenshot = SDL_CreateRGBSurface(0, (vid_widescreen ? width : height * 4 / 3),
height, bpp, rmask, gmask, bmask, amask)))
height, sdlbpp, sdlrmask, sdlgmask, sdlbmask, sdlamask)))
{
if (!SDL_RenderReadPixels(sdlrenderer, NULL, pixelformat, screenshot->pixels, screenshot->pitch))
if (!SDL_RenderReadPixels(sdlrenderer, NULL, sdlpixelformat, screenshot->pixels, screenshot->pitch))
result = !IMG_SavePNG(screenshot, path);

SDL_FreeSurface(screenshot);
Expand Down Expand Up @@ -1849,7 +1850,7 @@ bool V_ScreenShot(void)
M_snprintf(lbmpath1, sizeof(lbmpath1), "%s%s", screenshotfolder, lbmname1);
} while (M_FileExists(lbmpath1));

result = V_SavePNG(window, renderer, lbmpath1);
result = V_SavePNG(window, renderer, pixelformat, bpp, rmask, gmask, bmask, amask, lbmpath1);

if (result && mapwindow && gamestate == GS_LEVEL)
{
Expand All @@ -1863,7 +1864,7 @@ bool V_ScreenShot(void)
free(temp2);
} while (M_FileExists(lbmpath2));

V_SavePNG(mapwindow, maprenderer, lbmpath2);
V_SavePNG(mapwindow, maprenderer, mappixelformat, mapbpp, maprmask, mapgmask, mapbmask, mapamask, lbmpath2);
}

free(temp1);
Expand Down

0 comments on commit 7b1bfb3

Please sign in to comment.