mirror of
https://github.com/libSDL2pp/libSDL2pp.git
synced 2025-09-08 06:48:56 -04:00
Added Surface constructor based on SDL_CreateRGBSurfaceWithFormat (issue #80)
This commit is contained in:
parent
7cfc30970b
commit
a668a2dbd5
@ -51,6 +51,13 @@ Surface::Surface(void* pixels, int width, int height, int depth, int pitch, Uint
|
||||
throw Exception("SDL_CreateRGBSurfaceFrom");
|
||||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 5)
|
||||
Surface::Surface(Uint32 flags, int width, int height, int depth, Uint32 format) {
|
||||
if ((surface_ = SDL_CreateRGBSurfaceWithFormat(flags, width, height, depth, format)) == nullptr)
|
||||
throw Exception("SDL_CreateRGBSurfaceWithFormat");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SDL2PP_WITH_IMAGE
|
||||
Surface::Surface(RWops& rwops) {
|
||||
if ((surface_ = IMG_Load_RW(rwops.Get(), 0)) == nullptr)
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include <SDL_stdinc.h>
|
||||
#include <SDL_blendmode.h>
|
||||
#include <SDL_version.h>
|
||||
|
||||
#include <SDL2pp/Config.hh>
|
||||
#include <SDL2pp/Optional.hh>
|
||||
@ -210,6 +211,24 @@ public:
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Surface(void* pixels, int width, int height, int depth, int pitch, Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 5)
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create RGB surface with the given format
|
||||
///
|
||||
/// \param[in] flags Flags are obsolete and should be set to 0
|
||||
/// \param[in] width Width of the surface
|
||||
/// \param[in] height Height of the surface
|
||||
/// \param[in] depth Depth of the surface
|
||||
/// \param[in] format The pixel format of the surface
|
||||
///
|
||||
/// \throws SDL2pp::Exception
|
||||
///
|
||||
/// \see https://wiki.libsdl.org/SDL_CreateRGBSurfaceWithFormat
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
Surface(Uint32 flags, int width, int height, int depth, Uint32 format);
|
||||
#endif
|
||||
|
||||
#ifdef SDL2PP_WITH_IMAGE
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -17,4 +17,15 @@ BEGIN_TEST(int, char*[])
|
||||
EXPECT_EQUAL(crate.GetHeight(), 32);
|
||||
EXPECT_EQUAL(crate.GetSize(), Point(32, 32));
|
||||
}
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 5)
|
||||
{
|
||||
// Test create surface from pixel format
|
||||
Surface surface(0, 600, 300, 24, SDL_PIXELFORMAT_RGBA32);
|
||||
|
||||
EXPECT_EQUAL(surface.GetWidth(), 600);
|
||||
EXPECT_EQUAL(surface.GetHeight(), 300);
|
||||
EXPECT_EQUAL(surface.GetFormat(), SDL_PIXELFORMAT_RGBA32);
|
||||
}
|
||||
#endif
|
||||
END_TEST()
|
||||
|
Loading…
x
Reference in New Issue
Block a user