1// SuperTux
2// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17#include "video/sdl/sdl_texture.hpp"
18
19#include <SDL.h>
20#include <sstream>
21
22#include "video/sdl/sdl_screen_renderer.hpp"
23#include "video/video_system.hpp"
24
25SDLTexture::SDLTexture(SDL_Texture* texture, int width, int height, const Sampler& sampler) :
26 m_texture(texture),
27 m_width(width),
28 m_height(height),
29 m_sampler(sampler)
30{
31}
32
33SDLTexture::SDLTexture(const SDL_Surface& image, const Sampler& sampler) :
34 m_texture(),
35 m_width(),
36 m_height(),
37 m_sampler(sampler)
38{
39 m_texture = SDL_CreateTextureFromSurface(static_cast<SDLScreenRenderer&>(VideoSystem::current()->get_renderer()).get_sdl_renderer(),
40 const_cast<SDL_Surface*>(&image));
41 if (!m_texture)
42 {
43 std::ostringstream msg;
44 msg << "couldn't create texture: " << SDL_GetError();
45 throw std::runtime_error(msg.str());
46 }
47
48 m_width = image.w;
49 m_height = image.h;
50}
51
52SDLTexture::~SDLTexture()
53{
54 SDL_DestroyTexture(m_texture);
55}
56
57/* EOF */
58