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 "flint/core/api.h"
5
6#include <SDL3/SDL_render.h>
7
8namespace Flint {
13 class Texture {
14 public:
15 Texture() = default;
16
17 virtual ~Texture() {
18 free();
19 }
20
21 Texture(const Texture &) = delete;
22
23 Texture &operator=(const Texture &) = delete;
24
26 FLINT_API Texture(Texture &&other) noexcept;
27
29 FLINT_API Texture &operator=(Texture &&other) noexcept;
30
42 FLINT_API bool loadFromMemory(SDL_Renderer *renderer, const void *data, size_t size);
43
44 FLINT_API void free();
45
47 FLINT_API SDL_Texture *getSDLTexture() const;
48
50 FLINT_API int getWidth() const;
51
53 FLINT_API int getHeight() const;
54
65 FLINT_API bool createRenderTarget(SDL_Renderer *renderer, int width, int height);
66
67 FLINT_API static Texture fromRenderer(SDL_Renderer *renderer, int width, int height);
68
69 private:
70 SDL_Renderer *m_renderer = nullptr;
71 SDL_Texture *m_texture = nullptr;
72 int m_width = 0, m_height = 0;
73 };
74}
Owns an SDL_Texture loaded from memory or created as a render target.
Definition texture.h:13
FLINT_API int getHeight() const
Return the texture height in pixels.
FLINT_API Texture & operator=(Texture &&other) noexcept
Move-assignment; releases current texture then steals from the other.
FLINT_API SDL_Texture * getSDLTexture() const
Return the underlying SDL_Texture handle.
FLINT_API Texture(Texture &&other) noexcept
Move constructor; transfers SDL_Texture ownership from the other.
FLINT_API bool createRenderTarget(SDL_Renderer *renderer, int width, int height)
Create a render-target texture of the given dimensions.
FLINT_API bool loadFromMemory(SDL_Renderer *renderer, const void *data, size_t size)
Load a texture from an in-memory image file.
FLINT_API int getWidth() const
Return the texture width in pixels.