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_),
41 x(0), y(0), w(0), h(0)
43 // Copy the given surface and make sure that it is not stored in
45 surface = SDL_CreateRGBSurface(temp->flags & (~SDL_HWSURFACE),
47 temp->format->BitsPerPixel,
53 Termination::abort("No memory left.", "");
54 SDL_SetAlpha(temp,0,0);
55 SDL_BlitSurface(temp, NULL, surface, NULL);
58 SurfaceData::SurfaceData(const std::string& file_, bool use_alpha_)
59 : type(LOAD), surface(0), file(file_), use_alpha(use_alpha_)
62 SurfaceData::SurfaceData(const std::string& file_, int x_, int y_,
63 int w_, int h_, bool use_alpha_)
64 : type(LOAD_PART), surface(0), file(file_), use_alpha(use_alpha_),
65 x(x_), y(y_), w(w_), h(h_)
68 SurfaceData::SurfaceData(Color top_gradient_, Color bottom_gradient_,
70 : type(GRADIENT), surface(0), use_alpha(false), w(w_), h(h_)
72 top_gradient = top_gradient_;
73 bottom_gradient = bottom_gradient_;
77 SurfaceData::~SurfaceData()
79 SDL_FreeSurface(surface);
87 return create_SurfaceOpenGL();
89 return create_SurfaceSDL();
91 return create_SurfaceSDL();
96 SurfaceData::create_SurfaceSDL()
101 return new SurfaceSDL(file, use_alpha);
103 return new SurfaceSDL(file, x, y, w, h, use_alpha);
105 return new SurfaceSDL(surface, use_alpha);
107 return new SurfaceSDL(top_gradient, bottom_gradient, w, h);
113 SurfaceData::create_SurfaceOpenGL()
119 return new SurfaceOpenGL(file, use_alpha);
121 return new SurfaceOpenGL(file, x, y, w, h, use_alpha);
123 return new SurfaceOpenGL(surface, use_alpha);
125 return new SurfaceOpenGL(top_gradient, bottom_gradient, w, h);
132 /* Quick utility function for texture creation */
133 static int power_of_two(int input)
137 while ( value < input )
145 Surface::Surface(SDL_Surface* surf, bool use_alpha)
146 : data(surf, use_alpha), w(0), h(0)
148 impl = data.create();
154 surfaces.push_back(this);
157 Surface::Surface(const std::string& file, bool use_alpha)
158 : data(file, use_alpha), w(0), h(0)
160 impl = data.create();
166 surfaces.push_back(this);
169 Surface::Surface(const std::string& file, int x, int y, int w_, int h_, bool use_alpha)
170 : data(file, x, y, w_, h_, use_alpha), w(0), h(0)
172 impl = data.create();
178 surfaces.push_back(this);
181 Surface::Surface(Color top_background, Color bottom_background, int w_, int h_)
182 : data(top_background, bottom_background, w_, h_), w(0), h(0)
184 impl = data.create();
190 surfaces.push_back(this);
197 impl = data.create();
202 for(std::vector<SurfaceData::Filter>::iterator i =
203 data.applied_filters.begin(); i != data.applied_filters.end();
205 impl->apply_filter(i->type, i->color);
209 void Surface::apply_filter(int filter, Color color)
211 impl->apply_filter(filter, color);
213 SurfaceData::Filter apply_filter;
214 apply_filter.type = filter;
215 apply_filter.color = color;
216 data.applied_filters.push_back(apply_filter);
223 for(std::list<Surface*>::iterator i = surfaces.begin(); i != surfaces.end();
232 printf("Error: Surface freed twice!!!\n");
234 surfaces.remove(this);
239 Surface::reload_all()
241 for(Surfaces::iterator i = surfaces.begin(); i != surfaces.end(); ++i)
248 Surface::debug_check()
250 for(Surfaces::iterator i = surfaces.begin(); i != surfaces.end(); ++i)
252 printf("Surface not freed: T:%d F:%s.\n", (*i)->data.type,
253 (*i)->data.file.c_str());
258 apply_filter_to_surface(SDL_Surface* surface, int filter, Color color)
260 if(filter == HORIZONTAL_FLIP_FILTER) {
261 SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true);
262 SDL_BlitSurface(surface, NULL, sur_copy, NULL);
263 SDL_SetAlpha(sur_copy,0,0);
268 src.h = dst.h = sur_copy->h;
269 for(int x = 0; x < sur_copy->w; x++)
271 src.x = x; dst.x = sur_copy->w-1 - x;
272 SDL_BlitSurface(sur_copy, &src, surface, &dst);
275 SDL_FreeSurface(sur_copy);
276 } else if(filter == MASK_FILTER) {
277 SDL_Surface* sur_copy = sdl_surface_from_sdl_surface(surface, true);
281 SDL_LockSurface(sur_copy);
282 for(int x = 0; x < sur_copy->w; x++)
283 for(int y = 0; y < sur_copy->h; y++) {
284 SDL_GetRGBA(getpixel(sur_copy,x,y), sur_copy->format, &r,&g,&b,&a);
286 putpixel(sur_copy, x,y, color.map_rgba(sur_copy));
289 SDL_UnlockSurface(sur_copy);
291 SDL_BlitSurface(sur_copy, NULL, surface, NULL);
292 SDL_FreeSurface(sur_copy);
297 sdl_surface_part_from_file(const std::string& file, int x, int y, int w, int h, bool use_alpha)
300 SDL_Surface * sdl_surface;
304 temp = IMG_Load(file.c_str());
307 Termination::abort("Can't load", file);
309 /* Set source rectangle for conv: */
316 conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, temp->format->BitsPerPixel,
320 temp->format->Amask);
322 SDL_SetAlpha(temp,0,0);
324 SDL_BlitSurface(temp, &src, conv, NULL);
325 if(use_alpha == false && !use_gl)
326 sdl_surface = SDL_DisplayFormat(conv);
328 sdl_surface = SDL_DisplayFormatAlpha(conv);
330 if (sdl_surface == NULL)
331 Termination::abort("Can't covert to display format", file);
333 if (use_alpha == false && !use_gl)
334 SDL_SetAlpha(sdl_surface, 0, 0);
336 SDL_FreeSurface(temp);
337 SDL_FreeSurface(conv);
343 sdl_surface_from_file(const std::string& file, bool use_alpha)
345 SDL_Surface* sdl_surface;
348 temp = IMG_Load(file.c_str());
351 Termination::abort("Can't load", file);
353 if(use_alpha == false && !use_gl)
354 sdl_surface = SDL_DisplayFormat(temp);
356 sdl_surface = SDL_DisplayFormatAlpha(temp);
358 if (sdl_surface == NULL)
359 Termination::abort("Can't covert to display format", file);
361 if (use_alpha == false && !use_gl)
362 SDL_SetAlpha(sdl_surface, 0, 0);
364 SDL_FreeSurface(temp);
370 SuperTux::sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, bool use_alpha)
372 SDL_Surface* sdl_surface;
377 /* Save the alpha blending attributes */
378 saved_flags = sdl_surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
379 saved_alpha = sdl_surf->format->alpha;
380 if ( (saved_flags & SDL_SRCALPHA)
383 SDL_SetAlpha(sdl_surf, 0, 0);
387 if(use_alpha == false && !use_gl)
388 sdl_surface = SDL_DisplayFormat(sdl_surf);
390 sdl_surface = SDL_DisplayFormatAlpha(sdl_surf);
393 /* Restore the alpha blending attributes */
394 if ( (saved_flags & SDL_SRCALPHA)
397 SDL_SetAlpha(sdl_surface, saved_flags, saved_alpha);
401 if (sdl_surface == NULL)
402 Termination::abort("Can't covert to display format", "SURFACE");
404 if (use_alpha == false && !use_gl)
405 SDL_SetAlpha(sdl_surface, 0, 0);
411 sdl_surface_from_gradient(Color top, Color bottom, int w, int h)
413 SDL_Surface* sdl_surface
414 = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h,
415 screen->format->BitsPerPixel, screen->format->Rmask,
416 screen->format->Gmask, screen->format->Bmask, 0);
419 Termination::abort("Cannot create surface for the gradient", "SURFACE");
422 SDL_FillRect(sdl_surface, NULL, SDL_MapRGB(sdl_surface->format,
423 top.red, top.green, top.blue));
425 float redstep = (float(bottom.red)-float(top.red)) / float(h);
426 float greenstep = (float(bottom.green)-float(top.green)) / float(h);
427 float bluestep = (float(bottom.blue) - float(top.blue)) / float(h);
433 for(float y = 0; y < h; y++) {
435 SDL_FillRect(sdl_surface, &rect, SDL_MapRGB(sdl_surface->format,
436 int(float(top.red) + redstep * y),
437 int(float(top.green) + greenstep * y),
438 int(float(top.blue) + bluestep * y)));
445 //---------------------------------------------------------------------------
447 SurfaceImpl::SurfaceImpl()
450 SurfaceImpl::~SurfaceImpl()
452 SDL_FreeSurface(sdl_surface);
455 SDL_Surface* SurfaceImpl::get_sdl_surface() const
461 SurfaceOpenGL::SurfaceOpenGL(SDL_Surface* surf, bool use_alpha)
463 sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha);
464 create_gl(sdl_surface,&gl_texture);
470 SurfaceOpenGL::SurfaceOpenGL(const std::string& file, bool use_alpha)
472 sdl_surface = sdl_surface_from_file(file, use_alpha);
473 create_gl(sdl_surface,&gl_texture);
479 SurfaceOpenGL::SurfaceOpenGL(const std::string& file_, int x_, int y_,
480 int w_, int h_, bool use_alpha_)
482 sdl_surface = sdl_surface_part_from_file(file_,x_,y_,w_,h_,use_alpha_);
484 create_gl(sdl_surface, &gl_texture);
489 SurfaceOpenGL::SurfaceOpenGL(Color top_gradient, Color bottom_gradient,
492 sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient,_w,_h);
493 create_gl(sdl_surface, &gl_texture);
498 SurfaceOpenGL::~SurfaceOpenGL()
500 glDeleteTextures(1, &gl_texture);
504 SurfaceOpenGL::create_gl(SDL_Surface * surf, GLuint * tex)
511 w = power_of_two(surf->w);
512 h = power_of_two(surf->h),
514 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
515 conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
516 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
518 conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
519 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
522 /* Save the alpha blending attributes */
523 saved_flags = surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
524 saved_alpha = surf->format->alpha;
525 if ( (saved_flags & SDL_SRCALPHA)
528 SDL_SetAlpha(surf, 0, 0);
531 SDL_BlitSurface(surf, 0, conv, 0);
533 /* Restore the alpha blending attributes */
534 if ( (saved_flags & SDL_SRCALPHA)
537 SDL_SetAlpha(surf, saved_flags, saved_alpha);
540 // We check all the pixels of the surface to figure out which
541 // internal format OpenGL should use for storing it, ie. if no alpha
542 // is present store in RGB instead of RGBA, this saves a few bytes
543 // of memory, but much more importantly it makes the game look
544 // *much* better in 16bit color mode
545 int internal_format = GL_RGB10_A2;
546 bool has_alpha = false;
548 unsigned char* buf = static_cast<unsigned char*>(conv->pixels);
549 for (int y = 0; y < surf->h; ++y)
550 for (int x = 0; x < surf->w; ++x)
552 if (buf[(conv->pitch*y + x*4) + 3] != 255)
561 internal_format = GL_RGB;
564 glGenTextures(1, &*tex);
565 glBindTexture(GL_TEXTURE_2D , *tex);
566 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
567 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
568 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
569 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
570 glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel);
571 glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels);
572 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
574 SDL_FreeSurface(conv);
578 SurfaceOpenGL::draw(float x, float y, Uint8 alpha, Uint32 effect)
580 float pw = power_of_two(w);
581 float ph = power_of_two(h);
583 if(effect & SEMI_TRANSPARENT)
586 glEnable(GL_TEXTURE_2D);
588 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
590 glColor4ub(alpha, alpha, alpha, alpha);
592 glBindTexture(GL_TEXTURE_2D, gl_texture);
596 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
599 glVertex2f((float)w+x, (float)h+y);
601 glTexCoord2f((float)w / pw, 0);
602 glVertex2f(x, (float)h+y);
604 glTexCoord2f((float)w / pw, (float)h / ph);
607 glTexCoord2f(0, (float)h / ph);
608 glVertex2f((float)w+x, y);
610 else if(effect & VERTICAL_FLIP)
613 glVertex2f(x, (float)h+y);
615 glTexCoord2f((float)w / pw, 0);
616 glVertex2f((float)w+x, (float)h+y);
618 glTexCoord2f((float)w / pw, (float)h / ph);
619 glVertex2f((float)w+x, y);
621 glTexCoord2f(0, (float)h / ph);
624 else if(effect & HORIZONTAL_FLIP)
627 glVertex2f((float)w+x, y);
629 glTexCoord2f((float)w / pw, 0);
632 glTexCoord2f((float)w / pw, (float)h / ph);
633 glVertex2f(x, (float)h+y);
635 glTexCoord2f(0, (float)h / ph);
636 glVertex2f((float)w+x, (float)h+y);
643 glTexCoord2f((float)w / pw, 0);
644 glVertex2f((float)w+x, y);
646 glTexCoord2f((float)w / pw, (float)h / ph);
647 glVertex2f((float)w+x, (float)h+y);
649 glTexCoord2f(0, (float)h / ph);
650 glVertex2f(x, (float)h+y);
654 glDisable(GL_TEXTURE_2D);
661 SurfaceOpenGL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect)
663 float pw = power_of_two(int(this->w));
664 float ph = power_of_two(int(this->h));
666 if(effect & SEMI_TRANSPARENT)
669 glBindTexture(GL_TEXTURE_2D, gl_texture);
672 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
674 glColor4ub(alpha, alpha, alpha, alpha);
676 glEnable(GL_TEXTURE_2D);
681 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
683 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
684 glVertex2f((float)w+x, (float)h+y);
686 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
687 glVertex2f(x, (float)h+y);
689 glTexCoord2f((float)(sx + w) / pw, sy / ph);
692 glTexCoord2f(sx / pw, sy / ph);
693 glVertex2f((float)w+x, y);
695 else if(effect & VERTICAL_FLIP)
697 glTexCoord2f(sx / pw, sy / ph);
700 glTexCoord2f((float)(sx + w) / pw, sy / ph);
703 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
704 glVertex2f(w +x, h+y);
706 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
709 else if(effect & HORIZONTAL_FLIP)
711 glTexCoord2f(sx / pw, sy / ph);
712 glVertex2f((float)w+x, y);
714 glTexCoord2f((float)(sx + w) / pw, sy / ph);
717 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
718 glVertex2f(x, (float)h+y);
720 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
721 glVertex2f((float)w+x, (float)h+y);
725 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
728 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
729 glVertex2f(w +x, h+y);
731 glTexCoord2f((float)(sx + w) / pw, sy / ph);
734 glTexCoord2f(sx / pw, sy / ph);
740 glDisable(GL_TEXTURE_2D);
747 SurfaceOpenGL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uint32 effect)
749 float pw = power_of_two(sw);
750 float ph = power_of_two(sh);
752 if(effect & SEMI_TRANSPARENT)
755 glEnable(GL_TEXTURE_2D);
757 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
759 glColor4ub(alpha, alpha, alpha, alpha);
761 glBindTexture(GL_TEXTURE_2D, gl_texture);
765 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
768 glVertex2f((float)sw+x, (float)sh+y);
770 glTexCoord2f((float)w / pw, 0);
771 glVertex2f(x, (float)sh+y);
773 glTexCoord2f((float)w / pw, (float)h / ph);
776 glTexCoord2f(0, (float)h / ph);
777 glVertex2f((float)sw+x, y);
779 else if(effect & VERTICAL_FLIP)
782 glVertex2f(x, (float)sh+y);
784 glTexCoord2f((float)w / pw, 0);
785 glVertex2f((float)sw+x, (float)sh+y);
787 glTexCoord2f((float)w / pw, (float)h / ph);
788 glVertex2f((float)sw+x, y);
790 glTexCoord2f(0, (float)h / ph);
793 else if(effect & HORIZONTAL_FLIP)
796 glVertex2f((float)sw+x, y);
798 glTexCoord2f((float)w / pw, 0);
801 glTexCoord2f((float)w / pw, (float)h / ph);
802 glVertex2f(x, (float)sh+y);
804 glTexCoord2f(0, (float)h / ph);
805 glVertex2f((float)sw+x, (float)sh+y);
812 glTexCoord2f((float)w / pw, 0);
813 glVertex2f((float)sw+x, y);
815 glTexCoord2f((float)w / pw, (float)h / ph);
816 glVertex2f((float)sw+x, (float)sh+y);
818 glTexCoord2f(0, (float)h / ph);
819 glVertex2f(x, (float)sh+y);
823 glDisable(GL_TEXTURE_2D);
830 SurfaceOpenGL::apply_filter(int filter, Color color)
832 ::apply_filter_to_surface(sdl_surface, filter, color);
833 create_gl(sdl_surface,&gl_texture);
841 SurfaceSDL::SurfaceSDL(SDL_Surface* surf, bool use_alpha)
843 sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha);
848 SurfaceSDL::SurfaceSDL(const std::string& file, bool use_alpha)
850 sdl_surface = sdl_surface_from_file(file, use_alpha);
855 SurfaceSDL::SurfaceSDL(const std::string& file, int x, int y, int _w, int _h,
858 sdl_surface = sdl_surface_part_from_file(file, x, y, _w, _h, use_alpha);
863 SurfaceSDL::SurfaceSDL(Color top_gradient, Color bottom_gradient,
866 sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient,_w,_h);
872 SurfaceSDL::draw(float x, float y, Uint8 alpha, Uint32 effect)
881 if(effect & SEMI_TRANSPARENT)
884 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
886 // FIXME: this hack is damn slow. Just keep it cause it isn't that used.
887 for(float sx = 0; sx < w; sx++)
888 for(float sy = 0; sy < h; sy++)
889 if(draw_part(sx, sy, x+(w-sx), y+(h-sy), 1, 1, alpha, NONE_EFFECT) == -2)
893 else if(effect & VERTICAL_FLIP) // FIXME: feel free to replace this hack
895 for(float sy = 0; sy < h; sy++)
896 if(draw_part(0, sy, x, y+(h-sy), w, 1, alpha, NONE_EFFECT) == -2)
900 else if(effect & HORIZONTAL_FLIP) // FIXME: feel free to replace this hack
902 for(float sx = 0; sx < w; sx++)
903 if(draw_part(sx, 0, x+(w-sx), y, 1, h, alpha, NONE_EFFECT) == -2)
910 /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha
911 to temp sur, blit the temp into the screen */
912 /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that
913 already have an alpha mask yet... */
915 SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
916 sdl_surface->w, sdl_surface->h, sdl_surface->format->BitsPerPixel,
917 sdl_surface->format->Rmask, sdl_surface->format->Gmask,
918 sdl_surface->format->Bmask,
920 int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255);
921 SDL_FillRect(sdl_surface_copy, NULL, colorkey);
922 SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey);
925 SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
926 SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha);
928 int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest);
930 SDL_FreeSurface (sdl_surface_copy);
934 int ret = SDL_BlitSurface(sdl_surface, NULL, screen, &dest);
940 SurfaceSDL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect)
954 if(effect & SEMI_TRANSPARENT)
957 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
959 // FIXME: this hack is damn slow. Just keep it cause it isn't that used.
960 for(float sx_ = 0; sx_ < w; sx++)
961 for(float sy_ = 0; sy_ < h; sy++)
962 if(draw_part(sx_, sy_, sx+(w-sx_), sy+(h-sy_), 1, 1, alpha, NONE_EFFECT) == -2)
966 else if(effect & VERTICAL_FLIP) // FIXME: feel free to replace this hack
968 for(float sy_ = sy; sy_ < h; sy_++)
969 if(draw_part(sx, sy_, x, y+(h-sy_), w, 1, alpha, NONE_EFFECT) == -2)
973 else if(effect & HORIZONTAL_FLIP) // FIXME: feel free to replace this hack
975 for(float sx_ = 0; sx_ < w; sx_++)
976 if(draw_part(sx_, 0, sx+(w-sx_), sy, 1, h, alpha, NONE_EFFECT) == -2)
983 /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha
984 to temp sur, blit the temp into the screen */
985 /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that
986 already have an alpha mask, yet... */
988 SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
989 (int)w, (int)h, sdl_surface->format->BitsPerPixel,
990 sdl_surface->format->Rmask, sdl_surface->format->Gmask,
991 sdl_surface->format->Bmask,
993 int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255);
994 SDL_FillRect(sdl_surface_copy, NULL, colorkey);
995 SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey);
998 SDL_BlitSurface(sdl_surface, &src, sdl_surface_copy, NULL);
999 SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha);
1001 int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest);
1003 SDL_FreeSurface (sdl_surface_copy);
1007 int ret = SDL_BlitSurface(sdl_surface, &src, screen, &dest);
1013 SurfaceSDL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uint32 effect)
1022 if(effect & SEMI_TRANSPARENT)
1025 SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
1026 sw, sh, sdl_surface->format->BitsPerPixel,
1027 sdl_surface->format->Rmask, sdl_surface->format->Gmask,
1028 sdl_surface->format->Bmask,
1031 SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
1032 SDL_SoftStretch(sdl_surface_copy, NULL, sdl_surface_copy, &dest);
1035 SDL_SetAlpha(sdl_surface_copy,SDL_SRCALPHA,alpha);
1037 int ret = SDL_BlitSurface(sdl_surface_copy,NULL,screen,&dest);
1038 SDL_FreeSurface(sdl_surface_copy);
1044 SurfaceSDL::apply_filter(int filter, Color color)
1046 ::apply_filter_to_surface(sdl_surface, filter, color);
1052 SurfaceSDL::~SurfaceSDL()