2021-03-06 05:40:13 +01:00
|
|
|
#include <SDL.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2022-12-01 07:30:16 +01:00
|
|
|
#include "Alloc.h"
|
2023-01-07 19:28:07 +01:00
|
|
|
#include "Constants.h"
|
2020-01-01 21:29:24 +01:00
|
|
|
#include "Graphics.h"
|
2021-03-06 05:40:13 +01:00
|
|
|
#include "Maths.h"
|
2023-01-07 19:28:07 +01:00
|
|
|
#include "Screen.h"
|
|
|
|
#include "UtilityClass.h"
|
|
|
|
#include "Vlogging.h"
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void setRect( SDL_Rect& _r, int x, int y, int w, int h )
|
|
|
|
{
|
|
|
|
_r.x = x;
|
|
|
|
_r.y = y;
|
|
|
|
_r.w = w;
|
|
|
|
_r.h = h;
|
|
|
|
}
|
|
|
|
|
2021-03-06 05:12:01 +01:00
|
|
|
static SDL_Surface* RecreateSurfaceWithDimensions(
|
|
|
|
SDL_Surface* surface,
|
|
|
|
const int width,
|
|
|
|
const int height
|
|
|
|
) {
|
|
|
|
SDL_Surface* retval;
|
Copy blend mode to recreated surface
This fixes a "root cause" bug (that's existed since 2.2 and below) where
recreated surfaces wouldn't preserve the blend mode of their original
surface.
The surface-level (pun genuinely unintended) bug that this root bug
fixes is the one where there's no background to the room name during the
map menu animation in Flip Mode.
This is because the room name background relies on graphics.backBuffer
being filled with complete black. This is achieved by a call to
ClearSurface() - however, ClearSurface() actually fills it with
transparent black (this is not a regression; in 2.2 and previous, this
was an "inlined" FillRect(backBuffer, 0x00000000)). This would be okay,
and indeed the room name background renders fine in unflipped mode - but
it suddenly breaks in Flip Mode.
Why? Because backBuffer gets fed through FlipSurfaceVerticle(), and
FlipSurfaceVerticle() creates a temporary surface with the same
dimensions and color masks as backBuffer - it, however, does NOT create
it with the same blend mode, and kind of sort of just forgets that the
original was SDL_BLENDMODE_NONE; the new surface is SDL_BLENDMODE_BLEND.
Thus, transparency applies on the new surface, and instead of the room
name being drawn against black, it gets drawn against transparency.
2021-03-06 05:17:56 +01:00
|
|
|
SDL_BlendMode blend_mode;
|
2021-03-06 05:12:01 +01:00
|
|
|
|
|
|
|
if (surface == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = SDL_CreateRGBSurface(
|
|
|
|
surface->flags,
|
|
|
|
width,
|
|
|
|
height,
|
|
|
|
surface->format->BitsPerPixel,
|
|
|
|
surface->format->Rmask,
|
|
|
|
surface->format->Gmask,
|
|
|
|
surface->format->Bmask,
|
|
|
|
surface->format->Amask
|
|
|
|
);
|
|
|
|
|
|
|
|
if (retval == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
Copy blend mode to recreated surface
This fixes a "root cause" bug (that's existed since 2.2 and below) where
recreated surfaces wouldn't preserve the blend mode of their original
surface.
The surface-level (pun genuinely unintended) bug that this root bug
fixes is the one where there's no background to the room name during the
map menu animation in Flip Mode.
This is because the room name background relies on graphics.backBuffer
being filled with complete black. This is achieved by a call to
ClearSurface() - however, ClearSurface() actually fills it with
transparent black (this is not a regression; in 2.2 and previous, this
was an "inlined" FillRect(backBuffer, 0x00000000)). This would be okay,
and indeed the room name background renders fine in unflipped mode - but
it suddenly breaks in Flip Mode.
Why? Because backBuffer gets fed through FlipSurfaceVerticle(), and
FlipSurfaceVerticle() creates a temporary surface with the same
dimensions and color masks as backBuffer - it, however, does NOT create
it with the same blend mode, and kind of sort of just forgets that the
original was SDL_BLENDMODE_NONE; the new surface is SDL_BLENDMODE_BLEND.
Thus, transparency applies on the new surface, and instead of the room
name being drawn against black, it gets drawn against transparency.
2021-03-06 05:17:56 +01:00
|
|
|
SDL_GetSurfaceBlendMode(surface, &blend_mode);
|
|
|
|
SDL_SetSurfaceBlendMode(retval, blend_mode);
|
|
|
|
|
2021-03-06 05:12:01 +01:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2020-01-01 21:29:24 +01:00
|
|
|
SDL_Surface* GetSubSurface( SDL_Surface* metaSurface, int x, int y, int width, int height )
|
|
|
|
{
|
|
|
|
// Create an SDL_Rect with the area of the _surface
|
|
|
|
SDL_Rect area;
|
|
|
|
area.x = x;
|
|
|
|
area.y = y;
|
|
|
|
area.w = width;
|
|
|
|
area.h = height;
|
|
|
|
|
|
|
|
//Convert to the correct display format after nabbing the new _surface or we will slow things down.
|
2021-03-06 05:12:01 +01:00
|
|
|
SDL_Surface* preSurface = RecreateSurfaceWithDimensions(
|
|
|
|
metaSurface,
|
2020-08-23 03:52:42 +02:00
|
|
|
width,
|
2021-03-06 05:12:01 +01:00
|
|
|
height
|
2020-08-23 03:52:42 +02:00
|
|
|
);
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
// Lastly, apply the area from the meta _surface onto the whole of the sub _surface.
|
|
|
|
SDL_BlitSurface(metaSurface, &area, preSurface, 0);
|
|
|
|
|
|
|
|
// Return the new Bitmap _surface
|
|
|
|
return preSurface;
|
|
|
|
}
|
|
|
|
|
2023-01-07 19:28:07 +01:00
|
|
|
void DrawPixel(SDL_Surface* surface, const int x, const int y, const SDL_Color color)
|
2020-01-01 21:29:24 +01:00
|
|
|
{
|
2023-12-29 20:34:16 +01:00
|
|
|
const SDL_Point point = {x, y};
|
|
|
|
const SDL_Rect rect = {0, 0, surface->w, surface->h};
|
|
|
|
const bool inbounds = SDL_PointInRect(&point, &rect);
|
|
|
|
if (!inbounds)
|
|
|
|
{
|
|
|
|
WHINE_ONCE_ARGS((
|
|
|
|
"Pixel draw is not inbounds: "
|
|
|
|
"Attempted to draw to %i,%i in %ix%i surface",
|
|
|
|
x, y, surface->w, surface->h
|
|
|
|
));
|
|
|
|
SDL_assert(0 && "Pixel draw is not inbounds!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 01:36:43 +01:00
|
|
|
const SDL_PixelFormat* fmt = surface->format;
|
|
|
|
const int bpp = fmt->BytesPerPixel;
|
2023-11-01 06:52:42 +01:00
|
|
|
Uint8* pixel = (Uint8*) surface->pixels + y * surface->pitch + x * bpp;
|
|
|
|
Uint32* pixel32 = (Uint32*) pixel;
|
2023-01-02 01:36:43 +01:00
|
|
|
|
|
|
|
switch (bpp)
|
2020-01-01 21:29:24 +01:00
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
case 2:
|
2023-11-01 06:52:42 +01:00
|
|
|
SDL_assert(0 && "Colors other than 24- or 32- bit unsupported!");
|
|
|
|
break;
|
|
|
|
|
2020-01-01 21:29:24 +01:00
|
|
|
case 3:
|
2023-11-01 06:52:42 +01:00
|
|
|
{
|
|
|
|
const Uint32 single = SDL_MapRGB(fmt, color.r, color.g, color.b);
|
|
|
|
pixel[0] = (single & 0xFF0000) >> 16;
|
|
|
|
pixel[1] = (single & 0x00FF00) >> 8;
|
|
|
|
pixel[2] = (single & 0x0000FF) >> 0;
|
|
|
|
break;
|
|
|
|
}
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
case 4:
|
2023-11-01 06:52:42 +01:00
|
|
|
*pixel32 = SDL_MapRGBA(fmt, color.r, color.g, color.b, color.a);
|
2020-01-01 21:29:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-02 01:36:43 +01:00
|
|
|
SDL_Color ReadPixel(const SDL_Surface* surface, const int x, const int y)
|
2020-01-01 21:29:24 +01:00
|
|
|
{
|
2023-12-29 20:34:16 +01:00
|
|
|
SDL_Color color = {0, 0, 0, 0};
|
|
|
|
const SDL_Point point = {x, y};
|
|
|
|
const SDL_Rect rect = {0, 0, surface->w, surface->h};
|
|
|
|
const bool inbounds = SDL_PointInRect(&point, &rect);
|
|
|
|
if (!inbounds)
|
|
|
|
{
|
|
|
|
WHINE_ONCE_ARGS((
|
|
|
|
"Pixel read is not inbounds: "
|
|
|
|
"Attempted to read %i,%i in %ix%i surface",
|
|
|
|
x, y, surface->w, surface->h
|
|
|
|
));
|
|
|
|
SDL_assert(0 && "Pixel read is not inbounds!");
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
2023-01-02 01:36:43 +01:00
|
|
|
const SDL_PixelFormat* fmt = surface->format;
|
|
|
|
const int bpp = surface->format->BytesPerPixel;
|
2023-11-01 06:52:42 +01:00
|
|
|
const Uint8* pixel = (Uint8*) surface->pixels + y * surface->pitch + x * bpp;
|
|
|
|
const Uint32* pixel32 = (Uint32*) pixel;
|
2020-01-01 21:29:24 +01:00
|
|
|
|
2023-01-02 01:36:43 +01:00
|
|
|
switch (bpp)
|
2020-01-01 21:29:24 +01:00
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
case 2:
|
2023-11-01 06:52:42 +01:00
|
|
|
SDL_assert(0 && "Colors other than 24- or 32- bit unsupported!");
|
|
|
|
break;
|
|
|
|
|
2020-01-01 21:29:24 +01:00
|
|
|
case 3:
|
2023-11-01 06:52:42 +01:00
|
|
|
{
|
|
|
|
const Uint32 single = (pixel[0] << 16) | (pixel[1] << 8) | (pixel[2] << 0);
|
|
|
|
SDL_GetRGB(single, fmt, &color.r, &color.g, &color.b);
|
|
|
|
color.a = 255;
|
2023-01-02 19:44:35 +01:00
|
|
|
break;
|
2023-11-01 06:52:42 +01:00
|
|
|
}
|
2020-01-01 21:29:24 +01:00
|
|
|
|
|
|
|
case 4:
|
2023-11-01 06:52:42 +01:00
|
|
|
SDL_GetRGBA(*pixel32, fmt, &color.r, &color.g, &color.b, &color.a);
|
2023-01-02 01:36:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return color;
|
2020-01-01 21:29:24 +01:00
|
|
|
}
|
|
|
|
|
2021-01-10 18:14:37 +01:00
|
|
|
static int oldscrollamount = 0;
|
|
|
|
static int scrollamount = 0;
|
|
|
|
static bool isscrolling = 0;
|
2020-04-02 22:35:43 +02:00
|
|
|
|
Explicitly declare void for all void parameter functions (#628)
Apparently in C, if you have `void test();`, it's completely okay to do
`test(2);`. The function will take in the argument, but just discard it
and throw it away. It's like a trash can, and a rude one at that. If you
declare it like `void test(void);`, this is prevented.
This is not a problem in C++ - doing `void test();` and `test(2);` is
guaranteed to result in a compile error (this also means that right now,
at least in all `.cpp` files, nobody is ever calling a void parameter
function with arguments and having their arguments be thrown away).
However, we may not be using C++ in the future, so I just want to lay
down the precedent that if a function takes in no arguments, you must
explicitly declare it as such.
I would've added `-Wstrict-prototypes`, but it produces an annoying
warning message saying it doesn't work in C++ mode if you're compiling
in C++ mode. So it can be added later.
2021-02-25 23:23:59 +01:00
|
|
|
void UpdateFilter(void)
|
2020-05-03 05:27:47 +02:00
|
|
|
{
|
2020-04-02 22:35:43 +02:00
|
|
|
if (rand() % 4000 < 8)
|
|
|
|
{
|
|
|
|
isscrolling = true;
|
|
|
|
}
|
|
|
|
|
2020-11-08 01:21:30 +01:00
|
|
|
oldscrollamount = scrollamount;
|
2020-04-02 22:35:43 +02:00
|
|
|
if(isscrolling == true)
|
|
|
|
{
|
|
|
|
scrollamount += 20;
|
|
|
|
if(scrollamount > 240)
|
|
|
|
{
|
|
|
|
scrollamount = 0;
|
2020-11-08 01:21:30 +01:00
|
|
|
oldscrollamount = 0;
|
2020-04-02 22:35:43 +02:00
|
|
|
isscrolling = false;
|
|
|
|
}
|
|
|
|
}
|
2020-05-03 05:27:47 +02:00
|
|
|
}
|
|
|
|
|
2023-10-27 19:21:18 +02:00
|
|
|
void ApplyFilter(SDL_Surface** src, SDL_Surface** dest)
|
2020-05-03 05:27:47 +02:00
|
|
|
{
|
2023-10-27 19:21:18 +02:00
|
|
|
if (src == NULL || dest == NULL)
|
|
|
|
{
|
|
|
|
SDL_assert(0 && "NULL src or dest!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*src == NULL)
|
2023-03-04 23:02:47 +01:00
|
|
|
{
|
2023-10-27 19:21:18 +02:00
|
|
|
*src = SDL_CreateRGBSurface(0, SCREEN_WIDTH_PIXELS, SCREEN_HEIGHT_PIXELS, 32, 0, 0, 0, 0);
|
2023-03-04 23:02:47 +01:00
|
|
|
}
|
2023-10-27 19:21:18 +02:00
|
|
|
if (*dest == NULL)
|
2023-03-04 23:02:47 +01:00
|
|
|
{
|
2023-10-27 19:21:18 +02:00
|
|
|
*dest = SDL_CreateRGBSurface(0, SCREEN_WIDTH_PIXELS, SCREEN_HEIGHT_PIXELS, 32, 0, 0, 0, 0);
|
2023-03-04 23:02:47 +01:00
|
|
|
}
|
2023-10-27 19:21:18 +02:00
|
|
|
if (*src == NULL || *dest == NULL)
|
2023-01-07 19:28:07 +01:00
|
|
|
{
|
2023-10-27 19:21:18 +02:00
|
|
|
WHINE_ONCE_ARGS(("Could not create temporary surfaces: %s", SDL_GetError()));
|
2023-01-07 19:28:07 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-27 19:21:18 +02:00
|
|
|
const int result = SDL_RenderReadPixels(gameScreen.m_renderer, NULL, 0, (*src)->pixels, (*src)->pitch);
|
2023-01-07 19:28:07 +01:00
|
|
|
if (result != 0)
|
|
|
|
{
|
2023-10-27 19:21:18 +02:00
|
|
|
SDL_FreeSurface(*src);
|
2023-01-07 19:28:07 +01:00
|
|
|
WHINE_ONCE_ARGS(("Could not read pixels from renderer: %s", SDL_GetError()));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-01-02 01:36:43 +01:00
|
|
|
const int red_offset = rand() % 4;
|
2020-04-02 22:35:43 +02:00
|
|
|
|
2023-10-27 19:21:18 +02:00
|
|
|
for (int x = 0; x < (*src)->w; x++)
|
2020-04-02 22:35:43 +02:00
|
|
|
{
|
2023-10-27 19:21:18 +02:00
|
|
|
for (int y = 0; y < (*src)->h; y++)
|
2020-04-02 22:35:43 +02:00
|
|
|
{
|
2023-01-02 01:36:43 +01:00
|
|
|
const int sampley = (y + (int) graphics.lerp(oldscrollamount, scrollamount)) % 240;
|
2020-04-02 22:35:43 +02:00
|
|
|
|
2023-10-27 19:21:18 +02:00
|
|
|
const SDL_Color pixel = ReadPixel(*src, x, sampley);
|
2020-04-02 22:35:43 +02:00
|
|
|
|
2023-01-02 01:36:43 +01:00
|
|
|
Uint8 green = pixel.g;
|
|
|
|
Uint8 blue = pixel.b;
|
2020-04-02 22:35:43 +02:00
|
|
|
|
2023-10-27 19:21:18 +02:00
|
|
|
const SDL_Color pixel_offset = ReadPixel(*src, SDL_min(x + red_offset, 319), sampley);
|
2023-01-02 01:36:43 +01:00
|
|
|
Uint8 red = pixel_offset.r;
|
2020-04-02 22:35:43 +02:00
|
|
|
|
Remove `VVV_min/max` in favor of `SDL_min/max`
VVV_min/max are functions that only operate on ints, and SDL_min/max are
macros that operate on any type but double-evaluate everything.
I know I more-or-less said earlier that SDL_min/max were dumb but I've
changed my mind and think it's better to use them, taking care to make
sure you don't double-evaluate, rather than trying to generate your own
litany of functions with either your own hand-rolled generation macros,
C++ templates, C11 generics, or GCC extensions (that last one you'd
technically use in a macro but it doesn't really matter), all of which
have more downsides than just not double-evaluating.
And the upside of not double-evaluating is that you're disencouraged
from having really complicated single-line min/max expressions and
encouraged to precompute the values beforehand anyway so the final
min/max is more readable. And furthermore you'll notice when you
yourself end up doing double-evaluations anyway. I removed a couple
instances of Graphics::len() being double-evaluated in this commit (as
well as cleaned up some other min/max-using code). Although the only
downside to those double-evaluations was unnecessary computation,
rather than checking the wrong result or having multiple side effects,
thankfully, it's still good to minimize double-evaluations where
possible.
2021-12-23 01:43:31 +01:00
|
|
|
double mult;
|
2021-12-23 06:49:08 +01:00
|
|
|
int tmp; /* needed to avoid char overflow */
|
2023-01-02 01:36:43 +01:00
|
|
|
if (isscrolling && sampley > 220 && ((rand() % 10) < 4))
|
2020-04-02 22:35:43 +02:00
|
|
|
{
|
Remove `VVV_min/max` in favor of `SDL_min/max`
VVV_min/max are functions that only operate on ints, and SDL_min/max are
macros that operate on any type but double-evaluate everything.
I know I more-or-less said earlier that SDL_min/max were dumb but I've
changed my mind and think it's better to use them, taking care to make
sure you don't double-evaluate, rather than trying to generate your own
litany of functions with either your own hand-rolled generation macros,
C++ templates, C11 generics, or GCC extensions (that last one you'd
technically use in a macro but it doesn't really matter), all of which
have more downsides than just not double-evaluating.
And the upside of not double-evaluating is that you're disencouraged
from having really complicated single-line min/max expressions and
encouraged to precompute the values beforehand anyway so the final
min/max is more readable. And furthermore you'll notice when you
yourself end up doing double-evaluations anyway. I removed a couple
instances of Graphics::len() being double-evaluated in this commit (as
well as cleaned up some other min/max-using code). Although the only
downside to those double-evaluations was unnecessary computation,
rather than checking the wrong result or having multiple side effects,
thankfully, it's still good to minimize double-evaluations where
possible.
2021-12-23 01:43:31 +01:00
|
|
|
mult = 0.6;
|
2020-04-02 22:35:43 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
Remove `VVV_min/max` in favor of `SDL_min/max`
VVV_min/max are functions that only operate on ints, and SDL_min/max are
macros that operate on any type but double-evaluate everything.
I know I more-or-less said earlier that SDL_min/max were dumb but I've
changed my mind and think it's better to use them, taking care to make
sure you don't double-evaluate, rather than trying to generate your own
litany of functions with either your own hand-rolled generation macros,
C++ templates, C11 generics, or GCC extensions (that last one you'd
technically use in a macro but it doesn't really matter), all of which
have more downsides than just not double-evaluating.
And the upside of not double-evaluating is that you're disencouraged
from having really complicated single-line min/max expressions and
encouraged to precompute the values beforehand anyway so the final
min/max is more readable. And furthermore you'll notice when you
yourself end up doing double-evaluations anyway. I removed a couple
instances of Graphics::len() being double-evaluated in this commit (as
well as cleaned up some other min/max-using code). Although the only
downside to those double-evaluations was unnecessary computation,
rather than checking the wrong result or having multiple side effects,
thankfully, it's still good to minimize double-evaluations where
possible.
2021-12-23 01:43:31 +01:00
|
|
|
mult = 0.2;
|
2020-04-02 22:35:43 +02:00
|
|
|
}
|
|
|
|
|
2021-12-23 06:49:08 +01:00
|
|
|
tmp = red + fRandom() * mult * 254;
|
|
|
|
red = SDL_min(tmp, 255);
|
|
|
|
tmp = green + fRandom() * mult * 254;
|
|
|
|
green = SDL_min(tmp, 255);
|
|
|
|
tmp = blue + fRandom() * mult * 254;
|
|
|
|
blue = SDL_min(tmp, 255);
|
2020-04-02 22:35:43 +02:00
|
|
|
|
2023-01-02 01:36:43 +01:00
|
|
|
if (y % 2 == 0)
|
2020-04-02 22:35:43 +02:00
|
|
|
{
|
2023-01-02 01:36:43 +01:00
|
|
|
red = (Uint8) (red / 1.2f);
|
|
|
|
green = (Uint8) (green / 1.2f);
|
|
|
|
blue = (Uint8) (blue / 1.2f);
|
2020-04-02 22:35:43 +02:00
|
|
|
}
|
|
|
|
|
2023-01-02 01:36:43 +01:00
|
|
|
int distX = (int) ((SDL_abs(160.0f - x) / 160.0f) * 16);
|
|
|
|
int distY = (int) ((SDL_abs(120.0f - y) / 120.0f) * 32);
|
2020-04-02 22:35:43 +02:00
|
|
|
|
2023-01-02 01:36:43 +01:00
|
|
|
red = SDL_max(red - (distX + distY), 0);
|
|
|
|
green = SDL_max(green - (distX + distY), 0);
|
|
|
|
blue = SDL_max(blue - (distX + distY), 0);
|
2020-04-02 22:35:43 +02:00
|
|
|
|
2023-01-02 01:36:43 +01:00
|
|
|
const SDL_Color color = {red, green, blue, pixel.a};
|
2023-10-27 19:21:18 +02:00
|
|
|
DrawPixel(*dest, x, y, color);
|
2020-04-02 22:35:43 +02:00
|
|
|
}
|
|
|
|
}
|
2023-01-02 01:36:43 +01:00
|
|
|
|
2023-10-27 19:21:18 +02:00
|
|
|
SDL_UpdateTexture(graphics.gameTexture, NULL, (*dest)->pixels, (*dest)->pitch);
|
2020-01-01 21:29:24 +01:00
|
|
|
}
|
2024-01-09 20:29:50 +01:00
|
|
|
|
|
|
|
bool TakeScreenshot(SDL_Surface** surface)
|
|
|
|
{
|
|
|
|
if (surface == NULL)
|
|
|
|
{
|
|
|
|
SDL_assert(0 && "surface is NULL!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
|
|
|
int result = graphics.query_texture(
|
|
|
|
graphics.gameTexture, NULL, NULL, &width, &height
|
|
|
|
);
|
|
|
|
if (result != 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*surface == NULL)
|
|
|
|
{
|
|
|
|
*surface = SDL_CreateRGBSurface(0, width, height, 24, 0, 0, 0, 0);
|
|
|
|
if (*surface == NULL)
|
|
|
|
{
|
|
|
|
WHINE_ONCE_ARGS(
|
|
|
|
("Could not create temporary surface: %s", SDL_GetError())
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((*surface)->w != width || (*surface)->h != height)
|
|
|
|
{
|
|
|
|
SDL_assert(0 && "Width and height of surface and texture mismatch!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = graphics.set_render_target(graphics.gameTexture);
|
|
|
|
if (result != 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = SDL_RenderReadPixels(
|
|
|
|
gameScreen.m_renderer, NULL, SDL_PIXELFORMAT_RGB24,
|
|
|
|
(*surface)->pixels, (*surface)->pitch
|
|
|
|
);
|
|
|
|
if (result != 0)
|
|
|
|
{
|
|
|
|
WHINE_ONCE_ARGS(
|
|
|
|
("Could not read pixels from renderer: %s", SDL_GetError())
|
|
|
|
);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-11-01 06:52:42 +01:00
|
|
|
/* Need to manually vertically reverse pixels in Flip Mode. */
|
|
|
|
if (graphics.flipmode)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < (*surface)->w; x++)
|
|
|
|
{
|
|
|
|
for (int y = 0; y < (*surface)->h / 2; y++)
|
|
|
|
{
|
|
|
|
const SDL_Color upper = ReadPixel(*surface, x, y);
|
|
|
|
const SDL_Color lower = ReadPixel(*surface, x, (*surface)->h - 1 - y);
|
|
|
|
DrawPixel(*surface, x, y, lower);
|
|
|
|
DrawPixel(*surface, x, (*surface)->h - 1 - y, upper);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-09 20:29:50 +01:00
|
|
|
return true;
|
|
|
|
}
|