38 #include "SDL_image.h"
39 #include "SDL_getenv.h"
56 static std::string backend_name =
"SDL";
63 std::string envVar = std::string(
"SDL_VIDEODRIVER=") + driver;
64 buf =
const_cast<char*
>(envVar.c_str());
68 if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
69 throw SDLException(SDL_GetError());
71 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
86 SDL_Surface *img = IMG_Load(icon.c_str());
88 SDL_WM_SetIcon(img, 0);
93 SDL_WM_SetCaption(title.c_str(), 0);
103 if (bitsPerPixel != 0) {
104 uint16_t bpp = SDL_VideoModeOK(width, height, bitsPerPixel, flags);
106 throw SDLException(
"Selected video mode not supported!");
113 m_screen = SDL_SetVideoMode(width, height, bitsPerPixel, flags);
115 throw SDLException(
"Unable to set video mode selected!");
120 <<
"Videomode " << width <<
"x" << height
121 <<
" at " << int32_t(
m_screen->format->BitsPerPixel) <<
" bpp");
162 return new SDLImage(data, width, height);
166 return new SDLImage(name, data, width, height);
170 SDLException(
"Lighting not available under SDL");
208 int32_t dx =
ABS(x2 - x1);
209 int32_t dy =
ABS(y2 - y1);
228 for (int32_t x = x1; x <= x2; x++) {
241 for (int32_t x = x1; x <= x2; x++) {
269 for (int32_t y = y1; y <= y2; y++) {
282 for (int32_t y = y1; y <= y2; y++) {
301 Point p1, p2, p3, p4;
325 Uint32 color = SDL_MapRGBA(
m_target->format, r, g, b, a);
326 SDL_FillRect(
m_target, &rect, color);
330 fillRectangle(p1, static_cast<uint16_t>(p3.
x-p1.
x), static_cast<uint16_t>(p3.
y-p1.
y), r, g, b, a);
353 SDL_Surface* surface = SDL_CreateRGBSurface(SDL_SWSURFACE, swidth, sheight, 24,
360 SDL_BlitSurface(
m_screen, NULL, surface, NULL);
363 SDL_FreeSurface(surface);
371 const bool same_size = (width == swidth && height == sheight);
373 if (width < 1 || height < 1) {
382 SDL_Surface* src = SDL_CreateRGBSurface(SDL_SWSURFACE, swidth, sheight, 32,
389 SDL_BlitSurface(
m_screen, NULL, src, NULL);
391 SDL_Surface* dst = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 32,
395 uint32_t* src_help_pointer = src_pointer;
398 int32_t x, y, *sx_ca, *sy_ca;
399 int32_t sx =
static_cast<int32_t
>(0xffff * src->w / dst->w);
400 int32_t sy =
static_cast<int32_t
>(0xffff * src->h / dst->h);
405 int32_t* sx_a =
new int32_t[dst->w + 1];
407 for (x = 0; x <= dst->w; x++) {
414 int32_t* sy_a =
new int32_t[dst->h + 1];
416 for (y = 0; y <= dst->h; y++) {
426 if (SDL_MUSTLOCK(src)) {
427 SDL_LockSurface(src);
430 if (SDL_MUSTLOCK(dst)) {
431 SDL_LockSurface(dst);
434 for (y = 0; y < dst->h; y++) {
435 src_pointer = src_help_pointer;
437 for (x = 0; x < dst->w; x++) {
438 *dst_pointer = *src_pointer;
440 src_pointer += (*sx_ca >> 16);
444 src_help_pointer = (
uint32_t*)((
uint8_t*)src_help_pointer + (*sy_ca >> 16) * src->pitch);
447 if (SDL_MUSTLOCK(dst)) {
448 SDL_UnlockSurface(dst);
450 if (SDL_MUSTLOCK(src)) {
451 SDL_UnlockSurface(src);
457 SDL_FreeSurface(src);
458 SDL_FreeSurface(dst);
476 SDL_FillRect(
m_target, &rect, color);
Abstract interface for all the renderbackends.
static bool putPixel(SDL_Surface *surface, int32_t x, int32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
virtual void createMainScreen(const ScreenMode &mode, const std::string &title, const std::string &icon)
Creates the mainscreen (the display window).
virtual void changeRenderInfos(uint16_t elements, int32_t src, int32_t dst, bool light, bool stentest, uint8_t stenref, GLConstants stenop, GLConstants stenfunc)
Dirty helper function to change the render infos.
virtual void renderVertexArrays()
Render the Vertex Arrays, only for primitives (points, lines,...)
T h
Height of the rectangle.
Helper class to create log strings out from separate parts Usage: LMsg("some text") << variable << "...
SDL_PixelFormat m_rgba_format
virtual void drawTriangle(const Point &p1, const Point &p2, const Point &p3, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws triangle between given points with given RGBA.
virtual void resetStencilBuffer(uint8_t buffer)
Reset stencil buffer with given value.
uint32_t getHeight() const
uint32_t getSDLFlags() const
Returns the SDL flags used when testing this mode.
The SDL implementation of the Image base class.
static void saveAsPng(const std::string &filename, const SDL_Surface &surface)
Saves the SDL_Surface to png format.
virtual void captureScreen(const std::string &filename)
Creates a Screenshot and saves it to a file.
uint16_t getBPP() const
Returns the number of bits per pixel this mode uses.
virtual void setClipArea(const Rect &cliparea, bool clear)
Sets given clip area into image.
static Logger _log(LM_AUDIO)
virtual void drawQuad(const Point &p1, const Point &p2, const Point &p3, const Point &p4, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws quad between given points with given RGBA.
virtual ~RenderBackendSDL()
virtual const std::string & getName() const
The name of the renderbackend.
virtual Image * createImage(IResourceLoader *loader=0)
virtual uint32_t getLightingModel() const
Gets the current light model.
const Rect & getArea() const
virtual void startFrame()
Called when a new frame starts.
virtual void setScreenMode(const ScreenMode &mode)
Sets the mainscreen display mode.
virtual bool putPixel(int32_t x, int32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Writes pixel to given position.
PointType2D< int32_t > Point
SDL_Surface * getSurface()
virtual void drawLightPrimitive(const Point &p, uint8_t intensity, float radius, int32_t subdivisions, float xstretch, float ystretch, uint8_t red, uint8_t green, uint8_t blue)
Draws a light primitive that based on a triangle fan.
virtual void startFrame()
Called when a new frame starts.
virtual void drawRectangle(const Point &p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws an axis parallel rectangle.
RenderBackendSDL(const SDL_Color &colorkey)
virtual void detachRenderTarget()
Detaches current render surface.
uint16_t getHeight() const
Returns the height of the screen mode.
virtual void resetLighting()
Reset lighting with default values.
uint16_t getWidth() const
Returns the width of the screen mode.
SDL_Color m_backgroundcolor
virtual void fillRectangle(const Point &p, uint16_t w, uint16_t h, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws a filled axis parallel rectangle.
#define FL_LOG(logger, msg)
uint32_t getWidth() const
virtual void endFrame()
Called when a frame is finished and ready to be displayed.
virtual void clearBackBuffer()
Forces a clear of the backbuffer.
virtual void endFrame()
Called when a frame is finished and ready to be displayed.
virtual void changeBlending(int32_t scr, int32_t dst)
Change the Blendingmodel.
virtual void setLighting(float red, float green, float blue)
Set colors for lighting.
virtual void drawLine(const Point &p1, const Point &p2, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws line between given points with given RGBA.
virtual void attachRenderTarget(ImagePtr &img, bool discard)
Attaches given image as a new render surface.
void deinit()
Performs cleanup actions.
virtual void addImageToArray(uint32_t id, const Rect &rec, float const *st, uint8_t alpha, uint8_t const *rgba)
Add the Image data to the array.
T w
Width of the rectangle.
virtual void setLightingModel(uint32_t lighting)
Initializes the light.
virtual void drawVertex(const Point &p, const uint8_t size, uint8_t r, uint8_t g, uint8_t b, uint8_t a=255)
Draws a quad that represents a vertex with given RGBA.
virtual void init(const std::string &driver)
Initializes the backend.