20 if (renderer !=
nullptr && surface !=
nullptr) {
29 SDL_SetSurfaceRLE(surface, 0);
31 SDL_Surface* workingSurface = surface;
33 if (surface->format->BitsPerPixel != 32) {
34 workingSurface = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA8888, 0);
35 if (workingSurface !=
nullptr) {
37 SDL_FreeSurface(surface);
39 surface = workingSurface;
43 if (SDL_LockSurface(surface) == 0) {
44 Uint32* pixels =
static_cast<Uint32*
>(surface->pixels);
45 int const pixelCount = surface->w * surface->h;
47 SDL_PixelFormat
const * fmt = surface->format;
48 Uint32
const amask = fmt->Amask;
50 for (
int i = 0; i < pixelCount; ++i) {
53 SDL_GetRGBA(pixels[i], fmt, &r, &g, &b, &a);
55 if (r == 255 && g == 0 && b == 255) {
59 SDL_UnlockSurface(surface);
62 SDL_SetColorKey(surface, 0, 0);
64 mTexture = SDL_CreateTextureFromSurface(renderer, surface);
66 throwException(std::string(
"Failed to create texture: ") + SDL_GetError());
69 SDL_SetTextureBlendMode(
mTexture, SDL_BLENDMODE_BLEND);
70#if SDL_VERSION_ATLEAST(2, 0, 12)
71 SDL_SetTextureScaleMode(
mTexture, SDL_ScaleModeNearest);
76 SDL_QueryTexture(
mTexture,
nullptr,
nullptr, &w, &h);
77 mTransientSurface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 32, SDL_PIXELFORMAT_RGBA8888);
79 throwException(std::string(
"Failed to create transient surface: ") + SDL_GetError());
81 SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA8888, 0);
83 SDL_Surface* converted = SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA8888, 0);
84 if (converted !=
nullptr) {
86 SDL_FreeSurface(converted);
93 SDL_FreeSurface(surface);
95 }
else if (autoFree && surface !=
nullptr) {
96 SDL_FreeSurface(surface);
void SDLputPixel(SDL_Surface *surface, int x, int y, Color const &color)
Puts a pixel on an SDL_Surface.