1#ifndef RAYLIB_CPP_INCLUDE_TEXTURE_HPP_
2#define RAYLIB_CPP_INCLUDE_TEXTURE_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);
212 inline Texture&
Draw(
int posX = 0,
int posY = 0, ::Color tint = {255, 255, 255, 255}) {
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);
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);
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;
Image type, bpp always RGBA (32bit)
Exception used for most raylib-related exceptions.
Texture & Draw(int posX=0, int posY=0, ::Color tint={255, 255, 255, 255})
Draw a Texture2D.
Texture & operator=(Texture &&other) noexcept
Texture(unsigned int id=0, int width=0, int height=0, int mipmaps=0, int format=0)
Default constructor to create an empty Texture object.
void Unload()
Unload texture from GPU memory (VRAM)
bool Load(const std::string &fileName)
Load texture from file into GPU memory (VRAM)
Texture & Update(::Rectangle rec, const void *pixels)
Update GPU texture rectangle with new data.
Texture(const ::Texture &texture)
Creates a texture object based on the given Texture struct data.
Texture & Draw(::Vector2 position, ::Color tint={255, 255, 255, 255})
Texture & DrawPoly(Vector2 center, Vector2 *points, Vector2 *texcoords, int pointsCount, Color tint={255, 255, 255, 255})
Texture & Draw(::Rectangle sourceRec, ::Vector2 position={0, 0}, ::Color tint={255, 255, 255, 255})
Texture & SetShaderValue(const ::Shader &shader, int locIndex)
Set shader uniform value for texture (sampler2d)
inline ::Vector2 GetSize() const
Retrieve the width and height of the texture.
inline ::Image GetData() const
Get pixel data from GPU texture and return an Image.
Texture(const ::Image &image)
Creates a texture from the given Image.
bool Load(const ::Image &image, int layoutType)
Load cubemap from image, multiple image cubemap layouts supported.
Texture(const Texture &)=delete
Texture & DrawTiled(::Rectangle sourceRec, ::Rectangle destRec, ::Vector2 origin={0, 0}, float rotation=0, float scale=1, Color tint={255, 255, 255, 255})
bool IsReady() const
Determines whether or not the Texture has been loaded and is ready.
Texture & Draw(::NPatchInfo nPatchInfo, ::Rectangle destRec, ::Vector2 origin={0, 0}, float rotation=0, ::Color tint={255, 255, 255, 255})
Texture & operator=(const Texture &)=delete
Texture & SetMaterial(const ::Material &material, int mapType=MATERIAL_MAP_NORMAL)
Texture & GenMipmaps()
Generate GPU mipmaps for a texture.
Texture(const ::Image &image, int layout)
Load cubemap from image, multiple image cubemap layouts supported.
Texture & SetMaterial(::Material *material, int mapType=MATERIAL_MAP_NORMAL)
Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...)
Texture & SetWrap(int wrapMode)
Set texture wrapping mode.
Texture(const std::string &fileName)
Load texture from file into GPU memory (VRAM)
Texture & Draw(::Rectangle sourceRec, ::Rectangle destRec, ::Vector2 origin={0, 0}, float rotation=0, ::Color tint={255, 255, 255, 255})
Texture & SetShapes(const ::Rectangle &source)
Set texture and rectangle to be used on shapes drawing.
Texture & Update(const void *pixels)
Update GPU texture with new data.
Texture & SetFilter(int filterMode)
Set texture scaling filter mode.
Texture & Draw(::Vector2 tiling, ::Vector2 offset, ::Rectangle quad, ::Color tint={255, 255, 255, 255})
Texture & Draw(::Vector2 position, float rotation, float scale=1.0f, ::Color tint={255, 255, 255, 255})
Texture & Draw(::Vector3 position, float width, float height, float length, ::Color tint={255, 255, 255, 255})
bool Load(const ::Image &image)
Load texture from image data.
All raylib-cpp classes and functions appear in the raylib namespace.