New code and data to get something on screen.

WiP.
This commit is contained in:
King_DuckZ 2014-02-09 00:32:11 +01:00
parent 2429229a95
commit a8f8d50129
10 changed files with 157 additions and 0 deletions

View file

@ -3,8 +3,11 @@
#include "sdlmain.hpp"
#include <SDL2/SDL.h>
#include <stdexcept>
#include <cassert>
namespace cloonel {
///------------------------------------------------------------------------
///------------------------------------------------------------------------
Texture::Texture (const std::string& parPath, SDLMain* parMain, bool parLoadNow) :
m_path(parPath),
m_texture(nullptr),
@ -14,10 +17,14 @@ namespace cloonel {
Reload();
}
///------------------------------------------------------------------------
///------------------------------------------------------------------------
Texture::~Texture() noexcept {
Destroy();
}
///------------------------------------------------------------------------
///------------------------------------------------------------------------
void Texture::Destroy() noexcept {
if (m_texture) {
SDL_DestroyTexture(m_texture);
@ -25,6 +32,8 @@ namespace cloonel {
}
}
///------------------------------------------------------------------------
///------------------------------------------------------------------------
void Texture::Reload() {
Destroy();
SDL_Surface* surf = SDL_LoadBMP(m_path.c_str());
@ -32,5 +41,13 @@ namespace cloonel {
throw std::runtime_error(GetFullErrorMessage(__PRETTY_FUNCTION__, m_path));
m_texture = SDL_CreateTextureFromSurface(m_sdlmain->GetRenderer(), surf);
SDL_FreeSurface(surf);
}
///------------------------------------------------------------------------
///------------------------------------------------------------------------
void Texture::Render() {
assert(IsLoaded());
SDL_RenderCopy(m_sdlmain->GetRenderer(), m_texture, nullptr, nullptr);
}
} //namespace cloonel