raylib-cpp
C++ object-oriented wrapper library for raylib.
RenderTexture.hpp
1#ifndef RAYLIB_CPP_INCLUDE_RENDERTEXTURE_HPP_
2#define RAYLIB_CPP_INCLUDE_RENDERTEXTURE_HPP_
3
4#include "./raylib.hpp"
5#include "./raylib-cpp-utils.hpp"
6#include "./RaylibException.hpp"
7
8namespace raylib {
12class RenderTexture : public ::RenderTexture {
13 public:
18 id = 0;
19 }
20
21 RenderTexture(const ::RenderTexture& renderTexture) {
22 set(renderTexture);
23 }
24
25 RenderTexture(unsigned int id, ::Texture texture, ::Texture depth) : ::RenderTexture{id, texture, depth} {}
26
27 RenderTexture(int width, int height) {
28 if (!Load(width, height)) {
29 throw RaylibException("Failed to create RenderTexture");
30 }
31 }
32
33 RenderTexture(const RenderTexture&) = delete;
34
36 set(other);
37
38 other.id = 0;
39 other.texture = {};
40 other.depth = {};
41 }
42
43 GETTERSETTER(unsigned int, Id, id)
44 GETTERSETTER(::Texture2D, Texture, texture)
45 GETTERSETTER(::Texture2D, Depth, depth)
46
47 RenderTexture& operator=(const ::RenderTexture& texture) {
48 set(texture);
49 return *this;
50 }
51
53
55 if (this == &other) {
56 return *this;
57 }
58
59 Unload();
60 set(other);
61
62 other.id = 0;
63 other.texture = {};
64 other.depth = {};
65
66 return *this;
67 }
68
70 Unload();
71 }
72
73 inline void Unload() {
74 UnloadRenderTexture(*this);
75 }
76
81 ::BeginTextureMode(*this);
82 return *this;
83 }
84
89 ::EndTextureMode();
90 return *this;
91 }
92
96 bool Load(int width, int height) {
97 set(::LoadRenderTexture(width, height));
98 return IsReady();
99 }
100
104 bool IsReady() const {
105 return id != 0;
106 }
107
108 private:
109 inline void set(const ::RenderTexture& renderTexture) {
110 id = renderTexture.id;
111 texture = renderTexture.texture;
112 depth = renderTexture.depth;
113 }
114};
116} // namespace raylib
117
118#endif // RAYLIB_CPP_INCLUDE_RENDERTEXTURE_HPP_
Exception used for most raylib-related exceptions.
RenderTexture type, for texture rendering.
RenderTexture & operator=(const RenderTexture &)=delete
RenderTexture(unsigned int id, ::Texture texture, ::Texture depth)
RenderTexture(RenderTexture &&other)
bool IsReady() const
Retrieves whether or not the render texture is ready.
RenderTexture & BeginMode()
Initializes render texture for drawing.
RenderTexture & EndMode()
Ends drawing to render texture.
RenderTexture(const ::RenderTexture &renderTexture)
bool Load(int width, int height)
Loads a render texture at the given width and height.
RenderTexture & operator=(RenderTexture &&other) noexcept
RenderTexture()
Default constructor to build an empty RenderTexture.
RenderTexture(const RenderTexture &)=delete
RenderTexture(int width, int height)
Texture type.
Definition: Texture.hpp:16
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:8
RenderTexture RenderTexture2D