4 // Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #include "SDL_image.h"
28 #include "../video/surface.h"
29 #include "../video/screen.h"
30 #include "../app/globals.h"
31 #include "../app/setup.h"
33 using namespace SuperTux;
35 Surface::Surfaces Surface::surfaces;
37 SurfaceData::SurfaceData(SDL_Surface* temp, bool use_alpha_)
38 : type(SURFACE), surface(0), use_alpha(use_alpha_)
40 // Copy the given surface and make sure that it is not stored in
42 surface = SDL_CreateRGBSurface(temp->flags & (~SDL_HWSURFACE),
44 temp->format->BitsPerPixel,
50 Termination::abort("No memory left.", "");
51 SDL_SetAlpha(temp,0,0);
52 SDL_BlitSurface(temp, NULL, surface, NULL);
55 SurfaceData::SurfaceData(const std::string& file_, bool use_alpha_)
56 : type(LOAD), surface(0), file(file_), use_alpha(use_alpha_)
59 SurfaceData::SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, bool use_alpha_)
60 : type(LOAD_PART), surface(0), file(file_), use_alpha(use_alpha_),
61 x(x_), y(y_), w(w_), h(h_)
64 SurfaceData::SurfaceData(Color top_gradient_, Color bottom_gradient_, int w_, int h_)
65 : type(GRADIENT), surface(0), use_alpha(false), w(w_), h(h_)
67 top_gradient = top_gradient_;
68 bottom_gradient = bottom_gradient_;
72 SurfaceData::~SurfaceData()
74 SDL_FreeSurface(surface);
82 return create_SurfaceOpenGL();
84 return create_SurfaceSDL();
86 return create_SurfaceSDL();
91 SurfaceData::create_SurfaceSDL()
96 return new SurfaceSDL(file, use_alpha);
98 return new SurfaceSDL(file, x, y, w, h, use_alpha);
100 return new SurfaceSDL(surface, use_alpha);
102 return new SurfaceSDL(top_gradient, bottom_gradient, w, h);
108 SurfaceData::create_SurfaceOpenGL()
114 return new SurfaceOpenGL(file, use_alpha);
116 return new SurfaceOpenGL(file, x, y, w, h, use_alpha);
118 return new SurfaceOpenGL(surface, use_alpha);
120 return new SurfaceOpenGL(top_gradient, bottom_gradient, w, h);
127 /* Quick utility function for texture creation */
128 static int power_of_two(int input)
132 while ( value < input )
140 Surface::Surface(SDL_Surface* surf, bool use_alpha)
141 : data(surf, use_alpha), w(0), h(0)
143 impl = data.create();
149 surfaces.push_back(this);
152 Surface::Surface(const std::string& file, bool use_alpha)
153 : data(file, use_alpha), w(0), h(0)
155 impl = data.create();
161 surfaces.push_back(this);
164 Surface::Surface(const std::string& file, int x, int y, int w, int h, bool use_alpha)
165 : data(file, x, y, w, h, use_alpha), w(0), h(0)
167 impl = data.create();
173 surfaces.push_back(this);
176 Surface::Surface(Color top_background, Color bottom_background, int w_, int h_)
177 : data(top_background, bottom_background, w_, h_), w(0), h(0)
179 impl = data.create();
185 surfaces.push_back(this);
192 impl = data.create();
197 for(std::vector<SurfaceData::Filter>::iterator i =
198 data.applied_filters.begin(); i != data.applied_filters.end();
200 impl->apply_filter(i->type, i->color);
204 void Surface::apply_filter(int filter, Color color)
206 impl->apply_filter(filter, color);
208 SurfaceData::Filter apply_filter;
209 apply_filter.type = filter;
210 apply_filter.color = color;
211 data.applied_filters.push_back(apply_filter);
218 for(std::list<Surface*>::iterator i = surfaces.begin(); i != surfaces.end();
227 printf("Error: Surface freed twice!!!\n");
229 surfaces.remove(this);
234 Surface::reload_all()
236 for(Surfaces::iterator i = surfaces.begin(); i != surfaces.end(); ++i)
243 Surface::debug_check()
245 for(Surfaces::iterator i = surfaces.begin(); i != surfaces.end(); ++i)
247 printf("Surface not freed: T:%d F:%s.\n", (*i)->data.type,
248 (*i)->data.file.c_str());
253 Surface::resize(int w_, int h_)
259 if (impl->resize(w_,h_) == -2)
265 apply_filter_to_surface(SDL_Surface* surface, int filter, Color color)
267 if(filter == HORIZONTAL_FLIP_FILTER)
269 SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true);
270 SDL_BlitSurface(surface, NULL, sur_copy, NULL);
271 SDL_SetAlpha(sur_copy,0,0);
276 src.h = dst.h = sur_copy->h;
277 for(int x = 0; x < sur_copy->w; x++)
279 src.x = x; dst.x = sur_copy->w-1 - x;
280 SDL_BlitSurface(sur_copy, &src, surface, &dst);
283 SDL_FreeSurface(sur_copy);
285 else if(filter == MASK_FILTER)
287 SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true);
291 SDL_LockSurface(sur_copy);
292 for(int x = 0; x < sur_copy->w; x++)
293 for(int y = 0; y < sur_copy->h; y++)
295 SDL_GetRGBA(getpixel(sur_copy,x,y), sur_copy->format, &r,&g,&b,&a);
298 putpixel(sur_copy, x,y, color.map_rgba(sur_copy));
301 SDL_UnlockSurface(sur_copy);
303 SDL_BlitSurface(sur_copy, NULL, surface, NULL);
304 SDL_FreeSurface(sur_copy);
309 sdl_surface_part_from_file(const std::string& file, int x, int y, int w, int h, bool use_alpha)
312 SDL_Surface * sdl_surface;
316 temp = IMG_Load(file.c_str());
319 Termination::abort("Can't load", file);
321 /* Set source rectangle for conv: */
328 conv = SDL_CreateRGBSurface(temp->flags, w, h, temp->format->BitsPerPixel,
332 temp->format->Amask);
334 /* #if SDL_BYTEORDER == SDL_BIG_ENDIAN
335 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
338 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
341 SDL_SetAlpha(temp,0,0);
343 SDL_BlitSurface(temp, &src, conv, NULL);
344 if(use_alpha == false && !use_gl)
345 sdl_surface = SDL_DisplayFormat(conv);
347 sdl_surface = SDL_DisplayFormatAlpha(conv);
349 if (sdl_surface == NULL)
350 Termination::abort("Can't covert to display format", file);
352 if (use_alpha == false && !use_gl)
353 SDL_SetAlpha(sdl_surface, 0, 0);
355 SDL_FreeSurface(temp);
356 SDL_FreeSurface(conv);
362 sdl_surface_from_file(const std::string& file, bool use_alpha)
364 SDL_Surface* sdl_surface;
367 temp = IMG_Load(file.c_str());
370 Termination::abort("Can't load", file);
372 if(use_alpha == false && !use_gl)
373 sdl_surface = SDL_DisplayFormat(temp);
375 sdl_surface = SDL_DisplayFormatAlpha(temp);
377 if (sdl_surface == NULL)
378 Termination::abort("Can't covert to display format", file);
380 if (use_alpha == false && !use_gl)
381 SDL_SetAlpha(sdl_surface, 0, 0);
383 SDL_FreeSurface(temp);
389 SuperTux::sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, bool use_alpha)
391 SDL_Surface* sdl_surface;
396 /* Save the alpha blending attributes */
397 saved_flags = sdl_surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
398 saved_alpha = sdl_surf->format->alpha;
399 if ( (saved_flags & SDL_SRCALPHA)
402 SDL_SetAlpha(sdl_surf, 0, 0);
406 if(use_alpha == false && !use_gl)
407 sdl_surface = SDL_DisplayFormat(sdl_surf);
409 sdl_surface = SDL_DisplayFormatAlpha(sdl_surf);
412 /* Restore the alpha blending attributes */
413 if ( (saved_flags & SDL_SRCALPHA)
416 SDL_SetAlpha(sdl_surface, saved_flags, saved_alpha);
420 if (sdl_surface == NULL)
421 Termination::abort("Can't covert to display format", "SURFACE");
423 if (use_alpha == false && !use_gl)
424 SDL_SetAlpha(sdl_surface, 0, 0);
430 sdl_surface_from_gradient(Color top, Color bottom, int w, int h)
432 SDL_Surface* sdl_surface;
434 sdl_surface = SDL_CreateRGBSurface(screen->flags, w, h,
435 screen->format->BitsPerPixel, screen->format->Rmask,
436 screen->format->Gmask, screen->format->Bmask, 0);
438 if(sdl_surface == NULL)
439 Termination::abort("Cannot create surface for the gradient", "SURFACE");
443 SDL_FillRect(sdl_surface, NULL, SDL_MapRGB(sdl_surface->format,
444 top.red, top.green, top.blue));
448 float redstep = (float(bottom.red)-float(top.red)) / float(h);
449 float greenstep = (float(bottom.green)-float(top.green)) / float(h);
450 float bluestep = (float(bottom.blue) - float(top.blue)) / float(h);
456 for(float y = 0; y < h; y++)
459 SDL_FillRect(sdl_surface, &rect, SDL_MapRGB(sdl_surface->format,
460 int(float(top.red) + redstep * y),
461 int(float(top.green) + greenstep * y),
462 int(float(top.blue) + bluestep * y)));
469 //---------------------------------------------------------------------------
471 SurfaceImpl::SurfaceImpl()
474 SurfaceImpl::~SurfaceImpl()
476 SDL_FreeSurface(sdl_surface);
479 SDL_Surface* SurfaceImpl::get_sdl_surface() const
484 int SurfaceImpl::resize(int w_, int h_)
493 int ret = SDL_SoftStretch(sdl_surface, NULL,
499 SurfaceOpenGL::SurfaceOpenGL(SDL_Surface* surf, bool use_alpha)
501 sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha);
502 create_gl(sdl_surface,&gl_texture);
508 SurfaceOpenGL::SurfaceOpenGL(const std::string& file, bool use_alpha)
510 sdl_surface = sdl_surface_from_file(file, use_alpha);
511 create_gl(sdl_surface,&gl_texture);
517 SurfaceOpenGL::SurfaceOpenGL(const std::string& file_, int x_, int y_, int w_, int h_, bool use_alpha_)
519 sdl_surface = sdl_surface_part_from_file(file_,x_,y_,w_,h_,use_alpha_);
521 create_gl(sdl_surface, &gl_texture);
527 SurfaceOpenGL::SurfaceOpenGL(Color top_gradient, Color bottom_gradient, int w, int h)
529 sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient, w, h);
530 create_gl(sdl_surface, &gl_texture);
536 SurfaceOpenGL::~SurfaceOpenGL()
538 glDeleteTextures(1, &gl_texture);
542 SurfaceOpenGL::create_gl(SDL_Surface * surf, GLuint * tex)
549 w = power_of_two(surf->w);
550 h = power_of_two(surf->h),
552 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
553 conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
554 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
556 conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
557 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
560 /* Save the alpha blending attributes */
561 saved_flags = surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
562 saved_alpha = surf->format->alpha;
563 if ( (saved_flags & SDL_SRCALPHA)
566 SDL_SetAlpha(surf, 0, 0);
569 SDL_BlitSurface(surf, 0, conv, 0);
571 /* Restore the alpha blending attributes */
572 if ( (saved_flags & SDL_SRCALPHA)
575 SDL_SetAlpha(surf, saved_flags, saved_alpha);
578 // We check all the pixels of the surface to figure out which
579 // internal format OpenGL should use for storing it, ie. if no alpha
580 // is present store in RGB instead of RGBA, this saves a few bytes
581 // of memory, but much more importantly it makes the game look
582 // *much* better in 16bit color mode
583 int internal_format = GL_RGB10_A2;
584 bool has_alpha = false;
586 unsigned char* buf = static_cast<unsigned char*>(conv->pixels);
587 for (int y = 0; y < surf->h; ++y)
588 for (int x = 0; x < surf->w; ++x)
590 if (buf[(conv->pitch*y + x*4) + 3] != 255)
599 internal_format = GL_RGB;
602 glGenTextures(1, &*tex);
603 glBindTexture(GL_TEXTURE_2D , *tex);
604 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
605 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
606 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
607 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
608 glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel);
609 glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels);
610 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
612 SDL_FreeSurface(conv);
616 SurfaceOpenGL::draw(float x, float y, Uint8 alpha, Uint32 effect)
618 float pw = power_of_two(w);
619 float ph = power_of_two(h);
621 if(effect & SEMI_TRANSPARENT)
624 glEnable(GL_TEXTURE_2D);
626 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
628 glColor4ub(alpha, alpha, alpha, alpha);
630 glBindTexture(GL_TEXTURE_2D, gl_texture);
634 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
637 glVertex2f((float)w+x, (float)h+y);
639 glTexCoord2f((float)w / pw, 0);
640 glVertex2f(x, (float)h+y);
642 glTexCoord2f((float)w / pw, (float)h / ph);
645 glTexCoord2f(0, (float)h / ph);
646 glVertex2f((float)w+x, y);
648 else if(effect & VERTICAL_FLIP)
651 glVertex2f(x, (float)h+y);
653 glTexCoord2f((float)w / pw, 0);
654 glVertex2f((float)w+x, (float)h+y);
656 glTexCoord2f((float)w / pw, (float)h / ph);
657 glVertex2f((float)w+x, y);
659 glTexCoord2f(0, (float)h / ph);
662 else if(effect & HORIZONTAL_FLIP)
665 glVertex2f((float)w+x, y);
667 glTexCoord2f((float)w / pw, 0);
670 glTexCoord2f((float)w / pw, (float)h / ph);
671 glVertex2f(x, (float)h+y);
673 glTexCoord2f(0, (float)h / ph);
674 glVertex2f((float)w+x, (float)h+y);
681 glTexCoord2f((float)w / pw, 0);
682 glVertex2f((float)w+x, y);
684 glTexCoord2f((float)w / pw, (float)h / ph);
685 glVertex2f((float)w+x, (float)h+y);
687 glTexCoord2f(0, (float)h / ph);
688 glVertex2f(x, (float)h+y);
692 glDisable(GL_TEXTURE_2D);
699 SurfaceOpenGL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect)
701 float pw = power_of_two(int(this->w));
702 float ph = power_of_two(int(this->h));
704 if(effect & SEMI_TRANSPARENT)
707 glBindTexture(GL_TEXTURE_2D, gl_texture);
710 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
712 glColor4ub(alpha, alpha, alpha, alpha);
714 glEnable(GL_TEXTURE_2D);
719 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
721 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
722 glVertex2f((float)w+x, (float)h+y);
724 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
725 glVertex2f(x, (float)h+y);
727 glTexCoord2f((float)(sx + w) / pw, sy / ph);
730 glTexCoord2f(sx / pw, sy / ph);
731 glVertex2f((float)w+x, y);
733 else if(effect & VERTICAL_FLIP)
735 glTexCoord2f(sx / pw, sy / ph);
738 glTexCoord2f((float)(sx + w) / pw, sy / ph);
741 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
742 glVertex2f(w +x, h+y);
744 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
747 else if(effect & HORIZONTAL_FLIP)
749 glTexCoord2f(sx / pw, sy / ph);
750 glVertex2f((float)w+x, y);
752 glTexCoord2f((float)(sx + w) / pw, sy / ph);
755 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
756 glVertex2f(x, (float)h+y);
758 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
759 glVertex2f((float)w+x, (float)h+y);
763 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
766 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
767 glVertex2f(w +x, h+y);
769 glTexCoord2f((float)(sx + w) / pw, sy / ph);
772 glTexCoord2f(sx / pw, sy / ph);
778 glDisable(GL_TEXTURE_2D);
785 SurfaceOpenGL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uint32 effect)
787 float pw = power_of_two(sw);
788 float ph = power_of_two(sh);
790 if(effect & SEMI_TRANSPARENT)
793 glEnable(GL_TEXTURE_2D);
795 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
797 glColor4ub(alpha, alpha, alpha, alpha);
799 glBindTexture(GL_TEXTURE_2D, gl_texture);
803 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
806 glVertex2f((float)sw+x, (float)sh+y);
808 glTexCoord2f((float)w / pw, 0);
809 glVertex2f(x, (float)sh+y);
811 glTexCoord2f((float)w / pw, (float)h / ph);
814 glTexCoord2f(0, (float)h / ph);
815 glVertex2f((float)sw+x, y);
817 else if(effect & VERTICAL_FLIP)
820 glVertex2f(x, (float)sh+y);
822 glTexCoord2f((float)w / pw, 0);
823 glVertex2f((float)sw+x, (float)sh+y);
825 glTexCoord2f((float)w / pw, (float)h / ph);
826 glVertex2f((float)sw+x, y);
828 glTexCoord2f(0, (float)h / ph);
831 else if(effect & HORIZONTAL_FLIP)
834 glVertex2f((float)sw+x, y);
836 glTexCoord2f((float)w / pw, 0);
839 glTexCoord2f((float)w / pw, (float)h / ph);
840 glVertex2f(x, (float)sh+y);
842 glTexCoord2f(0, (float)h / ph);
843 glVertex2f((float)sw+x, (float)sh+y);
850 glTexCoord2f((float)w / pw, 0);
851 glVertex2f((float)sw+x, y);
853 glTexCoord2f((float)w / pw, (float)h / ph);
854 glVertex2f((float)sw+x, (float)sh+y);
856 glTexCoord2f(0, (float)h / ph);
857 glVertex2f(x, (float)sh+y);
861 glDisable(GL_TEXTURE_2D);
868 SurfaceOpenGL::apply_filter(int filter, Color color)
870 ::apply_filter_to_surface(sdl_surface, filter, color);
871 create_gl(sdl_surface,&gl_texture);
879 SurfaceSDL::SurfaceSDL(SDL_Surface* surf, bool use_alpha)
881 sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha);
886 SurfaceSDL::SurfaceSDL(const std::string& file, bool use_alpha)
888 sdl_surface = sdl_surface_from_file(file, use_alpha);
893 SurfaceSDL::SurfaceSDL(const std::string& file, int x, int y, int w, int h, bool use_alpha)
895 sdl_surface = sdl_surface_part_from_file(file, x, y, w, h, use_alpha);
900 SurfaceSDL::SurfaceSDL(Color top_gradient, Color bottom_gradient, int w, int h)
902 sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient, w, h);
908 SurfaceSDL::draw(float x, float y, Uint8 alpha, Uint32 effect)
917 if(effect & SEMI_TRANSPARENT)
920 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
922 // FIXME: this hack is damn slow. Just keep it cause it isn't that used.
923 for(float sx = 0; sx < w; sx++)
924 for(float sy = 0; sy < h; sy++)
925 if(draw_part(sx, sy, x+(w-sx), y+(h-sy), 1, 1, alpha, NONE_EFFECT) == -2)
929 else if(effect & VERTICAL_FLIP) // FIXME: feel free to replace this hack
931 for(float sy = 0; sy < h; sy++)
932 if(draw_part(0, sy, x, y+(h-sy), w, 1, alpha, NONE_EFFECT) == -2)
936 else if(effect & HORIZONTAL_FLIP) // FIXME: feel free to replace this hack
938 for(float sx = 0; sx < w; sx++)
939 if(draw_part(sx, 0, x+(w-sx), y, 1, h, alpha, NONE_EFFECT) == -2)
946 /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha
947 to temp sur, blit the temp into the screen */
948 /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that
949 already have an alpha mask yet... */
951 SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
952 sdl_surface->w, sdl_surface->h, sdl_surface->format->BitsPerPixel,
953 sdl_surface->format->Rmask, sdl_surface->format->Gmask,
954 sdl_surface->format->Bmask,
956 int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255);
957 SDL_FillRect(sdl_surface_copy, NULL, colorkey);
958 SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey);
961 SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
962 SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha);
964 int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest);
966 SDL_FreeSurface (sdl_surface_copy);
970 int ret = SDL_BlitSurface(sdl_surface, NULL, screen, &dest);
976 SurfaceSDL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect)
990 if(effect & SEMI_TRANSPARENT)
993 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
995 // FIXME: this hack is damn slow. Just keep it cause it isn't that used.
996 for(float sx_ = 0; sx_ < w; sx++)
997 for(float sy_ = 0; sy_ < h; sy++)
998 if(draw_part(sx_, sy_, sx+(w-sx_), sy+(h-sy_), 1, 1, alpha, NONE_EFFECT) == -2)
1002 else if(effect & VERTICAL_FLIP) // FIXME: feel free to replace this hack
1004 for(float sy_ = sy; sy_ < h; sy_++)
1005 if(draw_part(sx, sy_, x, y+(h-sy_), w, 1, alpha, NONE_EFFECT) == -2)
1009 else if(effect & HORIZONTAL_FLIP) // FIXME: feel free to replace this hack
1011 for(float sx_ = 0; sx_ < w; sx_++)
1012 if(draw_part(sx_, 0, sx+(w-sx_), sy, 1, h, alpha, NONE_EFFECT) == -2)
1019 /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha
1020 to temp sur, blit the temp into the screen */
1021 /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that
1022 already have an alpha mask, yet... */
1024 SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
1025 (int)w, (int)h, sdl_surface->format->BitsPerPixel,
1026 sdl_surface->format->Rmask, sdl_surface->format->Gmask,
1027 sdl_surface->format->Bmask,
1029 int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255);
1030 SDL_FillRect(sdl_surface_copy, NULL, colorkey);
1031 SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey);
1034 SDL_BlitSurface(sdl_surface, &src, sdl_surface_copy, NULL);
1035 SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha);
1037 int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest);
1039 SDL_FreeSurface (sdl_surface_copy);
1043 int ret = SDL_BlitSurface(sdl_surface, &src, screen, &dest);
1049 SurfaceSDL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uint32 effect)
1058 if(effect & SEMI_TRANSPARENT)
1061 SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
1062 sw, sh, sdl_surface->format->BitsPerPixel,
1063 sdl_surface->format->Rmask, sdl_surface->format->Gmask,
1064 sdl_surface->format->Bmask,
1067 SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
1068 SDL_SoftStretch(sdl_surface_copy, NULL, sdl_surface_copy, &dest);
1071 SDL_SetAlpha(sdl_surface_copy,SDL_SRCALPHA,alpha);
1073 int ret = SDL_BlitSurface(sdl_surface_copy,NULL,screen,&dest);
1074 SDL_FreeSurface(sdl_surface_copy);
1080 SurfaceSDL::apply_filter(int filter, Color color)
1082 ::apply_filter_to_surface(sdl_surface, filter, color);
1088 SurfaceSDL::~SurfaceSDL()