1#ifndef RAYLIB_CPP_INCLUDE_TEXTUREUNMANAGED_HPP_
2#define RAYLIB_CPP_INCLUDE_TEXTUREUNMANAGED_HPP_
8#include "./Material.hpp"
9#include "./RaylibException.hpp"
11#include "./RadiansDegrees.hpp"
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} {
76 TextureUnmanaged(::Texture&& other) : ::
Texture{other.id, other.width, other.height, other.mipmaps, other.format} {
80 GETTER(
unsigned int, Id,
id)
81 GETTER(
int, Width, width)
82 GETTER(
int, Height, height)
83 GETTER(
int, Mipmaps, mipmaps)
84 GETTER(
int, Format, format)
95 return {
static_cast<float>(width),
static_cast<float>(height)};
101 void Load(const ::Image& image) {
102 set(::LoadTextureFromImage(image));
111 void Load(const ::Image& image,
int layoutType) {
112 set(::LoadTextureCubemap(image, layoutType));
121 void Load(
const std::string_view fileName) {
122 set(::LoadTexture(fileName.data()));
124 throw RaylibException(
"Failed to load Texture from file: " + std::string(fileName));
134 ::UnloadTexture(*
this);
143 ::UpdateTexture(*
this, pixels);
151 UpdateTextureRec(*
this, rec, pixels);
159 return ::LoadImageFromTexture(*
this);
171 ::GenTextureMipmaps(
this);
179 ::SetTextureFilter(*
this, filterMode);
187 ::SetTextureWrap(*
this, wrapMode);
196 void Draw(
int posX = 0,
int posY = 0, ::Color tint = {255, 255, 255, 255})
const {
197 ::DrawTexture(*
this, posX, posY, tint);
205 void Draw(::Vector2 position, ::Color tint = {255, 255, 255, 255})
const { ::DrawTextureV(*
this, position, tint); }
212 void Draw(::Vector2 position,
Degree rotation,
float scale = 1.0f,
213 ::Color tint = {255, 255, 255, 255})
const {
214 ::DrawTextureEx(*
this, position, rotation, scale, tint);
222 void Draw(::Rectangle sourceRec, ::Vector2 position = {0, 0}, ::Color tint = {255, 255, 255, 255})
const {
223 ::DrawTextureRec(*
this, sourceRec, position, tint);
231 void Draw(::Rectangle sourceRec, ::Rectangle destRec, ::Vector2 origin = {0, 0},
232 Degree rotation = 0, ::Color tint = {255, 255, 255, 255})
const {
233 ::DrawTexturePro(*
this, sourceRec, destRec, origin, rotation, tint);
241 void Draw(::NPatchInfo nPatchInfo, ::Rectangle destRec, ::Vector2 origin = {0, 0},
242 Radian rotation = 0, ::Color tint = {255, 255, 255, 255})
const {
243 ::DrawTextureNPatch(*
this, nPatchInfo, destRec, origin, rotation, tint);
252 DrawBillboard(const ::Camera& camera, ::Vector3 position,
float size, ::Color tint = {255, 255, 255, 255})
const {
262 const ::Camera& camera,
266 ::Color tint = {255, 255, 255, 255})
const {
267 DrawBillboardRec(camera, *
this, source, position, size, tint);
276 ::Rectangle source,
Vector3 position,
278 ::Color tint = {255, 255, 255, 255})
const {
279 DrawBillboardPro(camera, *
this, source, position, up, size, origin, rotation, tint);
286 ::SetMaterialTexture(material, mapType, *
this);
291 ::SetMaterialTexture(
const_cast<::
Material*
>(&material), mapType, *
this);
299 ::SetShapesTexture(*
this, source);
307 ::SetShaderValueTexture(shader, locIndex, *
this);
316 [[nodiscard]]
bool IsValid()
const {
return IsTextureValid(*
this); }
318 void set(const ::Texture& texture) {
320 width = texture.width;
321 height = texture.height;
322 mipmaps = texture.mipmaps;
323 format = texture.format;
328using Texture2DUnmanaged = TextureUnmanaged;
329using 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.
bool IsValid() const
Determines whether or not the Texture has been loaded and is ready.
TextureUnmanaged(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.
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.
All raylib-cpp classes and functions appear in the raylib namespace.