mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-09-09 15:28:29 -04:00
Allow to load texture fro file or via RWops
This commit is contained in:
parent
d69a07ea1c
commit
2b84c17ce2
@ -21,12 +21,21 @@
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include <SDL2pp/Config.hh>
|
||||
|
||||
#include <SDL2/SDL_render.h>
|
||||
#ifdef SDL2PP_WITH_IMAGE
|
||||
# include <SDL2/SDL_image.h>
|
||||
#endif
|
||||
|
||||
#include <SDL2pp/Texture.hh>
|
||||
#include <SDL2pp/Config.hh>
|
||||
#include <SDL2pp/Renderer.hh>
|
||||
#include <SDL2pp/Exception.hh>
|
||||
#include <SDL2pp/Rect.hh>
|
||||
#ifdef SDL2PP_WITH_IMAGE
|
||||
# include <SDL2pp/RWops.hh>
|
||||
#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_);
|
||||
|
@ -22,15 +22,20 @@
|
||||
#ifndef SDL2PP_TEXTURE_HH
|
||||
#define SDL2PP_TEXTURE_HH
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <SDL2/SDL_stdinc.h>
|
||||
#include <SDL2/SDL_blendmode.h>
|
||||
|
||||
#include <SDL2pp/Config.hh>
|
||||
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user