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"
29 int width,
int height,
31 int format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
32 : ::
Texture{id, width, height, mipmaps, format} {
59 Texture(const ::Image& image,
int layout) {
88 GETTERSETTER(
unsigned int, Id,
id)
89 GETTERSETTER(
int, Width, width)
90 GETTERSETTER(
int, Height, height)
91 GETTERSETTER(
int, Mipmaps, mipmaps)
92 GETTERSETTER(
int, Format, format)
102 if (
this == &other) {
122 return {
static_cast<float>(width),
static_cast<float>(height)};
128 void Load(const ::Image& image) {
129 set(::LoadTextureFromImage(image));
138 void Load(const ::Image& image,
int layoutType) {
139 set(::LoadTextureCubemap(image, layoutType));
148 void Load(
const std::string& fileName) {
149 set(::LoadTexture(fileName.c_str()));
151 throw RaylibException(
"Failed to load Texture from file: " + fileName);
159 ::UnloadTexture(*
this);
166 ::UpdateTexture(*
this, pixels);
174 UpdateTextureRec(*
this, rec, pixels);
182 return ::LoadImageFromTexture(*
this);
196 ::GenTextureMipmaps(
this);
204 ::SetTextureFilter(*
this, filterMode);
212 ::SetTextureWrap(*
this, wrapMode);
220 ::DrawTexture(*
this, posX, posY, tint);
224 inline Texture&
Draw(::Vector2 position, ::Color tint = {255, 255, 255, 255}) {
225 ::DrawTextureV(*
this, position, tint);
229 inline Texture&
Draw(::Vector2 position,
float rotation,
float scale = 1.0f,
230 ::Color tint = {255, 255, 255, 255}) {
231 ::DrawTextureEx(*
this, position, rotation, scale, tint);
235 inline Texture&
Draw(::Rectangle sourceRec, ::Vector2 position = {0, 0},
236 ::Color tint = {255, 255, 255, 255}) {
237 ::DrawTextureRec(*
this, sourceRec, position, tint);
241 inline Texture&
Draw(::Vector2 tiling, ::Vector2 offset, ::Rectangle quad,
242 ::Color tint = {255, 255, 255, 255}) {
243 ::DrawTextureQuad(*
this, tiling, offset, quad, tint);
247 inline Texture&
Draw(::Vector3 position,
float width,
float height,
float length,
248 ::Color tint = {255, 255, 255, 255}) {
249 ::DrawCubeTexture(*
this, position, width, height, length, tint);
253 inline Texture& DrawTiled(::Rectangle sourceRec, ::Rectangle destRec, ::Vector2 origin = {0, 0},
254 float rotation = 0,
float scale = 1, Color tint = {255, 255, 255, 255}) {
255 ::DrawTextureTiled(*
this, sourceRec, destRec, origin, rotation, scale, tint);
259 inline Texture&
Draw(::Rectangle sourceRec, ::Rectangle destRec, ::Vector2 origin = {0, 0},
260 float rotation = 0, ::Color tint = {255, 255, 255, 255}) {
261 ::DrawTexturePro(*
this, sourceRec, destRec, origin, rotation, tint);
265 inline Texture&
Draw(::NPatchInfo nPatchInfo, ::Rectangle destRec, ::Vector2 origin = {0, 0},
266 float rotation = 0, ::Color tint = {255, 255, 255, 255}) {
267 ::DrawTextureNPatch(*
this, nPatchInfo, destRec, origin, rotation, tint);
271 inline Texture& DrawPoly(::Vector2 center, ::Vector2 *points,
272 ::Vector2 *texcoords,
int pointsCount,
273 ::Color tint = {255, 255, 255, 255}) {
274 ::DrawTexturePoly(*
this, center, points, texcoords, pointsCount, tint);
282 ::
Vector3 position,
float size,
283 ::
Color tint = {255, 255, 255, 255}) {
293 ::
Color tint = {255, 255, 255, 255}) {
294 DrawBillboardRec(camera, *
this, source, position, size, tint);
304 ::
Color tint = {255, 255, 255, 255}) {
305 DrawBillboardPro(camera, *
this, source, position, up, size, origin, rotation, tint);
313 ::SetMaterialTexture(material, mapType, *
this);
317 inline Texture&
SetMaterial(const ::Material& material,
int mapType = MATERIAL_MAP_NORMAL) {
318 ::SetMaterialTexture((::
Material*)(&material), mapType, *
this);
326 ::SetShapesTexture(*
this, source);
334 ::SetShaderValueTexture(shader, locIndex, *
this);
348 void set(const ::Texture& texture) {
350 width = texture.width;
351 height = texture.height;
352 mipmaps = texture.mipmaps;
353 format = texture.format;
358 typedef Texture Texture2D;
359 typedef Texture TextureCubemap;
Image type, bpp always RGBA (32bit)
Exception used for most raylib-related exceptions.
Texture & DrawBillboard(const ::Camera &camera, ::Rectangle source, Vector3 position, ::Vector3 up, Vector2 size, Vector2 origin, float rotation, ::Color tint={255, 255, 255, 255})
Draw a billboard texture defined by source and rotation.
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 & DrawBillboard(const ::Camera &camera, ::Vector3 position, float size, ::Color tint={255, 255, 255, 255})
Draw a billboard texture.
Texture(const ::Image &image, int layout)
Load cubemap from image, multiple image cubemap layouts supported.
Texture & DrawBillboard(const ::Camera &camera, ::Rectangle source, ::Vector3 position, ::Vector2 size, ::Color tint={255, 255, 255, 255})
Draw a billboard texture defined by source.
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.