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_, int w_, int h_, bool use_alpha_)
62 : type(LOAD_PART), surface(0), file(file_), use_alpha(use_alpha_),
63 x(x_), y(y_), w(w_), h(h_)
66 SurfaceData::SurfaceData(Color top_gradient_, Color bottom_gradient_, int w_, int h_)
67 : type(GRADIENT), surface(0), use_alpha(false), w(w_), h(h_)
69 top_gradient = top_gradient_;
70 bottom_gradient = bottom_gradient_;
74 SurfaceData::~SurfaceData()
76 SDL_FreeSurface(surface);
84 return create_SurfaceOpenGL();
86 return create_SurfaceSDL();
88 return create_SurfaceSDL();
93 SurfaceData::create_SurfaceSDL()
98 return new SurfaceSDL(file, use_alpha);
100 return new SurfaceSDL(file, x, y, w, h, use_alpha);
102 return new SurfaceSDL(surface, use_alpha);
104 return new SurfaceSDL(top_gradient, bottom_gradient, w, h);
110 SurfaceData::create_SurfaceOpenGL()
116 return new SurfaceOpenGL(file, use_alpha);
118 return new SurfaceOpenGL(file, x, y, w, h, use_alpha);
120 return new SurfaceOpenGL(surface, use_alpha);
122 return new SurfaceOpenGL(top_gradient, bottom_gradient, w, h);
129 /* Quick utility function for texture creation */
130 static int power_of_two(int input)
134 while ( value < input )
142 Surface::Surface(SDL_Surface* surf, bool use_alpha)
143 : data(surf, use_alpha), w(0), h(0)
145 impl = data.create();
151 surfaces.push_back(this);
154 Surface::Surface(const std::string& file, bool use_alpha)
155 : data(file, use_alpha), w(0), h(0)
157 impl = data.create();
163 surfaces.push_back(this);
166 Surface::Surface(const std::string& file, int x, int y, int w, int h, bool use_alpha)
167 : data(file, x, y, w, h, use_alpha), w(0), h(0)
169 impl = data.create();
175 surfaces.push_back(this);
178 Surface::Surface(Color top_background, Color bottom_background, int w_, int h_)
179 : data(top_background, bottom_background, w_, h_), w(0), h(0)
181 impl = data.create();
187 surfaces.push_back(this);
194 impl = data.create();
199 for(std::vector<SurfaceData::Filter>::iterator i =
200 data.applied_filters.begin(); i != data.applied_filters.end();
202 impl->apply_filter(i->type, i->color);
206 void Surface::apply_filter(int filter, Color color)
208 impl->apply_filter(filter, color);
210 SurfaceData::Filter apply_filter;
211 apply_filter.type = filter;
212 apply_filter.color = color;
213 data.applied_filters.push_back(apply_filter);
220 for(std::list<Surface*>::iterator i = surfaces.begin(); i != surfaces.end();
229 printf("Error: Surface freed twice!!!\n");
231 surfaces.remove(this);
236 Surface::reload_all()
238 for(Surfaces::iterator i = surfaces.begin(); i != surfaces.end(); ++i)
245 Surface::debug_check()
247 for(Surfaces::iterator i = surfaces.begin(); i != surfaces.end(); ++i)
249 printf("Surface not freed: T:%d F:%s.\n", (*i)->data.type,
250 (*i)->data.file.c_str());
255 Surface::resize(int w_, int h_)
261 if (impl->resize(w_,h_) == -2)
267 apply_filter_to_surface(SDL_Surface* surface, int filter, Color color)
269 if(filter == HORIZONTAL_FLIP_FILTER)
271 SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true);
272 SDL_BlitSurface(surface, NULL, sur_copy, NULL);
273 SDL_SetAlpha(sur_copy,0,0);
278 src.h = dst.h = sur_copy->h;
279 for(int x = 0; x < sur_copy->w; x++)
281 src.x = x; dst.x = sur_copy->w-1 - x;
282 SDL_BlitSurface(sur_copy, &src, surface, &dst);
285 SDL_FreeSurface(sur_copy);
287 else if(filter == MASK_FILTER)
289 SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true);
293 SDL_LockSurface(sur_copy);
294 for(int x = 0; x < sur_copy->w; x++)
295 for(int y = 0; y < sur_copy->h; y++)
297 SDL_GetRGBA(getpixel(sur_copy,x,y), sur_copy->format, &r,&g,&b,&a);
300 putpixel(sur_copy, x,y, color.map_rgba(sur_copy));
303 SDL_UnlockSurface(sur_copy);
305 SDL_BlitSurface(sur_copy, NULL, surface, NULL);
306 SDL_FreeSurface(sur_copy);
311 sdl_surface_part_from_file(const std::string& file, int x, int y, int w, int h, bool use_alpha)
314 SDL_Surface * sdl_surface;
318 temp = IMG_Load(file.c_str());
321 Termination::abort("Can't load", file);
323 /* Set source rectangle for conv: */
330 conv = SDL_CreateRGBSurface(temp->flags, w, h, temp->format->BitsPerPixel,
334 temp->format->Amask);
336 /* #if SDL_BYTEORDER == SDL_BIG_ENDIAN
337 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
340 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
343 SDL_SetAlpha(temp,0,0);
345 SDL_BlitSurface(temp, &src, conv, NULL);
346 if(use_alpha == false && !use_gl)
347 sdl_surface = SDL_DisplayFormat(conv);
349 sdl_surface = SDL_DisplayFormatAlpha(conv);
351 if (sdl_surface == NULL)
352 Termination::abort("Can't covert to display format", file);
354 if (use_alpha == false && !use_gl)
355 SDL_SetAlpha(sdl_surface, 0, 0);
357 SDL_FreeSurface(temp);
358 SDL_FreeSurface(conv);
364 sdl_surface_from_file(const std::string& file, bool use_alpha)
366 SDL_Surface* sdl_surface;
369 temp = IMG_Load(file.c_str());
372 Termination::abort("Can't load", file);
374 if(use_alpha == false && !use_gl)
375 sdl_surface = SDL_DisplayFormat(temp);
377 sdl_surface = SDL_DisplayFormatAlpha(temp);
379 if (sdl_surface == NULL)
380 Termination::abort("Can't covert to display format", file);
382 if (use_alpha == false && !use_gl)
383 SDL_SetAlpha(sdl_surface, 0, 0);
385 SDL_FreeSurface(temp);
391 SuperTux::sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, bool use_alpha)
393 SDL_Surface* sdl_surface;
398 /* Save the alpha blending attributes */
399 saved_flags = sdl_surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
400 saved_alpha = sdl_surf->format->alpha;
401 if ( (saved_flags & SDL_SRCALPHA)
404 SDL_SetAlpha(sdl_surf, 0, 0);
408 if(use_alpha == false && !use_gl)
409 sdl_surface = SDL_DisplayFormat(sdl_surf);
411 sdl_surface = SDL_DisplayFormatAlpha(sdl_surf);
414 /* Restore the alpha blending attributes */
415 if ( (saved_flags & SDL_SRCALPHA)
418 SDL_SetAlpha(sdl_surface, saved_flags, saved_alpha);
422 if (sdl_surface == NULL)
423 Termination::abort("Can't covert to display format", "SURFACE");
425 if (use_alpha == false && !use_gl)
426 SDL_SetAlpha(sdl_surface, 0, 0);
432 sdl_surface_from_gradient(Color top, Color bottom, int w, int h)
434 SDL_Surface* sdl_surface;
436 sdl_surface = SDL_CreateRGBSurface(screen->flags, w, h,
437 screen->format->BitsPerPixel, screen->format->Rmask,
438 screen->format->Gmask, screen->format->Bmask, 0);
440 if(sdl_surface == NULL)
441 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));
450 float redstep = (float(bottom.red)-float(top.red)) / float(h);
451 float greenstep = (float(bottom.green)-float(top.green)) / float(h);
452 float bluestep = (float(bottom.blue) - float(top.blue)) / float(h);
458 for(float y = 0; y < h; y++)
461 SDL_FillRect(sdl_surface, &rect, SDL_MapRGB(sdl_surface->format,
462 int(float(top.red) + redstep * y),
463 int(float(top.green) + greenstep * y),
464 int(float(top.blue) + bluestep * y)));
471 //---------------------------------------------------------------------------
473 SurfaceImpl::SurfaceImpl()
476 SurfaceImpl::~SurfaceImpl()
478 SDL_FreeSurface(sdl_surface);
481 SDL_Surface* SurfaceImpl::get_sdl_surface() const
486 int SurfaceImpl::resize(int w_, int h_)
495 int ret = SDL_SoftStretch(sdl_surface, NULL,
501 SurfaceOpenGL::SurfaceOpenGL(SDL_Surface* surf, bool use_alpha)
503 sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha);
504 create_gl(sdl_surface,&gl_texture);
510 SurfaceOpenGL::SurfaceOpenGL(const std::string& file, bool use_alpha)
512 sdl_surface = sdl_surface_from_file(file, use_alpha);
513 create_gl(sdl_surface,&gl_texture);
519 SurfaceOpenGL::SurfaceOpenGL(const std::string& file_, int x_, int y_, int w_, int h_, bool use_alpha_)
521 sdl_surface = sdl_surface_part_from_file(file_,x_,y_,w_,h_,use_alpha_);
523 create_gl(sdl_surface, &gl_texture);
529 SurfaceOpenGL::SurfaceOpenGL(Color top_gradient, Color bottom_gradient, int w, int h)
531 sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient, w, h);
532 create_gl(sdl_surface, &gl_texture);
538 SurfaceOpenGL::~SurfaceOpenGL()
540 glDeleteTextures(1, &gl_texture);
544 SurfaceOpenGL::create_gl(SDL_Surface * surf, GLuint * tex)
551 w = power_of_two(surf->w);
552 h = power_of_two(surf->h),
554 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
555 conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
556 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
558 conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
559 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
562 /* Save the alpha blending attributes */
563 saved_flags = surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
564 saved_alpha = surf->format->alpha;
565 if ( (saved_flags & SDL_SRCALPHA)
568 SDL_SetAlpha(surf, 0, 0);
571 SDL_BlitSurface(surf, 0, conv, 0);
573 /* Restore the alpha blending attributes */
574 if ( (saved_flags & SDL_SRCALPHA)
577 SDL_SetAlpha(surf, saved_flags, saved_alpha);
580 // We check all the pixels of the surface to figure out which
581 // internal format OpenGL should use for storing it, ie. if no alpha
582 // is present store in RGB instead of RGBA, this saves a few bytes
583 // of memory, but much more importantly it makes the game look
584 // *much* better in 16bit color mode
585 int internal_format = GL_RGB10_A2;
586 bool has_alpha = false;
588 unsigned char* buf = static_cast<unsigned char*>(conv->pixels);
589 for (int y = 0; y < surf->h; ++y)
590 for (int x = 0; x < surf->w; ++x)
592 if (buf[(conv->pitch*y + x*4) + 3] != 255)
601 internal_format = GL_RGB;
604 glGenTextures(1, &*tex);
605 glBindTexture(GL_TEXTURE_2D , *tex);
606 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
607 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
608 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
609 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
610 glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel);
611 glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels);
612 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
614 SDL_FreeSurface(conv);
618 SurfaceOpenGL::draw(float x, float y, Uint8 alpha, Uint32 effect)
620 float pw = power_of_two(w);
621 float ph = power_of_two(h);
623 if(effect & SEMI_TRANSPARENT)
626 glEnable(GL_TEXTURE_2D);
628 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
630 glColor4ub(alpha, alpha, alpha, alpha);
632 glBindTexture(GL_TEXTURE_2D, gl_texture);
636 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
639 glVertex2f((float)w+x, (float)h+y);
641 glTexCoord2f((float)w / pw, 0);
642 glVertex2f(x, (float)h+y);
644 glTexCoord2f((float)w / pw, (float)h / ph);
647 glTexCoord2f(0, (float)h / ph);
648 glVertex2f((float)w+x, y);
650 else if(effect & VERTICAL_FLIP)
653 glVertex2f(x, (float)h+y);
655 glTexCoord2f((float)w / pw, 0);
656 glVertex2f((float)w+x, (float)h+y);
658 glTexCoord2f((float)w / pw, (float)h / ph);
659 glVertex2f((float)w+x, y);
661 glTexCoord2f(0, (float)h / ph);
664 else if(effect & HORIZONTAL_FLIP)
667 glVertex2f((float)w+x, y);
669 glTexCoord2f((float)w / pw, 0);
672 glTexCoord2f((float)w / pw, (float)h / ph);
673 glVertex2f(x, (float)h+y);
675 glTexCoord2f(0, (float)h / ph);
676 glVertex2f((float)w+x, (float)h+y);
683 glTexCoord2f((float)w / pw, 0);
684 glVertex2f((float)w+x, y);
686 glTexCoord2f((float)w / pw, (float)h / ph);
687 glVertex2f((float)w+x, (float)h+y);
689 glTexCoord2f(0, (float)h / ph);
690 glVertex2f(x, (float)h+y);
694 glDisable(GL_TEXTURE_2D);
701 SurfaceOpenGL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect)
703 float pw = power_of_two(int(this->w));
704 float ph = power_of_two(int(this->h));
706 if(effect & SEMI_TRANSPARENT)
709 glBindTexture(GL_TEXTURE_2D, gl_texture);
712 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
714 glColor4ub(alpha, alpha, alpha, alpha);
716 glEnable(GL_TEXTURE_2D);
721 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
723 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
724 glVertex2f((float)w+x, (float)h+y);
726 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
727 glVertex2f(x, (float)h+y);
729 glTexCoord2f((float)(sx + w) / pw, sy / ph);
732 glTexCoord2f(sx / pw, sy / ph);
733 glVertex2f((float)w+x, y);
735 else if(effect & VERTICAL_FLIP)
737 glTexCoord2f(sx / pw, sy / ph);
740 glTexCoord2f((float)(sx + w) / pw, sy / ph);
743 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
744 glVertex2f(w +x, h+y);
746 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
749 else if(effect & HORIZONTAL_FLIP)
751 glTexCoord2f(sx / pw, sy / ph);
752 glVertex2f((float)w+x, y);
754 glTexCoord2f((float)(sx + w) / pw, sy / ph);
757 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
758 glVertex2f(x, (float)h+y);
760 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
761 glVertex2f((float)w+x, (float)h+y);
765 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
768 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
769 glVertex2f(w +x, h+y);
771 glTexCoord2f((float)(sx + w) / pw, sy / ph);
774 glTexCoord2f(sx / pw, sy / ph);
780 glDisable(GL_TEXTURE_2D);
787 SurfaceOpenGL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uint32 effect)
789 float pw = power_of_two(sw);
790 float ph = power_of_two(sh);
792 if(effect & SEMI_TRANSPARENT)
795 glEnable(GL_TEXTURE_2D);
797 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
799 glColor4ub(alpha, alpha, alpha, alpha);
801 glBindTexture(GL_TEXTURE_2D, gl_texture);
805 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
808 glVertex2f((float)sw+x, (float)sh+y);
810 glTexCoord2f((float)w / pw, 0);
811 glVertex2f(x, (float)sh+y);
813 glTexCoord2f((float)w / pw, (float)h / ph);
816 glTexCoord2f(0, (float)h / ph);
817 glVertex2f((float)sw+x, y);
819 else if(effect & VERTICAL_FLIP)
822 glVertex2f(x, (float)sh+y);
824 glTexCoord2f((float)w / pw, 0);
825 glVertex2f((float)sw+x, (float)sh+y);
827 glTexCoord2f((float)w / pw, (float)h / ph);
828 glVertex2f((float)sw+x, y);
830 glTexCoord2f(0, (float)h / ph);
833 else if(effect & HORIZONTAL_FLIP)
836 glVertex2f((float)sw+x, y);
838 glTexCoord2f((float)w / pw, 0);
841 glTexCoord2f((float)w / pw, (float)h / ph);
842 glVertex2f(x, (float)sh+y);
844 glTexCoord2f(0, (float)h / ph);
845 glVertex2f((float)sw+x, (float)sh+y);
852 glTexCoord2f((float)w / pw, 0);
853 glVertex2f((float)sw+x, y);
855 glTexCoord2f((float)w / pw, (float)h / ph);
856 glVertex2f((float)sw+x, (float)sh+y);
858 glTexCoord2f(0, (float)h / ph);
859 glVertex2f(x, (float)sh+y);
863 glDisable(GL_TEXTURE_2D);
870 SurfaceOpenGL::apply_filter(int filter, Color color)
872 ::apply_filter_to_surface(sdl_surface, filter, color);
873 create_gl(sdl_surface,&gl_texture);
881 SurfaceSDL::SurfaceSDL(SDL_Surface* surf, bool use_alpha)
883 sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha);
888 SurfaceSDL::SurfaceSDL(const std::string& file, bool use_alpha)
890 sdl_surface = sdl_surface_from_file(file, use_alpha);
895 SurfaceSDL::SurfaceSDL(const std::string& file, int x, int y, int w, int h, bool use_alpha)
897 sdl_surface = sdl_surface_part_from_file(file, x, y, w, h, use_alpha);
902 SurfaceSDL::SurfaceSDL(Color top_gradient, Color bottom_gradient, int w, int h)
904 sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient, w, h);
910 SurfaceSDL::draw(float x, float y, Uint8 alpha, Uint32 effect)
919 if(effect & SEMI_TRANSPARENT)
922 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
924 // FIXME: this hack is damn slow. Just keep it cause it isn't that used.
925 for(float sx = 0; sx < w; sx++)
926 for(float sy = 0; sy < h; sy++)
927 if(draw_part(sx, sy, x+(w-sx), y+(h-sy), 1, 1, alpha, NONE_EFFECT) == -2)
931 else if(effect & VERTICAL_FLIP) // FIXME: feel free to replace this hack
933 for(float sy = 0; sy < h; sy++)
934 if(draw_part(0, sy, x, y+(h-sy), w, 1, alpha, NONE_EFFECT) == -2)
938 else if(effect & HORIZONTAL_FLIP) // FIXME: feel free to replace this hack
940 for(float sx = 0; sx < w; sx++)
941 if(draw_part(sx, 0, x+(w-sx), y, 1, h, alpha, NONE_EFFECT) == -2)
948 /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha
949 to temp sur, blit the temp into the screen */
950 /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that
951 already have an alpha mask yet... */
953 SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
954 sdl_surface->w, sdl_surface->h, sdl_surface->format->BitsPerPixel,
955 sdl_surface->format->Rmask, sdl_surface->format->Gmask,
956 sdl_surface->format->Bmask,
958 int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255);
959 SDL_FillRect(sdl_surface_copy, NULL, colorkey);
960 SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey);
963 SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
964 SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha);
966 int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest);
968 SDL_FreeSurface (sdl_surface_copy);
972 int ret = SDL_BlitSurface(sdl_surface, NULL, screen, &dest);
978 SurfaceSDL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect)
992 if(effect & SEMI_TRANSPARENT)
995 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
997 // FIXME: this hack is damn slow. Just keep it cause it isn't that used.
998 for(float sx_ = 0; sx_ < w; sx++)
999 for(float sy_ = 0; sy_ < h; sy++)
1000 if(draw_part(sx_, sy_, sx+(w-sx_), sy+(h-sy_), 1, 1, alpha, NONE_EFFECT) == -2)
1004 else if(effect & VERTICAL_FLIP) // FIXME: feel free to replace this hack
1006 for(float sy_ = sy; sy_ < h; sy_++)
1007 if(draw_part(sx, sy_, x, y+(h-sy_), w, 1, alpha, NONE_EFFECT) == -2)
1011 else if(effect & HORIZONTAL_FLIP) // FIXME: feel free to replace this hack
1013 for(float sx_ = 0; sx_ < w; sx_++)
1014 if(draw_part(sx_, 0, sx+(w-sx_), sy, 1, h, alpha, NONE_EFFECT) == -2)
1021 /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha
1022 to temp sur, blit the temp into the screen */
1023 /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that
1024 already have an alpha mask, yet... */
1026 SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
1027 (int)w, (int)h, sdl_surface->format->BitsPerPixel,
1028 sdl_surface->format->Rmask, sdl_surface->format->Gmask,
1029 sdl_surface->format->Bmask,
1031 int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255);
1032 SDL_FillRect(sdl_surface_copy, NULL, colorkey);
1033 SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey);
1036 SDL_BlitSurface(sdl_surface, &src, sdl_surface_copy, NULL);
1037 SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha);
1039 int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest);
1041 SDL_FreeSurface (sdl_surface_copy);
1045 int ret = SDL_BlitSurface(sdl_surface, &src, screen, &dest);
1051 SurfaceSDL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uint32 effect)
1060 if(effect & SEMI_TRANSPARENT)
1063 SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
1064 sw, sh, sdl_surface->format->BitsPerPixel,
1065 sdl_surface->format->Rmask, sdl_surface->format->Gmask,
1066 sdl_surface->format->Bmask,
1069 SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
1070 SDL_SoftStretch(sdl_surface_copy, NULL, sdl_surface_copy, &dest);
1073 SDL_SetAlpha(sdl_surface_copy,SDL_SRCALPHA,alpha);
1075 int ret = SDL_BlitSurface(sdl_surface_copy,NULL,screen,&dest);
1076 SDL_FreeSurface(sdl_surface_copy);
1082 SurfaceSDL::apply_filter(int filter, Color color)
1084 ::apply_filter_to_surface(sdl_surface, filter, color);
1090 SurfaceSDL::~SurfaceSDL()