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"
28 Texture(
unsigned int id,
int width,
int height,
29 int mipmaps = 1,
int format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
30 : ::
Texture{id, width, height, mipmaps, format} {
57 Texture(const ::Image& image,
int layout) {
86 GETTERSETTER(
unsigned int, Id,
id)
87 GETTERSETTER(
int, Width, width)
88 GETTERSETTER(
int, Height, height)
89 GETTERSETTER(
int, Mipmaps, mipmaps)
90 GETTERSETTER(
int, Format, format)
100 if (
this == &other) {
120 return {
static_cast<float>(width),
static_cast<float>(height)};
126 void Load(const ::Image& image) {
127 set(::LoadTextureFromImage(image));
136 void Load(const ::Image& image,
int layoutType) {
137 set(::LoadTextureCubemap(image, layoutType));
146 void Load(
const std::string& fileName) {
147 set(::LoadTexture(fileName.c_str()));
149 throw RaylibException(
"Failed to load Texture from file: " + fileName);
157 ::UnloadTexture(*
this);
164 ::UpdateTexture(*
this, pixels);
172 UpdateTextureRec(*
this, rec, pixels);
180 return ::LoadImageFromTexture(*
this);
194 ::GenTextureMipmaps(
this);
202 ::SetTextureFilter(*
this, filterMode);
210 ::SetTextureWrap(*
this, wrapMode);
218 ::DrawTexture(*
this, posX, posY, tint);
222 inline Texture&
Draw(::Vector2 position, ::Color tint = {255, 255, 255, 255}) {
223 ::DrawTextureV(*
this, position, tint);
227 inline Texture&
Draw(::Vector2 position,
float rotation,
float scale = 1.0f,
228 ::Color tint = {255, 255, 255, 255}) {
229 ::DrawTextureEx(*
this, position, rotation, scale, tint);
233 inline Texture&
Draw(::Rectangle sourceRec, ::Vector2 position = {0, 0},
234 ::Color tint = {255, 255, 255, 255}) {
235 ::DrawTextureRec(*
this, sourceRec, position, tint);
239 inline Texture&
Draw(::Vector2 tiling, ::Vector2 offset, ::Rectangle quad,
240 ::Color tint = {255, 255, 255, 255}) {
241 ::DrawTextureQuad(*
this, tiling, offset, quad, tint);
245 inline Texture&
Draw(::Rectangle sourceRec, ::Rectangle destRec, ::Vector2 origin = {0, 0},
246 float rotation = 0, ::Color tint = {255, 255, 255, 255}) {
247 ::DrawTexturePro(*
this, sourceRec, destRec, origin, rotation, tint);
251 inline Texture&
Draw(::NPatchInfo nPatchInfo, ::Rectangle destRec, ::Vector2 origin = {0, 0},
252 float rotation = 0, ::Color tint = {255, 255, 255, 255}) {
253 ::DrawTextureNPatch(*
this, nPatchInfo, destRec, origin, rotation, tint);
257 inline Texture&
Draw(::Vector3 position,
float width,
float height,
float length,
258 ::Color tint = {255, 255, 255, 255}) {
259 ::DrawCubeTexture(*
this, position, width, height, length, tint);
263 inline Texture& DrawTiled(::Rectangle sourceRec, ::Rectangle destRec, ::Vector2 origin = {0, 0},
264 float rotation = 0,
float scale = 1, Color tint = {255, 255, 255, 255}) {
265 ::DrawTextureTiled(*
this, sourceRec, destRec, origin, rotation, scale, tint);
269 inline Texture& DrawPoly(Vector2 center, Vector2 *points,
270 Vector2 *texcoords,
int pointsCount,
271 Color tint = {255, 255, 255, 255}) {
272 ::DrawTexturePoly(*
this, center, points, texcoords, pointsCount, tint);
280 ::SetMaterialTexture(material, mapType, *
this);
284 inline Texture&
SetMaterial(const ::Material& material,
int mapType = MATERIAL_MAP_NORMAL) {
285 ::SetMaterialTexture((::
Material*)(&material), mapType, *
this);
293 ::SetShapesTexture(*
this, source);
301 ::SetShaderValueTexture(shader, locIndex, *
this);
315 void set(const ::Texture& texture) {
317 width = texture.width;
318 height = texture.height;
319 mipmaps = texture.mipmaps;
320 format = texture.format;
325 typedef Texture Texture2D;
326 typedef Texture TextureCubemap;
Image type, bpp always RGBA (32bit)
Exception used for most raylib-related exceptions.
void Unload()
Unload texture from GPU memory (VRAM)
void Load(const ::Image &image, int layoutType)
Load cubemap from image, multiple image cubemap layouts supported.
Texture(const ::Texture &texture)
Creates a texture object based on the given Texture struct data.
Texture & SetWrap(int wrapMode)
Set texture wrapping mode.
Texture(unsigned int id, int width, int height, int mipmaps=1, int format=PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
Move/Create a texture structure manually.
void Load(const ::Image &image)
Load texture from image data.
Texture & SetFilter(int filterMode)
Set texture scaling filter mode.
Texture & GenMipmaps()
Generate GPU mipmaps for a texture.
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.
Texture & Draw(int posX=0, int posY=0, ::Color tint={255, 255, 255, 255})
Draw a Texture2D.
void Load(const std::string &fileName)
Load texture from file into GPU memory (VRAM)
Texture & SetShapes(const ::Rectangle &source)
Set texture and rectangle to be used on shapes drawing.
bool IsReady() const
Determines whether or not the Texture has been loaded and is ready.
Texture()
Default texture constructor.
Texture & SetMaterial(::Material *material, int mapType=MATERIAL_MAP_NORMAL)
Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...)
Texture(const ::Image &image, int layout)
Load cubemap from image, multiple image cubemap layouts supported.
Texture(const std::string &fileName)
Load texture from file into GPU memory (VRAM)
Texture & Update(const void *pixels)
Update GPU texture with new data.
Texture & Update(::Rectangle rec, const void *pixels)
Update GPU texture rectangle with new data.
Texture & SetShaderValue(const ::Shader &shader, int locIndex)
Set shader uniform value for texture (sampler2d)
All raylib-cpp classes and functions appear in the raylib namespace.