mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-09-12 16:57:00 -04:00
Allow to create Texture from Surface
This commit is contained in:
parent
6e90301ba1
commit
fff166becd
@ -33,6 +33,7 @@
|
||||
#include <SDL2pp/Renderer.hh>
|
||||
#include <SDL2pp/Exception.hh>
|
||||
#include <SDL2pp/Rect.hh>
|
||||
#include <SDL2pp/Surface.hh>
|
||||
#ifdef SDL2PP_WITH_IMAGE
|
||||
# include <SDL2pp/RWops.hh>
|
||||
#endif
|
||||
@ -55,6 +56,11 @@ Texture::Texture(Renderer& renderer, const std::string& path) {
|
||||
}
|
||||
#endif
|
||||
|
||||
Texture::Texture(Renderer& renderer, const Surface& surface) {
|
||||
if ((texture_ = SDL_CreateTextureFromSurface(renderer.Get(), surface.Get())) == nullptr)
|
||||
throw Exception("SDL_CreateTextureFromSurface failed");
|
||||
}
|
||||
|
||||
Texture::~Texture() {
|
||||
if (texture_ != nullptr)
|
||||
SDL_DestroyTexture(texture_);
|
||||
|
@ -37,6 +37,7 @@ namespace SDL2pp {
|
||||
|
||||
class Renderer;
|
||||
class RWops;
|
||||
class Surface;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Image stored in the graphics card memory that
|
||||
@ -207,6 +208,19 @@ public:
|
||||
Texture(Renderer& renderer, const std::string& filename);
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create texture from surface
|
||||
///
|
||||
/// \param renderer Rendering context to create texture for
|
||||
/// \param surface Surface containing pixel data used to fill the texture
|
||||
///
|
||||
/// \throws SDL2pp::Exception
|
||||
///
|
||||
/// \see http://wiki.libsdl.org/SDL_CreateTextureFromSurface
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Texture(Renderer& renderer, const Surface& surface);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user