31 #include "util/base/exception.h"
32 #include "util/math/fife_math.h"
33 #include "util/log/logger.h"
34 #include "video/devicecaps.h"
36 #include "renderbackendsdl.h"
38 #include "SDL_image.h"
39 #include "SDL_getenv.h"
42 static Logger _log(LM_VIDEO);
44 RenderBackendSDL::RenderBackendSDL(
const SDL_Color& colorkey) : RenderBackend(colorkey) {
48 RenderBackendSDL::~RenderBackendSDL() {
53 static std::string backend_name =
"SDL";
60 std::string envVar = std::string(
"SDL_VIDEODRIVER=") + driver;
61 buf =
const_cast<char*
>(envVar.c_str());
65 if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
66 throw SDLException(SDL_GetError());
68 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
77 SDL_SetClipRect(m_screen->getSurface(), &rect);
78 SDL_FillRect(m_screen->getSurface(), 0, 0x00);
83 SDL_Surface *img = IMG_Load(icon.c_str());
85 SDL_WM_SetIcon(img, 0);
91 SDL_WM_SetCaption(title.c_str(), 0);
97 uint16_t width = mode.getWidth();
98 uint16_t height = mode.getHeight();
99 uint16_t bitsPerPixel = mode.getBPP();
100 bool fs = mode.isFullScreen();
101 uint32_t flags = mode.getSDLFlags();
103 SDL_Surface* screen = NULL;
105 if (bitsPerPixel != 0) {
106 uint16_t bpp = SDL_VideoModeOK(width, height, bitsPerPixel, flags);
108 throw SDLException(
"Selected video mode not supported!");
112 screen = SDL_SetVideoMode(width, height, bitsPerPixel, flags);
114 throw SDLException(
"Unable to set video mode selected!");
117 FL_LOG(_log,
LMsg(
"RenderBackendSDL")
118 <<
"Videomode " << width <<
"x" << height
119 <<
" at " <<
int(screen->format->BitsPerPixel) <<
" bpp");
122 m_screenMode = ScreenMode(width,
128 throw SDLException(SDL_GetError());
140 SDL_Flip(m_screen->getSurface());
148 return new SDLImage(data, width, height);
152 SDLException(
"Lighting not available under SDL");
177 void RenderBackendSDL::setStencilTest(uint8_t stencil_ref,
unsigned int stencil_op,
unsigned int stencil_func) {
180 void RenderBackendSDL::resetStencilBuffer(uint8_t buffer) {
199 bool RenderBackendSDL::putPixel(
int x,
int y,
int r,
int g,
int b,
int a) {
200 return static_cast<SDLImage*
>(m_screen)->putPixel(x, y, r, g, b, a);
203 void RenderBackendSDL::drawLine(
const Point& p1,
const Point& p2,
int r,
int g,
int b,
int a) {
204 static_cast<SDLImage*
>(m_screen)->drawLine(p1, p2, r, g, b, a);
207 void RenderBackendSDL::drawTriangle(
const Point& p1,
const Point& p2,
const Point& p3,
int r,
int g,
int b,
int a) {
208 static_cast<SDLImage*
>(m_screen)->drawTriangle(p1, p2, p3, r, g, b, a);
211 void RenderBackendSDL::drawRectangle(
const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
212 static_cast<SDLImage*
>(m_screen)->drawRectangle(p, w, h, r, g, b, a);
215 void RenderBackendSDL::fillRectangle(
const Point& p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a) {
216 static_cast<SDLImage*
>(m_screen)->fillRectangle(p, w, h, r, g, b, a);
219 void RenderBackendSDL::drawQuad(
const Point& p1,
const Point& p2,
const Point& p3,
const Point& p4,
int r,
int g,
int b,
int a) {
220 static_cast<SDLImage*
>(m_screen)->drawQuad(p1, p2, p3, p4, r, g, b, a);
223 void RenderBackendSDL::drawVertex(
const Point& p,
const uint8_t size,
int r,
int g,
int b,
int a){
224 static_cast<SDLImage*
>(m_screen)->drawVertex(p, 2, r, g, b, a);
227 void RenderBackendSDL::drawLightPrimitive(
const Point& p, uint8_t intensity,
float radius,
int subdivisions,
float xstretch,
float ystretch, uint8_t red, uint8_t green, uint8_t blue){
228 static_cast<SDLImage*
>(m_screen)->drawLightPrimitive(p, intensity, radius, subdivisions, xstretch, ystretch, red, green, blue);