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();
200 void Surface::apply_mask(Color color)
202 impl->apply_mask(color);
209 for(std::list<Surface*>::iterator i = surfaces.begin(); i != surfaces.end();
218 printf("Error: Surface freed twice!!!\n");
220 surfaces.remove(this);
225 Surface::reload_all()
227 for(Surfaces::iterator i = surfaces.begin(); i != surfaces.end(); ++i)
234 Surface::debug_check()
236 for(Surfaces::iterator i = surfaces.begin(); i != surfaces.end(); ++i)
238 printf("Surface not freed: T:%d F:%s.\n", (*i)->data.type,
239 (*i)->data.file.c_str());
244 Surface::resize(int w_, int h_)
250 if (impl->resize(w_,h_) == -2)
256 apply_filter_to_surface(SDL_Surface* surface, int filter, Color color)
258 if(filter == MASK_FILTER)
260 SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true);
264 SDL_LockSurface(sur_copy);
265 for(int x = 0; x < sur_copy->w; x++)
266 for(int y = 0; y < sur_copy->h; y++)
268 SDL_GetRGBA(getpixel(sur_copy,x,y), sur_copy->format, &r,&g,&b,&a);
271 putpixel(sur_copy, x,y, color.map_rgba(sur_copy));
274 SDL_UnlockSurface(sur_copy);
276 SDL_BlitSurface(sur_copy, NULL, surface, NULL);
277 SDL_FreeSurface(sur_copy);
282 sdl_surface_part_from_file(const std::string& file, int x, int y, int w, int h, bool use_alpha)
285 SDL_Surface * sdl_surface;
289 temp = IMG_Load(file.c_str());
292 Termination::abort("Can't load", file);
294 /* Set source rectangle for conv: */
301 conv = SDL_CreateRGBSurface(temp->flags, w, h, temp->format->BitsPerPixel,
305 temp->format->Amask);
307 /* #if SDL_BYTEORDER == SDL_BIG_ENDIAN
308 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
311 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
314 SDL_SetAlpha(temp,0,0);
316 SDL_BlitSurface(temp, &src, conv, NULL);
317 if(use_alpha == false && !use_gl)
318 sdl_surface = SDL_DisplayFormat(conv);
320 sdl_surface = SDL_DisplayFormatAlpha(conv);
322 if (sdl_surface == NULL)
323 Termination::abort("Can't covert to display format", file);
325 if (use_alpha == false && !use_gl)
326 SDL_SetAlpha(sdl_surface, 0, 0);
328 SDL_FreeSurface(temp);
329 SDL_FreeSurface(conv);
335 sdl_surface_from_file(const std::string& file, bool use_alpha)
337 SDL_Surface* sdl_surface;
340 temp = IMG_Load(file.c_str());
343 Termination::abort("Can't load", file);
345 if(use_alpha == false && !use_gl)
346 sdl_surface = SDL_DisplayFormat(temp);
348 sdl_surface = SDL_DisplayFormatAlpha(temp);
350 if (sdl_surface == NULL)
351 Termination::abort("Can't covert to display format", file);
353 if (use_alpha == false && !use_gl)
354 SDL_SetAlpha(sdl_surface, 0, 0);
356 SDL_FreeSurface(temp);
362 SuperTux::sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, bool use_alpha)
364 SDL_Surface* sdl_surface;
369 /* Save the alpha blending attributes */
370 saved_flags = sdl_surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
371 saved_alpha = sdl_surf->format->alpha;
372 if ( (saved_flags & SDL_SRCALPHA)
375 SDL_SetAlpha(sdl_surf, 0, 0);
379 if(use_alpha == false && !use_gl)
380 sdl_surface = SDL_DisplayFormat(sdl_surf);
382 sdl_surface = SDL_DisplayFormatAlpha(sdl_surf);
385 /* Restore the alpha blending attributes */
386 if ( (saved_flags & SDL_SRCALPHA)
389 SDL_SetAlpha(sdl_surface, saved_flags, saved_alpha);
393 if (sdl_surface == NULL)
394 Termination::abort("Can't covert to display format", "SURFACE");
396 if (use_alpha == false && !use_gl)
397 SDL_SetAlpha(sdl_surface, 0, 0);
403 sdl_surface_from_gradient(Color top, Color bottom, int w, int h)
405 SDL_Surface* sdl_surface;
407 sdl_surface = SDL_CreateRGBSurface(screen->flags, w, h,
408 screen->format->BitsPerPixel, screen->format->Rmask,
409 screen->format->Gmask, screen->format->Bmask, 0);
411 if(sdl_surface == NULL)
412 Termination::abort("Cannot create surface for the gradient", "SURFACE");
416 SDL_FillRect(sdl_surface, NULL, SDL_MapRGB(sdl_surface->format,
417 top.red, top.green, top.blue));
421 float redstep = (float(bottom.red)-float(top.red)) / float(h);
422 float greenstep = (float(bottom.green)-float(top.green)) / float(h);
423 float bluestep = (float(bottom.blue) - float(top.blue)) / float(h);
429 for(float y = 0; y < h; y++)
432 SDL_FillRect(sdl_surface, &rect, SDL_MapRGB(sdl_surface->format,
433 int(float(top.red) + redstep * y),
434 int(float(top.green) + greenstep * y),
435 int(float(top.blue) + bluestep * y)));
442 //---------------------------------------------------------------------------
444 SurfaceImpl::SurfaceImpl()
447 SurfaceImpl::~SurfaceImpl()
449 SDL_FreeSurface(sdl_surface);
452 SDL_Surface* SurfaceImpl::get_sdl_surface() const
457 int SurfaceImpl::resize(int w_, int h_)
466 int ret = SDL_SoftStretch(sdl_surface, NULL,
472 SurfaceOpenGL::SurfaceOpenGL(SDL_Surface* surf, bool use_alpha)
474 sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha);
475 create_gl(sdl_surface,&gl_texture);
481 SurfaceOpenGL::SurfaceOpenGL(const std::string& file, bool use_alpha)
483 sdl_surface = sdl_surface_from_file(file, use_alpha);
484 create_gl(sdl_surface,&gl_texture);
490 SurfaceOpenGL::SurfaceOpenGL(const std::string& file_, int x_, int y_, int w_, int h_, bool use_alpha_)
492 sdl_surface = sdl_surface_part_from_file(file_,x_,y_,w_,h_,use_alpha_);
494 create_gl(sdl_surface, &gl_texture);
500 SurfaceOpenGL::SurfaceOpenGL(Color top_gradient, Color bottom_gradient, int w, int h)
502 sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient, w, h);
503 create_gl(sdl_surface, &gl_texture);
509 SurfaceOpenGL::~SurfaceOpenGL()
511 glDeleteTextures(1, &gl_texture);
515 SurfaceOpenGL::create_gl(SDL_Surface * surf, GLuint * tex)
522 w = power_of_two(surf->w);
523 h = power_of_two(surf->h),
525 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
526 conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
527 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
529 conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
530 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
533 /* Save the alpha blending attributes */
534 saved_flags = surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
535 saved_alpha = surf->format->alpha;
536 if ( (saved_flags & SDL_SRCALPHA)
539 SDL_SetAlpha(surf, 0, 0);
542 SDL_BlitSurface(surf, 0, conv, 0);
544 /* Restore the alpha blending attributes */
545 if ( (saved_flags & SDL_SRCALPHA)
548 SDL_SetAlpha(surf, saved_flags, saved_alpha);
551 // We check all the pixels of the surface to figure out which
552 // internal format OpenGL should use for storing it, ie. if no alpha
553 // is present store in RGB instead of RGBA, this saves a few bytes
554 // of memory, but much more importantly it makes the game look
555 // *much* better in 16bit color mode
556 int internal_format = GL_RGB10_A2;
557 bool has_alpha = false;
559 unsigned char* buf = static_cast<unsigned char*>(conv->pixels);
560 for (int y = 0; y < surf->h; ++y)
561 for (int x = 0; x < surf->w; ++x)
563 if (buf[(conv->pitch*y + x*4) + 3] != 255)
572 internal_format = GL_RGB;
575 glGenTextures(1, &*tex);
576 glBindTexture(GL_TEXTURE_2D , *tex);
577 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
578 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
579 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
580 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
581 glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel);
582 glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels);
583 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
585 SDL_FreeSurface(conv);
589 SurfaceOpenGL::draw(float x, float y, Uint8 alpha, Uint32 effect)
591 float pw = power_of_two(w);
592 float ph = power_of_two(h);
594 if(effect & SEMI_TRANSPARENT)
597 glEnable(GL_TEXTURE_2D);
599 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
601 glColor4ub(alpha, alpha, alpha, alpha);
603 glBindTexture(GL_TEXTURE_2D, gl_texture);
607 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
610 glVertex2f((float)w+x, (float)h+y);
612 glTexCoord2f((float)w / pw, 0);
613 glVertex2f(x, (float)h+y);
615 glTexCoord2f((float)w / pw, (float)h / ph);
618 glTexCoord2f(0, (float)h / ph);
619 glVertex2f((float)w+x, y);
621 else if(effect & VERTICAL_FLIP)
624 glVertex2f(x, (float)h+y);
626 glTexCoord2f((float)w / pw, 0);
627 glVertex2f((float)w+x, (float)h+y);
629 glTexCoord2f((float)w / pw, (float)h / ph);
630 glVertex2f((float)w+x, y);
632 glTexCoord2f(0, (float)h / ph);
635 else if(effect & HORIZONTAL_FLIP)
638 glVertex2f((float)w+x, y);
640 glTexCoord2f((float)w / pw, 0);
643 glTexCoord2f((float)w / pw, (float)h / ph);
644 glVertex2f(x, (float)h+y);
646 glTexCoord2f(0, (float)h / ph);
647 glVertex2f((float)w+x, (float)h+y);
654 glTexCoord2f((float)w / pw, 0);
655 glVertex2f((float)w+x, y);
657 glTexCoord2f((float)w / pw, (float)h / ph);
658 glVertex2f((float)w+x, (float)h+y);
660 glTexCoord2f(0, (float)h / ph);
661 glVertex2f(x, (float)h+y);
665 glDisable(GL_TEXTURE_2D);
672 SurfaceOpenGL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect)
674 float pw = power_of_two(int(this->w));
675 float ph = power_of_two(int(this->h));
677 if(effect & SEMI_TRANSPARENT)
680 glBindTexture(GL_TEXTURE_2D, gl_texture);
683 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
685 glColor4ub(alpha, alpha, alpha, alpha);
687 glEnable(GL_TEXTURE_2D);
692 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
694 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
695 glVertex2f((float)w+x, (float)h+y);
697 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
698 glVertex2f(x, (float)h+y);
700 glTexCoord2f((float)(sx + w) / pw, sy / ph);
703 glTexCoord2f(sx / pw, sy / ph);
704 glVertex2f((float)w+x, y);
706 else if(effect & VERTICAL_FLIP)
708 glTexCoord2f(sx / pw, sy / ph);
711 glTexCoord2f((float)(sx + w) / pw, sy / ph);
714 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
715 glVertex2f(w +x, h+y);
717 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
720 else if(effect & HORIZONTAL_FLIP)
722 glTexCoord2f(sx / pw, sy / ph);
723 glVertex2f((float)w+x, y);
725 glTexCoord2f((float)(sx + w) / pw, sy / ph);
728 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
729 glVertex2f(x, (float)h+y);
731 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
732 glVertex2f((float)w+x, (float)h+y);
736 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
739 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
740 glVertex2f(w +x, h+y);
742 glTexCoord2f((float)(sx + w) / pw, sy / ph);
745 glTexCoord2f(sx / pw, sy / ph);
751 glDisable(GL_TEXTURE_2D);
758 SurfaceOpenGL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uint32 effect)
760 if(effect & SEMI_TRANSPARENT)
763 float pw = power_of_two(sw);
764 float ph = power_of_two(sh);
766 if(effect & SEMI_TRANSPARENT)
769 glEnable(GL_TEXTURE_2D);
771 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
773 glColor4ub(alpha, alpha, alpha, alpha);
775 glBindTexture(GL_TEXTURE_2D, gl_texture);
779 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
782 glVertex2f((float)sw+x, (float)sh+y);
784 glTexCoord2f((float)w / pw, 0);
785 glVertex2f(x, (float)sh+y);
787 glTexCoord2f((float)w / pw, (float)h / ph);
790 glTexCoord2f(0, (float)h / ph);
791 glVertex2f((float)sw+x, y);
793 else if(effect & VERTICAL_FLIP)
796 glVertex2f(x, (float)sh+y);
798 glTexCoord2f((float)w / pw, 0);
799 glVertex2f((float)sw+x, (float)sh+y);
801 glTexCoord2f((float)w / pw, (float)h / ph);
802 glVertex2f((float)sw+x, y);
804 glTexCoord2f(0, (float)h / ph);
807 else if(effect & HORIZONTAL_FLIP)
810 glVertex2f((float)sw+x, y);
812 glTexCoord2f((float)w / pw, 0);
815 glTexCoord2f((float)w / pw, (float)h / ph);
816 glVertex2f(x, (float)sh+y);
818 glTexCoord2f(0, (float)h / ph);
819 glVertex2f((float)sw+x, (float)sh+y);
826 glTexCoord2f((float)w / pw, 0);
827 glVertex2f((float)sw+x, y);
829 glTexCoord2f((float)w / pw, (float)h / ph);
830 glVertex2f((float)sw+x, (float)sh+y);
832 glTexCoord2f(0, (float)h / ph);
833 glVertex2f(x, (float)sh+y);
837 glDisable(GL_TEXTURE_2D);
844 SurfaceOpenGL::apply_mask(Color color)
846 ::apply_filter_to_surface(sdl_surface, MASK_FILTER, color);
847 create_gl(sdl_surface,&gl_texture);
855 SurfaceSDL::SurfaceSDL(SDL_Surface* surf, bool use_alpha)
857 sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha);
862 SurfaceSDL::SurfaceSDL(const std::string& file, bool use_alpha)
864 sdl_surface = sdl_surface_from_file(file, use_alpha);
869 SurfaceSDL::SurfaceSDL(const std::string& file, int x, int y, int w, int h, bool use_alpha)
871 sdl_surface = sdl_surface_part_from_file(file, x, y, w, h, use_alpha);
876 SurfaceSDL::SurfaceSDL(Color top_gradient, Color bottom_gradient, int w, int h)
878 sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient, w, h);
884 SurfaceSDL::draw(float x, float y, Uint8 alpha, Uint32 effect)
893 if(effect & SEMI_TRANSPARENT)
896 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
898 // FIXME: this hack is damn slow. Just keep it cause it isn't that used.
899 for(float sx = 0; sx < w; sx++)
900 for(float sy = 0; sy < h; sy++)
901 if(draw_part(sx, sy, x+(w-sx), y+(h-sy), 1, 1, alpha, NONE_EFFECT) == -2)
905 else if(effect & VERTICAL_FLIP) // FIXME: feel free to replace this hack
907 for(float sy = 0; sy < h; sy++)
908 if(draw_part(0, sy, x, y+(h-sy), w, 1, alpha, NONE_EFFECT) == -2)
912 else if(effect & HORIZONTAL_FLIP) // FIXME: feel free to replace this hack
914 for(float sx = 0; sx < w; sx++)
915 if(draw_part(sx, 0, x+(w-sx), y, 1, h, alpha, NONE_EFFECT) == -2)
922 /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha
923 to temp sur, blit the temp into the screen */
924 /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that
925 already have an alpha mask yet... */
927 SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
928 sdl_surface->w, sdl_surface->h, sdl_surface->format->BitsPerPixel,
929 sdl_surface->format->Rmask, sdl_surface->format->Gmask,
930 sdl_surface->format->Bmask,
932 int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255);
933 SDL_FillRect(sdl_surface_copy, NULL, colorkey);
934 SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey);
937 SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
938 SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha);
940 int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest);
942 SDL_FreeSurface (sdl_surface_copy);
946 int ret = SDL_BlitSurface(sdl_surface, NULL, screen, &dest);
952 SurfaceSDL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect)
966 if(effect & SEMI_TRANSPARENT)
969 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
971 // FIXME: this hack is damn slow. Just keep it cause it isn't that used.
972 for(float sx_ = 0; sx_ < w; sx++)
973 for(float sy_ = 0; sy_ < h; sy++)
974 if(draw_part(sx_, sy_, sx+(w-sx_), sy+(h-sy_), 1, 1, alpha, NONE_EFFECT) == -2)
978 else if(effect & VERTICAL_FLIP) // FIXME: feel free to replace this hack
980 for(float sy_ = sy; sy_ < h; sy_++)
981 if(draw_part(sx, sy_, x, y+(h-sy_), w, 1, alpha, NONE_EFFECT) == -2)
985 else if(effect & HORIZONTAL_FLIP) // FIXME: feel free to replace this hack
987 for(float sx_ = 0; sx_ < w; sx_++)
988 if(draw_part(sx_, 0, sx+(w-sx_), sy, 1, h, alpha, NONE_EFFECT) == -2)
995 /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha
996 to temp sur, blit the temp into the screen */
997 /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that
998 already have an alpha mask yet... */
1000 SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
1001 sdl_surface->w, sdl_surface->h, sdl_surface->format->BitsPerPixel,
1002 sdl_surface->format->Rmask, sdl_surface->format->Gmask,
1003 sdl_surface->format->Bmask,
1005 int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255);
1006 SDL_FillRect(sdl_surface_copy, NULL, colorkey);
1007 SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey);
1010 SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
1011 SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha);
1013 int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest);
1015 SDL_FreeSurface (sdl_surface_copy);
1019 int ret = SDL_BlitSurface(sdl_surface, &src, screen, &dest);
1025 SurfaceSDL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uint32 effect)
1034 if(effect & SEMI_TRANSPARENT)
1037 SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
1038 sw, sh, sdl_surface->format->BitsPerPixel,
1039 sdl_surface->format->Rmask, sdl_surface->format->Gmask,
1040 sdl_surface->format->Bmask,
1043 SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
1044 SDL_SoftStretch(sdl_surface_copy, NULL, sdl_surface_copy, &dest);
1047 SDL_SetAlpha(sdl_surface_copy,SDL_SRCALPHA,alpha);
1049 int ret = SDL_BlitSurface(sdl_surface_copy,NULL,screen,&dest);
1050 SDL_FreeSurface(sdl_surface_copy);
1056 SurfaceSDL::apply_mask(Color color)
1058 ::apply_filter_to_surface(sdl_surface, MASK_FILTER, color);
1064 SurfaceSDL::~SurfaceSDL()