raylib-cpp
raylib-cpp copied to clipboard
Get raylib::Texture from raylib::RenderTexture
In raylib::RenderTexture
, the GetTexture()
method returns a Texture
instead of the wrapped raylib::Texture
. This is kinda inconvenient since instead of render_texture.GetTexture().Draw(from, to)
, you have to use
DrawTexturePro(render_texture.GetTexture(),
from,
to,
raylib::Vector2(0, 0),
0.0f,
Color{255, 255, 255, 255});
This may be tricky, because if we have GetTexture() return a raylib::Texture, it will Unload the underlaying Texture when it completes....
{
raylib::Texture texture = renderTexture.GetTexture();
texture.Draw(100, 100);
}
// Error: The renderTexture's texture will now be destroyed.
Been considering implementing a TexturePointer
class or something, which inherits from Texture
, but overrides Unload()
to not actually Unload the Texture on deconstruction. Then in cases where we retrieve the Texture from something like this that doesn't want to Unload, it would be fine.
{
raylib::TexturePointer texture = renderTexture.GetTexturePointer();
texture.Draw(100, 100);
}
// Fine, because TexturePointer does not Unload on deconstruction.
Then, you'd be able to do this no problem, as the Texture wouldn't destruct itself.
render_texture.GetTexturePointer().Draw(from, to);
We could also have GetTexture returns the TexturePointer... Hmmm.
Or I wonder if it would be a good idea to add Draw(...)
methods to RenderTexture itself?
That's defintiely an easy option! :+1: