mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-08-04 03:15:59 -04:00
Add SDL_image surface loaders
This commit is contained in:
parent
6db6d0c1bc
commit
6e90301ba1
@ -21,10 +21,18 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <SDL2pp/Config.hh>
|
||||
|
||||
#include <SDL2/SDL_surface.h>
|
||||
#ifdef SDL2PP_WITH_IMAGE
|
||||
# include <SDL2/SDL_image.h>
|
||||
#endif
|
||||
|
||||
#include <SDL2pp/Surface.hh>
|
||||
#include <SDL2pp/Exception.hh>
|
||||
#ifdef SDL2PP_WITH_IMAGE
|
||||
# include <SDL2pp/RWops.hh>
|
||||
#endif
|
||||
|
||||
namespace SDL2pp {
|
||||
|
||||
@ -41,6 +49,18 @@ Surface::Surface(void* pixels, int width, int height, int depth, int pitch, Uint
|
||||
throw Exception("SDL_CreateRGBSurfaceFrom failed");
|
||||
}
|
||||
|
||||
#ifdef SDL2PP_WITH_IMAGE
|
||||
Surface::Surface(RWops& rwops) {
|
||||
if ((surface_ = IMG_Load_RW(rwops.Get(), 0)) == nullptr)
|
||||
throw Exception("IMG_Load_RW failed");
|
||||
}
|
||||
|
||||
Surface::Surface(const std::string& path) {
|
||||
if ((surface_ = IMG_Load(path.c_str())) == nullptr)
|
||||
throw Exception("IMG_Load failed");
|
||||
}
|
||||
#endif
|
||||
|
||||
Surface::~Surface() {
|
||||
if (surface_ != nullptr)
|
||||
SDL_FreeSurface(surface_);
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <SDL2/SDL_stdinc.h>
|
||||
#include <SDL2/SDL_blendmode.h>
|
||||
|
||||
#include <SDL2pp/Config.hh>
|
||||
#include <SDL2pp/Optional.hh>
|
||||
#include <SDL2pp/Rect.hh>
|
||||
|
||||
@ -33,6 +34,8 @@ struct SDL_PixelFormat;
|
||||
|
||||
namespace SDL2pp {
|
||||
|
||||
class RWops;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Image stored in system memory with direct access
|
||||
/// to pixel data
|
||||
@ -194,6 +197,24 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
Surface(void* pixels, int width, int height, int depth, int pitch, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
|
||||
|
||||
#ifdef SDL2PP_WITH_IMAGE
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create surface loading it via RWops
|
||||
///
|
||||
/// \param rwops RWops used to access an image file
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Surface(RWops& rwops);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create surface loading it from file
|
||||
///
|
||||
/// \param filename Path to an image file
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Surface(const std::string& filename);
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Destructor
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user