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
28 #include "SDL_image.h"
30 #include "../video/surface.h"
31 #include "../video/screen.h"
32 #include "../app/globals.h"
33 #include "../app/setup.h"
35 using namespace SuperTux;
37 Surface::Surfaces Surface::surfaces;
39 SurfaceData::SurfaceData(SDL_Surface* temp, bool use_alpha_)
40 : type(SURFACE), surface(0), use_alpha(use_alpha_)
42 // Copy the given surface and make sure that it is not stored in
44 surface = SDL_CreateRGBSurface(temp->flags & (~SDL_HWSURFACE),
46 temp->format->BitsPerPixel,
52 Termination::abort("No memory left.", "");
53 SDL_SetAlpha(temp,0,0);
54 SDL_BlitSurface(temp, NULL, surface, NULL);
57 SurfaceData::SurfaceData(const std::string& file_, bool use_alpha_)
58 : type(LOAD), surface(0), file(file_), use_alpha(use_alpha_)
61 SurfaceData::SurfaceData(const std::string& file_, int x_, int y_,
62 int w_, int h_, bool use_alpha_)
63 : type(LOAD_PART), surface(0), file(file_), use_alpha(use_alpha_),
64 x(x_), y(y_), w(w_), h(h_)
67 SurfaceData::SurfaceData(Color top_gradient_, Color bottom_gradient_,
69 : type(GRADIENT), surface(0), use_alpha(false), w(w_), h(h_)
71 top_gradient = top_gradient_;
72 bottom_gradient = bottom_gradient_;
76 SurfaceData::~SurfaceData()
78 SDL_FreeSurface(surface);
86 return create_SurfaceOpenGL();
88 return create_SurfaceSDL();
90 return create_SurfaceSDL();
95 SurfaceData::create_SurfaceSDL()
100 return new SurfaceSDL(file, use_alpha);
102 return new SurfaceSDL(file, x, y, w, h, use_alpha);
104 return new SurfaceSDL(surface, use_alpha);
106 return new SurfaceSDL(top_gradient, bottom_gradient, w, h);
112 SurfaceData::create_SurfaceOpenGL()
118 return new SurfaceOpenGL(file, use_alpha);
120 return new SurfaceOpenGL(file, x, y, w, h, use_alpha);
122 return new SurfaceOpenGL(surface, use_alpha);
124 return new SurfaceOpenGL(top_gradient, bottom_gradient, w, h);
131 /* Quick utility function for texture creation */
132 static int power_of_two(int input)
136 while ( value < input )
144 Surface::Surface(SDL_Surface* surf, bool use_alpha)
145 : data(surf, use_alpha), w(0), h(0)
147 impl = data.create();
153 surfaces.push_back(this);
156 Surface::Surface(const std::string& file, bool use_alpha)
157 : data(file, use_alpha), w(0), h(0)
159 impl = data.create();
165 surfaces.push_back(this);
168 Surface::Surface(const std::string& file, int x, int y, int w, int h, bool use_alpha)
169 : data(file, x, y, w, h, use_alpha), w(0), h(0)
171 impl = data.create();
177 surfaces.push_back(this);
180 Surface::Surface(Color top_background, Color bottom_background, int w_, int h_)
181 : data(top_background, bottom_background, w_, h_), w(0), h(0)
183 impl = data.create();
189 surfaces.push_back(this);
196 impl = data.create();
201 for(std::vector<SurfaceData::Filter>::iterator i =
202 data.applied_filters.begin(); i != data.applied_filters.end();
204 impl->apply_filter(i->type, i->color);
208 void Surface::apply_filter(int filter, Color color)
210 impl->apply_filter(filter, color);
212 SurfaceData::Filter apply_filter;
213 apply_filter.type = filter;
214 apply_filter.color = color;
215 data.applied_filters.push_back(apply_filter);
222 for(std::list<Surface*>::iterator i = surfaces.begin(); i != surfaces.end();
231 printf("Error: Surface freed twice!!!\n");
233 surfaces.remove(this);
238 Surface::reload_all()
240 for(Surfaces::iterator i = surfaces.begin(); i != surfaces.end(); ++i)
247 Surface::debug_check()
249 for(Surfaces::iterator i = surfaces.begin(); i != surfaces.end(); ++i)
251 printf("Surface not freed: T:%d F:%s.\n", (*i)->data.type,
252 (*i)->data.file.c_str());
257 Surface::resize(int w_, int h_)
263 if (impl->resize(w_,h_) == -2)
269 apply_filter_to_surface(SDL_Surface* surface, int filter, Color color)
271 if(filter == HORIZONTAL_FLIP_FILTER)
273 SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true);
274 SDL_BlitSurface(surface, NULL, sur_copy, NULL);
275 SDL_SetAlpha(sur_copy,0,0);
280 src.h = dst.h = sur_copy->h;
281 for(int x = 0; x < sur_copy->w; x++)
283 src.x = x; dst.x = sur_copy->w-1 - x;
284 SDL_BlitSurface(sur_copy, &src, surface, &dst);
287 SDL_FreeSurface(sur_copy);
289 else if(filter == MASK_FILTER)
291 SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true);
295 SDL_LockSurface(sur_copy);
296 for(int x = 0; x < sur_copy->w; x++)
297 for(int y = 0; y < sur_copy->h; y++)
299 SDL_GetRGBA(getpixel(sur_copy,x,y), sur_copy->format, &r,&g,&b,&a);
302 putpixel(sur_copy, x,y, color.map_rgba(sur_copy));
305 SDL_UnlockSurface(sur_copy);
307 SDL_BlitSurface(sur_copy, NULL, surface, NULL);
308 SDL_FreeSurface(sur_copy);
313 sdl_surface_part_from_file(const std::string& file, int x, int y, int w, int h, bool use_alpha)
316 SDL_Surface * sdl_surface;
320 temp = IMG_Load(file.c_str());
323 Termination::abort("Can't load", file);
325 /* Set source rectangle for conv: */
332 conv = SDL_CreateRGBSurface(temp->flags, w, h, temp->format->BitsPerPixel,
336 temp->format->Amask);
338 /* #if SDL_BYTEORDER == SDL_BIG_ENDIAN
339 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
342 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
345 SDL_SetAlpha(temp,0,0);
347 SDL_BlitSurface(temp, &src, conv, NULL);
348 if(use_alpha == false && !use_gl)
349 sdl_surface = SDL_DisplayFormat(conv);
351 sdl_surface = SDL_DisplayFormatAlpha(conv);
353 if (sdl_surface == NULL)
354 Termination::abort("Can't covert to display format", file);
356 if (use_alpha == false && !use_gl)
357 SDL_SetAlpha(sdl_surface, 0, 0);
359 SDL_FreeSurface(temp);
360 SDL_FreeSurface(conv);
366 sdl_surface_from_file(const std::string& file, bool use_alpha)
368 SDL_Surface* sdl_surface;
371 temp = IMG_Load(file.c_str());
374 Termination::abort("Can't load", file);
376 if(use_alpha == false && !use_gl)
377 sdl_surface = SDL_DisplayFormat(temp);
379 sdl_surface = SDL_DisplayFormatAlpha(temp);
381 if (sdl_surface == NULL)
382 Termination::abort("Can't covert to display format", file);
384 if (use_alpha == false && !use_gl)
385 SDL_SetAlpha(sdl_surface, 0, 0);
387 SDL_FreeSurface(temp);
393 SuperTux::sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, bool use_alpha)
395 SDL_Surface* sdl_surface;
400 /* Save the alpha blending attributes */
401 saved_flags = sdl_surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
402 saved_alpha = sdl_surf->format->alpha;
403 if ( (saved_flags & SDL_SRCALPHA)
406 SDL_SetAlpha(sdl_surf, 0, 0);
410 if(use_alpha == false && !use_gl)
411 sdl_surface = SDL_DisplayFormat(sdl_surf);
413 sdl_surface = SDL_DisplayFormatAlpha(sdl_surf);
416 /* Restore the alpha blending attributes */
417 if ( (saved_flags & SDL_SRCALPHA)
420 SDL_SetAlpha(sdl_surface, saved_flags, saved_alpha);
424 if (sdl_surface == NULL)
425 Termination::abort("Can't covert to display format", "SURFACE");
427 if (use_alpha == false && !use_gl)
428 SDL_SetAlpha(sdl_surface, 0, 0);
434 sdl_surface_from_gradient(Color top, Color bottom, int w, int h)
436 SDL_Surface* sdl_surface
437 = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h,
438 screen->format->BitsPerPixel, screen->format->Rmask,
439 screen->format->Gmask, screen->format->Bmask, 0);
442 Termination::abort("Cannot create surface for the gradient", "SURFACE");
445 SDL_FillRect(sdl_surface, NULL, SDL_MapRGB(sdl_surface->format,
446 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++) {
458 SDL_FillRect(sdl_surface, &rect, SDL_MapRGB(sdl_surface->format,
459 int(float(top.red) + redstep * y),
460 int(float(top.green) + greenstep * y),
461 int(float(top.blue) + bluestep * y)));
468 //---------------------------------------------------------------------------
470 SurfaceImpl::SurfaceImpl()
473 SurfaceImpl::~SurfaceImpl()
475 SDL_FreeSurface(sdl_surface);
478 SDL_Surface* SurfaceImpl::get_sdl_surface() const
483 int SurfaceImpl::resize(int w_, int h_)
492 int ret = SDL_SoftStretch(sdl_surface, NULL,
498 SurfaceOpenGL::SurfaceOpenGL(SDL_Surface* surf, bool use_alpha)
500 sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha);
501 create_gl(sdl_surface,&gl_texture);
507 SurfaceOpenGL::SurfaceOpenGL(const std::string& file, bool use_alpha)
509 sdl_surface = sdl_surface_from_file(file, use_alpha);
510 create_gl(sdl_surface,&gl_texture);
516 SurfaceOpenGL::SurfaceOpenGL(const std::string& file_, int x_, int y_,
517 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);
526 SurfaceOpenGL::SurfaceOpenGL(Color top_gradient, Color bottom_gradient,
529 sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient,_w,_h);
530 create_gl(sdl_surface, &gl_texture);
535 SurfaceOpenGL::~SurfaceOpenGL()
537 glDeleteTextures(1, &gl_texture);
541 SurfaceOpenGL::create_gl(SDL_Surface * surf, GLuint * tex)
548 w = power_of_two(surf->w);
549 h = power_of_two(surf->h),
551 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
552 conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
553 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
555 conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
556 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
559 /* Save the alpha blending attributes */
560 saved_flags = surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
561 saved_alpha = surf->format->alpha;
562 if ( (saved_flags & SDL_SRCALPHA)
565 SDL_SetAlpha(surf, 0, 0);
568 SDL_BlitSurface(surf, 0, conv, 0);
570 /* Restore the alpha blending attributes */
571 if ( (saved_flags & SDL_SRCALPHA)
574 SDL_SetAlpha(surf, saved_flags, saved_alpha);
577 // We check all the pixels of the surface to figure out which
578 // internal format OpenGL should use for storing it, ie. if no alpha
579 // is present store in RGB instead of RGBA, this saves a few bytes
580 // of memory, but much more importantly it makes the game look
581 // *much* better in 16bit color mode
582 int internal_format = GL_RGB10_A2;
583 bool has_alpha = false;
585 unsigned char* buf = static_cast<unsigned char*>(conv->pixels);
586 for (int y = 0; y < surf->h; ++y)
587 for (int x = 0; x < surf->w; ++x)
589 if (buf[(conv->pitch*y + x*4) + 3] != 255)
598 internal_format = GL_RGB;
601 glGenTextures(1, &*tex);
602 glBindTexture(GL_TEXTURE_2D , *tex);
603 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
604 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
605 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
606 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
607 glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel);
608 glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels);
609 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
611 SDL_FreeSurface(conv);
615 SurfaceOpenGL::draw(float x, float y, Uint8 alpha, Uint32 effect)
617 float pw = power_of_two(w);
618 float ph = power_of_two(h);
620 if(effect & SEMI_TRANSPARENT)
623 glEnable(GL_TEXTURE_2D);
625 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
627 glColor4ub(alpha, alpha, alpha, alpha);
629 glBindTexture(GL_TEXTURE_2D, gl_texture);
633 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
636 glVertex2f((float)w+x, (float)h+y);
638 glTexCoord2f((float)w / pw, 0);
639 glVertex2f(x, (float)h+y);
641 glTexCoord2f((float)w / pw, (float)h / ph);
644 glTexCoord2f(0, (float)h / ph);
645 glVertex2f((float)w+x, y);
647 else if(effect & VERTICAL_FLIP)
650 glVertex2f(x, (float)h+y);
652 glTexCoord2f((float)w / pw, 0);
653 glVertex2f((float)w+x, (float)h+y);
655 glTexCoord2f((float)w / pw, (float)h / ph);
656 glVertex2f((float)w+x, y);
658 glTexCoord2f(0, (float)h / ph);
661 else if(effect & HORIZONTAL_FLIP)
664 glVertex2f((float)w+x, y);
666 glTexCoord2f((float)w / pw, 0);
669 glTexCoord2f((float)w / pw, (float)h / ph);
670 glVertex2f(x, (float)h+y);
672 glTexCoord2f(0, (float)h / ph);
673 glVertex2f((float)w+x, (float)h+y);
680 glTexCoord2f((float)w / pw, 0);
681 glVertex2f((float)w+x, y);
683 glTexCoord2f((float)w / pw, (float)h / ph);
684 glVertex2f((float)w+x, (float)h+y);
686 glTexCoord2f(0, (float)h / ph);
687 glVertex2f(x, (float)h+y);
691 glDisable(GL_TEXTURE_2D);
698 SurfaceOpenGL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect)
700 float pw = power_of_two(int(this->w));
701 float ph = power_of_two(int(this->h));
703 if(effect & SEMI_TRANSPARENT)
706 glBindTexture(GL_TEXTURE_2D, gl_texture);
709 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
711 glColor4ub(alpha, alpha, alpha, alpha);
713 glEnable(GL_TEXTURE_2D);
718 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
720 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
721 glVertex2f((float)w+x, (float)h+y);
723 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
724 glVertex2f(x, (float)h+y);
726 glTexCoord2f((float)(sx + w) / pw, sy / ph);
729 glTexCoord2f(sx / pw, sy / ph);
730 glVertex2f((float)w+x, y);
732 else if(effect & VERTICAL_FLIP)
734 glTexCoord2f(sx / pw, sy / ph);
737 glTexCoord2f((float)(sx + w) / pw, sy / ph);
740 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
741 glVertex2f(w +x, h+y);
743 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
746 else if(effect & HORIZONTAL_FLIP)
748 glTexCoord2f(sx / pw, sy / ph);
749 glVertex2f((float)w+x, y);
751 glTexCoord2f((float)(sx + w) / pw, sy / ph);
754 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
755 glVertex2f(x, (float)h+y);
757 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
758 glVertex2f((float)w+x, (float)h+y);
762 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
765 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
766 glVertex2f(w +x, h+y);
768 glTexCoord2f((float)(sx + w) / pw, sy / ph);
771 glTexCoord2f(sx / pw, sy / ph);
777 glDisable(GL_TEXTURE_2D);
784 SurfaceOpenGL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uint32 effect)
786 float pw = power_of_two(sw);
787 float ph = power_of_two(sh);
789 if(effect & SEMI_TRANSPARENT)
792 glEnable(GL_TEXTURE_2D);
794 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
796 glColor4ub(alpha, alpha, alpha, alpha);
798 glBindTexture(GL_TEXTURE_2D, gl_texture);
802 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
805 glVertex2f((float)sw+x, (float)sh+y);
807 glTexCoord2f((float)w / pw, 0);
808 glVertex2f(x, (float)sh+y);
810 glTexCoord2f((float)w / pw, (float)h / ph);
813 glTexCoord2f(0, (float)h / ph);
814 glVertex2f((float)sw+x, y);
816 else if(effect & VERTICAL_FLIP)
819 glVertex2f(x, (float)sh+y);
821 glTexCoord2f((float)w / pw, 0);
822 glVertex2f((float)sw+x, (float)sh+y);
824 glTexCoord2f((float)w / pw, (float)h / ph);
825 glVertex2f((float)sw+x, y);
827 glTexCoord2f(0, (float)h / ph);
830 else if(effect & HORIZONTAL_FLIP)
833 glVertex2f((float)sw+x, y);
835 glTexCoord2f((float)w / pw, 0);
838 glTexCoord2f((float)w / pw, (float)h / ph);
839 glVertex2f(x, (float)sh+y);
841 glTexCoord2f(0, (float)h / ph);
842 glVertex2f((float)sw+x, (float)sh+y);
849 glTexCoord2f((float)w / pw, 0);
850 glVertex2f((float)sw+x, y);
852 glTexCoord2f((float)w / pw, (float)h / ph);
853 glVertex2f((float)sw+x, (float)sh+y);
855 glTexCoord2f(0, (float)h / ph);
856 glVertex2f(x, (float)sh+y);
860 glDisable(GL_TEXTURE_2D);
867 SurfaceOpenGL::apply_filter(int filter, Color color)
869 ::apply_filter_to_surface(sdl_surface, filter, color);
870 create_gl(sdl_surface,&gl_texture);
878 SurfaceSDL::SurfaceSDL(SDL_Surface* surf, bool use_alpha)
880 sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha);
885 SurfaceSDL::SurfaceSDL(const std::string& file, bool use_alpha)
887 sdl_surface = sdl_surface_from_file(file, use_alpha);
892 SurfaceSDL::SurfaceSDL(const std::string& file, int x, int y, int _w, int _h,
895 sdl_surface = sdl_surface_part_from_file(file, x, y, _w, _h, use_alpha);
900 SurfaceSDL::SurfaceSDL(Color top_gradient, Color bottom_gradient,
903 sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient,_w,_h);
909 SurfaceSDL::draw(float x, float y, Uint8 alpha, Uint32 effect)
918 if(effect & SEMI_TRANSPARENT)
921 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
923 // FIXME: this hack is damn slow. Just keep it cause it isn't that used.
924 for(float sx = 0; sx < w; sx++)
925 for(float sy = 0; sy < h; sy++)
926 if(draw_part(sx, sy, x+(w-sx), y+(h-sy), 1, 1, alpha, NONE_EFFECT) == -2)
930 else if(effect & VERTICAL_FLIP) // FIXME: feel free to replace this hack
932 for(float sy = 0; sy < h; sy++)
933 if(draw_part(0, sy, x, y+(h-sy), w, 1, alpha, NONE_EFFECT) == -2)
937 else if(effect & HORIZONTAL_FLIP) // FIXME: feel free to replace this hack
939 for(float sx = 0; sx < w; sx++)
940 if(draw_part(sx, 0, x+(w-sx), y, 1, h, alpha, NONE_EFFECT) == -2)
947 /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha
948 to temp sur, blit the temp into the screen */
949 /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that
950 already have an alpha mask yet... */
952 SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
953 sdl_surface->w, sdl_surface->h, sdl_surface->format->BitsPerPixel,
954 sdl_surface->format->Rmask, sdl_surface->format->Gmask,
955 sdl_surface->format->Bmask,
957 int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255);
958 SDL_FillRect(sdl_surface_copy, NULL, colorkey);
959 SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey);
962 SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
963 SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha);
965 int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest);
967 SDL_FreeSurface (sdl_surface_copy);
971 int ret = SDL_BlitSurface(sdl_surface, NULL, screen, &dest);
977 SurfaceSDL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect)
991 if(effect & SEMI_TRANSPARENT)
994 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
996 // FIXME: this hack is damn slow. Just keep it cause it isn't that used.
997 for(float sx_ = 0; sx_ < w; sx++)
998 for(float sy_ = 0; sy_ < h; sy++)
999 if(draw_part(sx_, sy_, sx+(w-sx_), sy+(h-sy_), 1, 1, alpha, NONE_EFFECT) == -2)
1003 else if(effect & VERTICAL_FLIP) // FIXME: feel free to replace this hack
1005 for(float sy_ = sy; sy_ < h; sy_++)
1006 if(draw_part(sx, sy_, x, y+(h-sy_), w, 1, alpha, NONE_EFFECT) == -2)
1010 else if(effect & HORIZONTAL_FLIP) // FIXME: feel free to replace this hack
1012 for(float sx_ = 0; sx_ < w; sx_++)
1013 if(draw_part(sx_, 0, sx+(w-sx_), sy, 1, h, alpha, NONE_EFFECT) == -2)
1020 /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha
1021 to temp sur, blit the temp into the screen */
1022 /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that
1023 already have an alpha mask, yet... */
1025 SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
1026 (int)w, (int)h, sdl_surface->format->BitsPerPixel,
1027 sdl_surface->format->Rmask, sdl_surface->format->Gmask,
1028 sdl_surface->format->Bmask,
1030 int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255);
1031 SDL_FillRect(sdl_surface_copy, NULL, colorkey);
1032 SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey);
1035 SDL_BlitSurface(sdl_surface, &src, sdl_surface_copy, NULL);
1036 SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha);
1038 int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest);
1040 SDL_FreeSurface (sdl_surface_copy);
1044 int ret = SDL_BlitSurface(sdl_surface, &src, screen, &dest);
1050 SurfaceSDL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uint32 effect)
1059 if(effect & SEMI_TRANSPARENT)
1062 SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
1063 sw, sh, sdl_surface->format->BitsPerPixel,
1064 sdl_surface->format->Rmask, sdl_surface->format->Gmask,
1065 sdl_surface->format->Bmask,
1068 SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
1069 SDL_SoftStretch(sdl_surface_copy, NULL, sdl_surface_copy, &dest);
1072 SDL_SetAlpha(sdl_surface_copy,SDL_SRCALPHA,alpha);
1074 int ret = SDL_BlitSurface(sdl_surface_copy,NULL,screen,&dest);
1075 SDL_FreeSurface(sdl_surface_copy);
1081 SurfaceSDL::apply_filter(int filter, Color color)
1083 ::apply_filter_to_surface(sdl_surface, filter, color);
1089 SurfaceSDL::~SurfaceSDL()