From 2b84c17ce2413d9d13490dbf4e39daf2412e69f6 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Fri, 5 Sep 2014 05:03:12 +0400 Subject: [PATCH] Allow to load texture fro file or via RWops --- SDL2pp/Texture.cc | 20 ++++++++++++++++++++ SDL2pp/Texture.hh | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/SDL2pp/Texture.cc b/SDL2pp/Texture.cc index fa01f88..62d062f 100644 --- a/SDL2pp/Texture.cc +++ b/SDL2pp/Texture.cc @@ -21,12 +21,21 @@ #include +#include + #include +#ifdef SDL2PP_WITH_IMAGE +# include +#endif #include +#include #include #include #include +#ifdef SDL2PP_WITH_IMAGE +# include +#endif namespace SDL2pp { @@ -35,6 +44,17 @@ Texture::Texture(Renderer& renderer, Uint32 format, int access, int w, int h) { throw Exception("SDL_CreateTexture failed"); } +#ifdef SDL2PP_WITH_IMAGE +Texture::Texture(Renderer& renderer, RWops& rwops) { + texture_ = IMG_LoadTexture_RW(renderer.Get(), rwops.Get(), 0); +} + +Texture::Texture(Renderer& renderer, const std::string& path) { + RWops rwops = RWops::FromFile(path); + texture_ = IMG_LoadTexture_RW(renderer.Get(), rwops.Get(), 0); +} +#endif + Texture::~Texture() { if (texture_ != nullptr) SDL_DestroyTexture(texture_); diff --git a/SDL2pp/Texture.hh b/SDL2pp/Texture.hh index 89aa223..85b342a 100644 --- a/SDL2pp/Texture.hh +++ b/SDL2pp/Texture.hh @@ -22,15 +22,20 @@ #ifndef SDL2PP_TEXTURE_HH #define SDL2PP_TEXTURE_HH +#include + #include #include +#include + struct SDL_Texture; namespace SDL2pp { class Renderer; class Rect; +class RWops; class Texture { private: @@ -38,6 +43,10 @@ private: public: Texture(Renderer& renderer, Uint32 format, int access, int w, int h); +#ifdef SDL2PP_WITH_IMAGE + Texture(Renderer& renderer, RWops& rwops); + Texture(Renderer& renderer, const std::string& filename); +#endif virtual ~Texture(); Texture(const Texture& other) = delete;