Add a ctor to ttexture which loads the texture from a file.
This commit is contained in:
parent
0fd45763a9
commit
c63c27ae5e
2 changed files with 33 additions and 0 deletions
|
@ -16,6 +16,7 @@
|
|||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
|
||||
#include "SDL_image.h"
|
||||
#include "sdl/exception.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
@ -36,6 +37,27 @@ ttexture::ttexture(SDL_Renderer& renderer,
|
|||
}
|
||||
}
|
||||
|
||||
ttexture::ttexture(SDL_Renderer& renderer,
|
||||
const std::string& file)
|
||||
: reference_count_(new unsigned(1))
|
||||
, texture_(NULL)
|
||||
{
|
||||
SDL_Surface* img;
|
||||
img = IMG_Load(file.c_str());
|
||||
|
||||
if (img == NULL) {
|
||||
throw texception("Failed to create SDL_Texture object.", true);
|
||||
} else {
|
||||
texture_ = SDL_CreateTextureFromSurface(&renderer, img);
|
||||
|
||||
if (texture_ == NULL) {
|
||||
throw texception("Failed to create SDL_Texture object.", true);
|
||||
}
|
||||
|
||||
SDL_FreeSurface(img);
|
||||
}
|
||||
}
|
||||
|
||||
ttexture::~ttexture()
|
||||
{
|
||||
assert(reference_count_);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
*/
|
||||
|
||||
#include <SDL_version.h>
|
||||
#include <string>
|
||||
|
||||
#if SDL_VERSION_ATLEAST(2, 0, 0)
|
||||
|
||||
|
@ -55,6 +56,16 @@ public:
|
|||
const int w,
|
||||
const int h);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Loads image data from @a file and converts it to a texture.
|
||||
*
|
||||
* @param renderer The renderer the texture is associated with.
|
||||
* @param file Path of the file to load the pixels from.
|
||||
*/
|
||||
ttexture(SDL_Renderer& renderer, const std::string& file);
|
||||
|
||||
~ttexture();
|
||||
|
||||
ttexture(const ttexture& texture);
|
||||
|
|
Loading…
Add table
Reference in a new issue