Flint Engine
Modular C++20 2D game engine powered by SDL3
Loading...
Searching...
No Matches
texture.h
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2025-2026 Manuel Osorio
3#pragma once
4#include <SDL3/SDL_render.h>
5
6namespace Flint {
11 class Texture {
12 public:
13 Texture() = default;
14
15 virtual ~Texture() {
16 free();
17 }
18
19 Texture(const Texture &) = delete;
20
21 Texture &operator=(const Texture &) = delete;
22
24 Texture(Texture &&other) noexcept;
25
27 Texture &operator=(Texture &&other) noexcept;
28
40 bool loadFromMemory(SDL_Renderer *renderer, const void *data, size_t size);
41
42 void free();
43
45 SDL_Texture *getSDLTexture() const;
46
48 int getWidth() const;
49
51 int getHeight() const;
52
63 bool createRenderTarget(SDL_Renderer *renderer, int width, int height);
64
65 static Texture fromRenderer(SDL_Renderer *renderer, int width, int height);
66
67 private:
68 SDL_Renderer *m_renderer = nullptr;
69 SDL_Texture *m_texture = nullptr;
70 int m_width = 0, m_height = 0;
71 };
72}
bool createRenderTarget(SDL_Renderer *renderer, int width, int height)
Create a render-target texture of the given dimensions.
bool loadFromMemory(SDL_Renderer *renderer, const void *data, size_t size)
Load a texture from an in-memory image file.
Owns an SDL_Texture loaded from memory or created as a render target.
Definition texture.h:11
Texture(Texture &&other) noexcept
Move constructor; transfers SDL_Texture ownership from the other.
Texture & operator=(Texture &&other) noexcept
Move-assignment; releases current texture then steals from the other.
int getWidth() const
Return the texture width in pixels.
int getHeight() const
Return the texture height in pixels.
SDL_Texture * getSDLTexture() const
Return the underlying SDL_Texture handle.