1#ifndef RAYLIB_CPP_INCLUDE_TEXTUREUNMANAGED_HPP_
2#define RAYLIB_CPP_INCLUDE_TEXTUREUNMANAGED_HPP_
8#include "./raylib-cpp-utils.hpp"
9#include "./Vector2.hpp"
10#include "./Material.hpp"
11#include "./RaylibException.hpp"
13#include "./RadiansDegrees.hpp"
36 int width,
int height,
38 int format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
39 : ::
Texture{id, width, height, mipmaps, format} {
47 ::
Texture{texture.id, texture.width, texture.height, texture.mipmaps, texture.format} {
81 ::
Texture{other.id, other.width, other.height, other.mipmaps, other.format} {
85 GETTER(
unsigned int, Id,
id)
86 GETTER(
int, Width, width)
87 GETTER(
int, Height, height)
88 GETTER(
int, Mipmaps, mipmaps)
89 GETTER(
int, Format, format)
100 return {
static_cast<float>(width),
static_cast<float>(height)};
106 void Load(const ::Image& image) {
107 set(::LoadTextureFromImage(image));
116 void Load(const ::Image& image,
int layoutType) {
117 set(::LoadTextureCubemap(image, layoutType));
126 void Load(
const std::string_view fileName) {
127 set(::LoadTexture(fileName.data()));
129 throw RaylibException(
"Failed to load Texture from file: " + std::string(fileName));
139 ::UnloadTexture(*
this);
148 ::UpdateTexture(*
this, pixels);
156 UpdateTextureRec(*
this, rec, pixels);
164 return ::LoadImageFromTexture(*
this);
178 ::GenTextureMipmaps(
this);
186 ::SetTextureFilter(*
this, filterMode);
194 ::SetTextureWrap(*
this, wrapMode);
203 void Draw(
int posX = 0,
int posY = 0, ::Color tint = {255, 255, 255, 255})
const {
204 ::DrawTexture(*
this, posX, posY, tint);
212 void Draw(::Vector2 position, ::Color tint = {255, 255, 255, 255})
const {
213 ::DrawTextureV(*
this, position, tint);
221 void Draw(::Vector2 position,
Degree rotation,
float scale = 1.0f,
222 ::Color tint = {255, 255, 255, 255})
const {
223 ::DrawTextureEx(*
this, position, rotation, scale, tint);
231 void Draw(::Rectangle sourceRec, ::Vector2 position = {0, 0},
232 ::Color tint = {255, 255, 255, 255})
const {
233 ::DrawTextureRec(*
this, sourceRec, position, tint);
241 void Draw(::Rectangle sourceRec, ::Rectangle destRec, ::Vector2 origin = {0, 0},
242 Degree rotation = 0, ::Color tint = {255, 255, 255, 255})
const {
243 ::DrawTexturePro(*
this, sourceRec, destRec, origin, rotation, tint);
251 void Draw(::NPatchInfo nPatchInfo, ::Rectangle destRec, ::Vector2 origin = {0, 0},
252 Radian rotation = 0, ::Color tint = {255, 255, 255, 255})
const {
253 ::DrawTextureNPatch(*
this, nPatchInfo, destRec, origin, rotation, tint);
262 ::Vector3 position,
float size,
263 ::Color tint = {255, 255, 255, 255})
const {
273 ::Rectangle source, ::Vector3 position, ::Vector2 size,
274 ::Color tint = {255, 255, 255, 255})
const {
275 DrawBillboardRec(camera, *
this, source, position, size, tint);
284 ::Rectangle source,
Vector3 position,
286 ::Color tint = {255, 255, 255, 255})
const {
287 DrawBillboardPro(camera, *
this, source, position, up, size, origin, rotation, tint);
294 ::SetMaterialTexture(material, mapType, *
this);
299 ::SetMaterialTexture((::Material*)(&material), mapType, *
this);
307 ::SetShapesTexture(*
this, source);
315 ::SetShaderValueTexture(shader, locIndex, *
this);
329 void set(const ::Texture& texture) {
331 width = texture.width;
332 height = texture.height;
333 mipmaps = texture.mipmaps;
334 format = texture.format;
339using Texture2DUnmanaged = TextureUnmanaged;
340using TextureCubemapUnmanaged = TextureUnmanaged;
Degree type (allows automatic worry free conversion between radians and degrees)
Image type, bpp always RGBA (32bit)
Radian type (allows automatic worry free conversion between radians and degrees)
Exception used for most raylib-related exceptions.
A Texture that is not managed by C++ RAII.
void DrawBillboard(const ::Camera &camera, ::Vector3 position, float size, ::Color tint={255, 255, 255, 255}) const
Draw a billboard texture.
void Load(const std::string_view fileName)
Load texture from file into GPU memory (VRAM)
TextureUnmanaged & SetShapes(const ::Rectangle &source)
Set texture and rectangle to be used on shapes drawing.
void Load(const ::Image &image, int layoutType)
Load cubemap from image, multiple image cubemap layouts supported.
void Draw(::Rectangle sourceRec, ::Rectangle destRec, ::Vector2 origin={0, 0}, Degree rotation=0, ::Color tint={255, 255, 255, 255}) const
Draw a part of a texture defined by a rectangle with 'pro' parameters.
TextureUnmanaged & SetFilter(int filterMode)
Set texture scaling filter mode.
TextureUnmanaged(const ::Image &image, int layout)
Load cubemap from image, multiple image cubemap layouts supported.
TextureUnmanaged(unsigned int id, int width, int height, int mipmaps=1, int format=PIXELFORMAT_UNCOMPRESSED_R8G8B8A8)
Move/Create a texture structure manually.
bool IsReady() const
Determines whether or not the Texture has been loaded and is ready.
void Load(const ::Image &image)
Load texture from image data.
TextureUnmanaged & SetWrap(int wrapMode)
Set texture wrapping mode.
TextureUnmanaged & Update(::Rectangle rec, const void *pixels)
Update GPU texture rectangle with new data.
TextureUnmanaged & SetMaterial(::Material *material, int mapType=MATERIAL_MAP_NORMAL)
Set texture for a material map type (MAP_DIFFUSE, MAP_SPECULAR...)
void Draw(int posX=0, int posY=0, ::Color tint={255, 255, 255, 255}) const
Draw a Texture2D.
Vector2 GetSize() const
Retrieve the width and height of the texture.
Image GetData() const
Get pixel data from GPU texture and return an Image.
void Draw(::Rectangle sourceRec, ::Vector2 position={0, 0}, ::Color tint={255, 255, 255, 255}) const
Draw a part of a texture defined by a rectangle.
void Draw(::Vector2 position, ::Color tint={255, 255, 255, 255}) const
Draw a Texture2D with position defined as Vector2.
TextureUnmanaged()
Default texture constructor.
void Draw(::Vector2 position, Degree rotation, float scale=1.0f, ::Color tint={255, 255, 255, 255}) const
Draw a Texture2D with extended parameters.
void Unload()
Unload texture from GPU memory (VRAM)
TextureUnmanaged(const std::string_view fileName)
Load texture from file into GPU memory (VRAM)
void Draw(::NPatchInfo nPatchInfo, ::Rectangle destRec, ::Vector2 origin={0, 0}, Radian rotation=0, ::Color tint={255, 255, 255, 255}) const
Draws a texture (or part of it) that stretches or shrinks nicely.
TextureUnmanaged & Update(const void *pixels)
Update GPU texture with new data.
void DrawBillboard(const ::Camera &camera, ::Rectangle source, Vector3 position, ::Vector3 up, Vector2 size, Vector2 origin, Degree rotation=0.0f, ::Color tint={255, 255, 255, 255}) const
Draw a billboard texture defined by source and rotation.
TextureUnmanaged(const ::Texture &texture)
Creates a texture object based on the given Texture struct data.
TextureUnmanaged(const ::Image &image)
Creates a texture from the given Image.
TextureUnmanaged & GenMipmaps()
Generate GPU mipmaps for a texture.
TextureUnmanaged & SetShaderValue(const ::Shader &shader, int locIndex)
Set shader uniform value for texture (sampler2d)
void DrawBillboard(const ::Camera &camera, ::Rectangle source, ::Vector3 position, ::Vector2 size, ::Color tint={255, 255, 255, 255}) const
Draw a billboard texture defined by source.