69 void loadTexture(
mxWindow *window,
const std::string &filename,
int &w,
int &h,
bool color, SDL_Color key);
83 std::optional<SDL_Texture *>
handle()
const {
98 throw Exception(
"unwrap: Invalid texture");
119 if (SDL_LockSurface(surface) != 0) {
122 Uint8* pixels = (Uint8*)surface->pixels;
123 int pitch = surface->pitch;
124 std::vector<Uint8> tempRow(pitch);
125 for (
int y = 0; y < surface->h / 2; ++y) {
126 Uint8* row1 = pixels + y * pitch;
127 Uint8* row2 = pixels + (surface->h - y - 1) * pitch;
128 memcpy(tempRow.data(), row1, pitch);
129 memcpy(row1, row2, pitch);
130 memcpy(row2, tempRow.data(), pitch);
132 SDL_UnlockSurface(surface);
146 bool saveBMP(SDL_Texture *
texture, SDL_Renderer *renderer,
const std::string &name);
General-purpose exception class for the mx library.
int width_
Cached texture width.
static SDL_Surface * flipSurface(SDL_Surface *surface)
Flip an SDL_Surface vertically (in-place).
~Texture()
Destructor — destroys the SDL_Texture if held.
SDL_Texture * texture
Managed SDL texture handle.
int height_
Cached texture height.
bool saveTexture(mxWindow *window, const std::string &filename)
Save the texture to a file.
Texture()=default
Default constructor — no texture loaded.
int imageType(const std::string &type)
Texture(const Texture &tex)=delete
Texture & operator=(const Texture &tex)=delete
SDL_Texture * unwrap() const
Unwrap the SDL_Texture pointer, throwing on null.
void createTexture(mxWindow *window, int width, int height)
Create an empty (blank) texture of the given dimensions.
Wrapper< SDL_Texture * > wrapper() const
Return a Wrapper around the SDL_Texture handle.
bool saveBMP(SDL_Texture *texture, SDL_Renderer *renderer, const std::string &name)
std::optional< SDL_Texture * > handle() const
Return the SDL_Texture as an optional.
void loadTexture(mxWindow *window, const std::string &filename)
Load a texture from an image file.
A nullable smart wrapper around a raw pointer.
Main SDL2 application window.
Tee stream utilities that duplicate output to two sinks simultaneously.
Type-safe nullable pointer wrapper inspired by Rust's Option<T>.