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