diff --git a/SDL2pp/Texture.cc b/SDL2pp/Texture.cc index 7a57687..099da8e 100644 --- a/SDL2pp/Texture.cc +++ b/SDL2pp/Texture.cc @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef SDL2PP_WITH_IMAGE # include #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_); diff --git a/SDL2pp/Texture.hh b/SDL2pp/Texture.hh index 98ac8bd..cb2a7ad 100644 --- a/SDL2pp/Texture.hh +++ b/SDL2pp/Texture.hh @@ -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 ///