1 #ifndef RAYLIB_CPP_INCLUDE_TEXTURE_HPP_
2 #define RAYLIB_CPP_INCLUDE_TEXTURE_HPP_
6 #include "./raylib.hpp"
7 #include "./raylib-cpp-utils.hpp"
8 #include "./Vector2.hpp"
9 #include "./Material.hpp"
10 #include "./RaylibException.hpp"
25 int format = 0) : ::
Texture{id, width, height, mipmaps, format} {
54 Texture(const ::Image& image,
int layout) {
55 if (!
Load(image, layout)) {
66 if (!
Load(fileName)) {
67 throw RaylibException(TextFormat(
"Failed to load Texture from file: %s", fileName.c_str()));
87 GETTERSETTER(
unsigned int, Id,
id)
88 GETTERSETTER(
int, Width, width)
89 GETTERSETTER(
int, Height, height)
90 GETTERSETTER(
int, Mipmaps, mipmaps)
91 GETTERSETTER(
int, Format, format)
101 if (
this == &other) {
121 return {
static_cast<float>(width),
static_cast<float>(height)};
127 bool Load(const ::Image& image) {
128 set(::LoadTextureFromImage(image));
135 bool Load(const ::Image& image,
int layoutType) {
136 set(::LoadTextureCubemap(image, layoutType));
143 bool Load(
const std::string& fileName) {
144 set(::LoadTexture(fileName.c_str()));
152 ::UnloadTexture(*
this);
159 ::UpdateTexture(*
this, pixels);
167 UpdateTextureRec(*
this, rec, pixels);
175 return ::LoadImageFromTexture(*
this);
189 ::GenTextureMipmaps(
this);
197 ::SetTextureFilter(*
this, filterMode);
205 ::SetTextureWrap(*
this, wrapMode);
213 ::DrawTexture(*
this, posX, posY, tint);
217 inline Texture&
Draw(::Vector2 position, ::Color tint = {255, 255, 255, 255}) {
218 ::DrawTextureV(*
this, position, tint);
222 inline Texture&
Draw(::Vector2 position,
float rotation,
float scale = 1.0f,
223 ::Color tint = {255, 255, 255, 255}) {
224 ::DrawTextureEx(*
this, position, rotation, scale, tint);
228 inline Texture&
Draw(::Rectangle sourceRec, ::Vector2 position = {0, 0},
229 ::Color tint = {255, 255, 255, 255}) {
230 ::DrawTextureRec(*
this, sourceRec, position, tint);
234 inline Texture&
Draw(::Vector2 tiling, ::Vector2 offset, ::Rectangle quad,
235 ::Color tint = {255, 255, 255, 255}) {
236 ::DrawTextureQuad(*
this, tiling, offset, quad, tint);
240 inline Texture&
Draw(::Rectangle sourceRec, ::Rectangle destRec, ::Vector2 origin = {0, 0},
241 float rotation = 0, ::Color tint = {255, 255, 255, 255}) {
242 ::DrawTexturePro(*
this, sourceRec, destRec, origin, rotation, tint);
246 inline Texture&
Draw(::NPatchInfo nPatchInfo, ::Rectangle destRec, ::Vector2 origin = {0, 0},
247 float rotation = 0, ::Color tint = {255, 255, 255, 255}) {
248 ::DrawTextureNPatch(*
this, nPatchInfo, destRec, origin, rotation, tint);
252 inline Texture&
Draw(::Vector3 position,
float width,
float height,
float length,
253 ::Color tint = {255, 255, 255, 255}) {
254 ::DrawCubeTexture(*
this, position, width, height, length, tint);
258 inline Texture& DrawTiled(::Rectangle sourceRec, ::Rectangle destRec, ::Vector2 origin = {0, 0},
259 float rotation = 0,
float scale = 1, Color tint = {255, 255, 255, 255}) {
260 ::DrawTextureTiled(*
this, sourceRec, destRec, origin, rotation, scale, tint);
264 inline Texture& DrawPoly(Vector2 center, Vector2 *points,
265 Vector2 *texcoords,
int pointsCount,
266 Color tint = {255, 255, 255, 255}) {
267 ::DrawTexturePoly(*
this, center, points, texcoords, pointsCount, tint);
275 ::SetMaterialTexture(material, mapType, *
this);
279 inline Texture&
SetMaterial(const ::Material& material,
int mapType = MATERIAL_MAP_NORMAL) {
280 ::SetMaterialTexture((::
Material*)(&material), mapType, *
this);
288 ::SetShapesTexture(*
this, source);
296 ::SetShaderValueTexture(shader, locIndex, *
this);
310 inline void set(const ::Texture& texture) {
312 width = texture.width;
313 height = texture.height;
314 mipmaps = texture.mipmaps;
315 format = texture.format;
320 typedef Texture Texture2D;
321 typedef Texture TextureCubemap;
325 #endif // RAYLIB_CPP_INCLUDE_TEXTURE_HPP_