raylib-cpp
C++ object-oriented wrapper library for raylib.
Texture.hpp
1 #ifndef RAYLIB_CPP_Texture_HPP_
2 #define RAYLIB_CPP_Texture_HPP_
3 
4 #include <string>
5 
6 #ifdef __cplusplus
7 extern "C"{
8 #endif
9 #include "raylib.h"
10 #ifdef __cplusplus
11 }
12 #endif
13 
14 #include "./raylib-cpp-utils.hpp"
15 #include "./Vector2.hpp"
16 #include "./Material.hpp"
17 
18 namespace raylib {
19  class Texture : public ::Texture {
20  public:
21  Texture() {
22  set(::GetTextureDefault());
23  };
24 
25  Texture(::Image& image) {
26  LoadFromImage(image);
27  }
28 
29  Texture(const std::string& fileName) {
30  Load(fileName);
31  }
32 
34  Unload();
35  };
36 
37  GETTERSETTER(unsigned int,Id,id)
38  GETTERSETTER(int,Width,width)
39  GETTERSETTER(int,Height,height)
40  GETTERSETTER(int,Mipmaps,mipmaps)
41  GETTERSETTER(int,Format,format)
42 
43  Texture& operator=(const ::Texture& texture) {
44  set(texture);
45  return *this;
46  }
47 
48  Texture& operator=(const Texture& texture) {
49  set(texture);
50  return *this;
51  }
52 
53  void LoadFromImage(::Image& image) {
54  set(::LoadTextureFromImage(image));
55  }
56 
57  void LoadTextureCubemap(::Image& image, int layoutType) {
58  set(::LoadTextureCubemap(image, layoutType));
59  }
60 
61  void Load(const std::string& fileName) {
62  set(::LoadTexture(fileName.c_str()));
63  }
64 
65  inline void Unload() {
66  ::UnloadTexture(*this);
67  }
68 
69  inline Texture& Update(const void *pixels) {
70  ::UpdateTexture(*this, pixels);
71  return *this;
72  }
73 
74  inline Texture& UpdateRec(Rectangle rec, const void *pixels) {
75  UpdateTextureRec(*this, rec, pixels);
76  return *this;
77  }
78 
79  inline Image GetTextureData() const {
80  return ::GetTextureData(*this);
81  }
82  inline operator raylib::Image() {
83  return GetTextureData();
84  }
85 
86  inline Texture& GenMipmaps() {
87  ::GenTextureMipmaps(this);
88  return *this;
89  }
90 
91  inline Texture& SetFilter(int filterMode) {
92  ::SetTextureFilter(*this, filterMode);
93  return *this;
94  }
95 
96  inline Texture& SetWrap(int wrapMode) {
97  ::SetTextureWrap(*this, wrapMode);
98  return *this;
99  }
100 
101  inline Texture& Draw(int posX, int posY, ::Color tint = WHITE) {
102  ::DrawTexture(*this, posX, posY, tint);
103  return *this;
104  }
105 
106  inline Texture& Draw(::Vector2 position, ::Color tint = WHITE) {
107  ::DrawTextureV(*this, position, tint);
108  return *this;
109  }
110  inline Texture& Draw(::Vector2 position, float rotation, float scale = 1.0f, ::Color tint = WHITE) {
111  ::DrawTextureEx(*this, position, rotation, scale, tint);
112  return *this;
113  }
114 
115  inline Texture& Draw(::Rectangle sourceRec, ::Vector2 position, ::Color tint = WHITE) {
116  ::DrawTextureRec(*this, sourceRec, position, tint);
117  return *this;
118  }
119  inline Texture& Draw(::Vector2 tiling, ::Vector2 offset, ::Rectangle quad, ::Color tint = WHITE) {
120  ::DrawTextureQuad(*this, tiling, offset, quad, tint);
121  return *this;
122  }
123  inline Texture& Draw(::Rectangle sourceRec, ::Rectangle destRec, ::Vector2 origin, float rotation = 0, ::Color tint = WHITE) {
124  ::DrawTexturePro(*this, sourceRec, destRec, origin, rotation, tint);
125  return *this;
126  }
127  inline Texture& Draw(::NPatchInfo nPatchInfo, ::Rectangle destRec, ::Vector2 origin, float rotation = 0, ::Color tint = WHITE) {
128  ::DrawTextureNPatch(*this, nPatchInfo, destRec, origin, rotation, tint);
129  return *this;
130  }
131 
132  inline Texture& Draw(::Vector3 position, float width, float height, float length, ::Color color = WHITE) {
133  ::DrawCubeTexture(*this, position, width, height, length, color);
134  return *this;
135  }
136 
137  inline Texture& DrawTiled(Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, float scale, Color tint = WHITE) {
138  ::DrawTextureTiled(*this, sourceRec, destRec, origin, rotation, scale, tint);
139  return *this;
140  }
141 
142  inline Texture& SetMaterialTexture(Material *material, int mapType) {
143  ::SetMaterialTexture(material, mapType, *this);
144  return *this;
145  }
146 
147  static int GetPixelDataSize(int width, int height, int format) {
148  return ::GetPixelDataSize(width, height, format);
149  }
150 
151  protected:
152  inline void set(::Texture texture) {
153  id = texture.id;
154  width = texture.width;
155  height = texture.height;
156  mipmaps = texture.mipmaps;
157  format = texture.format;
158  }
159  };
160 
161  // Create the Texture aliases.
164 }
165 
166 #endif
raylib::Texture::GetPixelDataSize
static int GetPixelDataSize(int width, int height, int format)
Definition: Texture.hpp:147
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:14
raylib::Texture::SetWrap
Texture & SetWrap(int wrapMode)
Definition: Texture.hpp:96
raylib::Texture::operator=
Texture & operator=(const Texture &texture)
Definition: Texture.hpp:48
raylib::Texture::LoadTextureCubemap
void LoadTextureCubemap(::Image &image, int layoutType)
Definition: Texture.hpp:57
raylib::Texture::Draw
Texture & Draw(::Vector2 tiling, ::Vector2 offset, ::Rectangle quad, ::Color tint=WHITE)
Definition: Texture.hpp:119
raylib::Texture::Draw
Texture & Draw(::NPatchInfo nPatchInfo, ::Rectangle destRec, ::Vector2 origin, float rotation=0, ::Color tint=WHITE)
Definition: Texture.hpp:127
raylib::Texture::UpdateRec
Texture & UpdateRec(Rectangle rec, const void *pixels)
Definition: Texture.hpp:74
raylib::Texture::set
void set(::Texture texture)
Definition: Texture.hpp:152
raylib::Texture::DrawTiled
Texture & DrawTiled(Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, float scale, Color tint=WHITE)
Definition: Texture.hpp:137
raylib::Image
Definition: Image.hpp:16
raylib::Vector3
Definition: Vector3.hpp:21
raylib::Texture::SetMaterialTexture
Texture & SetMaterialTexture(Material *material, int mapType)
Definition: Texture.hpp:142
raylib::Texture::Draw
Texture & Draw(::Vector3 position, float width, float height, float length, ::Color color=WHITE)
Definition: Texture.hpp:132
raylib::Texture::Load
void Load(const std::string &fileName)
Definition: Texture.hpp:61
raylib::Rectangle
Definition: Rectangle.hpp:16
raylib::Vector2
Definition: Vector2.hpp:22
raylib::Texture::Texture
Texture(const std::string &fileName)
Definition: Texture.hpp:29
raylib::Texture::SetFilter
Texture & SetFilter(int filterMode)
Definition: Texture.hpp:91
raylib::Color
Definition: Color.hpp:18
raylib::Texture::~Texture
~Texture()
Definition: Texture.hpp:33
raylib::Texture::Draw
Texture & Draw(::Rectangle sourceRec, ::Rectangle destRec, ::Vector2 origin, float rotation=0, ::Color tint=WHITE)
Definition: Texture.hpp:123
raylib::Texture::Draw
Texture & Draw(::Vector2 position, ::Color tint=WHITE)
Definition: Texture.hpp:106
raylib::Texture2D
Texture Texture2D
Definition: Texture.hpp:162
raylib::Texture::Texture
Texture(::Image &image)
Definition: Texture.hpp:25
raylib::Texture::LoadFromImage
void LoadFromImage(::Image &image)
Definition: Texture.hpp:53
raylib::Texture
Definition: Texture.hpp:19
raylib::Texture::Draw
Texture & Draw(::Vector2 position, float rotation, float scale=1.0f, ::Color tint=WHITE)
Definition: Texture.hpp:110
raylib::Texture::Unload
void Unload()
Definition: Texture.hpp:65
raylib::TextureCubemap
Texture TextureCubemap
Definition: Texture.hpp:163
raylib::Texture::GenMipmaps
Texture & GenMipmaps()
Definition: Texture.hpp:86
raylib::Material
Definition: Material.hpp:15
raylib::Texture::Texture
Texture()
Definition: Texture.hpp:21
raylib::Texture::Update
Texture & Update(const void *pixels)
Definition: Texture.hpp:69
raylib::Texture::Draw
Texture & Draw(::Rectangle sourceRec, ::Vector2 position, ::Color tint=WHITE)
Definition: Texture.hpp:115
raylib::Texture::GetTextureData
Image GetTextureData() const
Definition: Texture.hpp:79
raylib::Texture::Draw
Texture & Draw(int posX, int posY, ::Color tint=WHITE)
Definition: Texture.hpp:101