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 "../app/globals.h"
30 #include "../app/setup.h"
32 using namespace SuperTux;
34 Surface::Surfaces Surface::surfaces;
36 SurfaceData::SurfaceData(SDL_Surface* temp, bool use_alpha_)
37 : type(SURFACE), surface(0), use_alpha(use_alpha_)
39 // Copy the given surface and make sure that it is not stored in
41 surface = SDL_CreateRGBSurface(temp->flags & (~SDL_HWSURFACE),
43 temp->format->BitsPerPixel,
49 Termination::abort("No memory left.", "");
50 SDL_SetAlpha(temp,0,0);
51 SDL_BlitSurface(temp, NULL, surface, NULL);
54 SurfaceData::SurfaceData(const std::string& file_, bool use_alpha_)
55 : type(LOAD), surface(0), file(file_), use_alpha(use_alpha_)
58 SurfaceData::SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, bool use_alpha_)
59 : type(LOAD_PART), surface(0), file(file_), use_alpha(use_alpha_),
60 x(x_), y(y_), w(w_), h(h_)
63 SurfaceData::SurfaceData(Color top_gradient_, Color bottom_gradient_, int w_, int h_)
64 : type(GRADIENT), surface(0), use_alpha(false), w(w_), h(h_)
66 top_gradient = top_gradient_;
67 bottom_gradient = bottom_gradient_;
71 SurfaceData::~SurfaceData()
73 SDL_FreeSurface(surface);
81 return create_SurfaceOpenGL();
83 return create_SurfaceSDL();
85 return create_SurfaceSDL();
90 SurfaceData::create_SurfaceSDL()
95 return new SurfaceSDL(file, use_alpha);
97 return new SurfaceSDL(file, x, y, w, h, use_alpha);
99 return new SurfaceSDL(surface, use_alpha);
101 return new SurfaceSDL(top_gradient, bottom_gradient, w, h);
107 SurfaceData::create_SurfaceOpenGL()
113 return new SurfaceOpenGL(file, use_alpha);
115 return new SurfaceOpenGL(file, x, y, w, h, use_alpha);
117 return new SurfaceOpenGL(surface, use_alpha);
119 return new SurfaceOpenGL(top_gradient, bottom_gradient, w, h);
126 /* Quick utility function for texture creation */
127 static int power_of_two(int input)
131 while ( value < input )
139 Surface::Surface(SDL_Surface* surf, bool use_alpha)
140 : data(surf, use_alpha), w(0), h(0)
142 impl = data.create();
148 surfaces.push_back(this);
151 Surface::Surface(const std::string& file, bool use_alpha)
152 : data(file, use_alpha), w(0), h(0)
154 impl = data.create();
160 surfaces.push_back(this);
163 Surface::Surface(const std::string& file, int x, int y, int w, int h, bool use_alpha)
164 : data(file, x, y, w, h, use_alpha), w(0), h(0)
166 impl = data.create();
172 surfaces.push_back(this);
175 Surface::Surface(Color top_background, Color bottom_background, int w_, int h_)
176 : data(top_background, bottom_background, w_, h_), w(0), h(0)
178 impl = data.create();
184 surfaces.push_back(this);
191 impl = data.create();
203 for(std::list<Surface*>::iterator i = surfaces.begin(); i != surfaces.end();
212 printf("Error: Surface freed twice!!!\n");
214 surfaces.remove(this);
219 Surface::reload_all()
221 for(Surfaces::iterator i = surfaces.begin(); i != surfaces.end(); ++i)
228 Surface::debug_check()
230 for(Surfaces::iterator i = surfaces.begin(); i != surfaces.end(); ++i)
232 printf("Surface not freed: T:%d F:%s.\n", (*i)->data.type,
233 (*i)->data.file.c_str());
238 Surface::resize(int w_, int h_)
244 if (impl->resize(w_,h_) == -2)
250 sdl_surface_part_from_file(const std::string& file, int x, int y, int w, int h, bool use_alpha)
253 SDL_Surface * sdl_surface;
257 temp = IMG_Load(file.c_str());
260 Termination::abort("Can't load", file);
262 /* Set source rectangle for conv: */
269 conv = SDL_CreateRGBSurface(temp->flags, w, h, temp->format->BitsPerPixel,
273 temp->format->Amask);
275 /* #if SDL_BYTEORDER == SDL_BIG_ENDIAN
276 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
279 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
282 SDL_SetAlpha(temp,0,0);
284 SDL_BlitSurface(temp, &src, conv, NULL);
285 if(use_alpha == false && !use_gl)
286 sdl_surface = SDL_DisplayFormat(conv);
288 sdl_surface = SDL_DisplayFormatAlpha(conv);
290 if (sdl_surface == NULL)
291 Termination::abort("Can't covert to display format", file);
293 if (use_alpha == false && !use_gl)
294 SDL_SetAlpha(sdl_surface, 0, 0);
296 SDL_FreeSurface(temp);
297 SDL_FreeSurface(conv);
303 sdl_surface_from_file(const std::string& file, bool use_alpha)
305 SDL_Surface* sdl_surface;
308 temp = IMG_Load(file.c_str());
311 Termination::abort("Can't load", file);
313 if(use_alpha == false && !use_gl)
314 sdl_surface = SDL_DisplayFormat(temp);
316 sdl_surface = SDL_DisplayFormatAlpha(temp);
318 if (sdl_surface == NULL)
319 Termination::abort("Can't covert to display format", file);
321 if (use_alpha == false && !use_gl)
322 SDL_SetAlpha(sdl_surface, 0, 0);
324 SDL_FreeSurface(temp);
330 SuperTux::sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, bool use_alpha)
332 SDL_Surface* sdl_surface;
336 /* Save the alpha blending attributes */
337 saved_flags = sdl_surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
338 saved_alpha = sdl_surf->format->alpha;
339 if ( (saved_flags & SDL_SRCALPHA)
342 SDL_SetAlpha(sdl_surf, 0, 0);
345 if(use_alpha == false && !use_gl)
346 sdl_surface = SDL_DisplayFormat(sdl_surf);
348 sdl_surface = SDL_DisplayFormatAlpha(sdl_surf);
350 /* Restore the alpha blending attributes */
351 if ( (saved_flags & SDL_SRCALPHA)
354 SDL_SetAlpha(sdl_surface, saved_flags, saved_alpha);
357 if (sdl_surface == NULL)
358 Termination::abort("Can't covert to display format", "SURFACE");
360 if (use_alpha == false && !use_gl)
361 SDL_SetAlpha(sdl_surface, 0, 0);
367 sdl_surface_from_gradient(Color top, Color bottom, int w, int h)
369 SDL_Surface* sdl_surface;
371 sdl_surface = SDL_CreateRGBSurface(screen->flags, w, h,
372 screen->format->BitsPerPixel, screen->format->Rmask,
373 screen->format->Gmask, screen->format->Bmask, 0);
375 if(sdl_surface == NULL)
376 Termination::abort("Cannot create surface for the gradient", "SURFACE");
380 SDL_FillRect(sdl_surface, NULL, SDL_MapRGB(sdl_surface->format,
381 top.red, top.green, top.blue));
385 float redstep = (float(bottom.red)-float(top.red)) / float(h);
386 float greenstep = (float(bottom.green)-float(top.green)) / float(h);
387 float bluestep = (float(bottom.blue) - float(top.blue)) / float(h);
393 for(float y = 0; y < h; y++)
396 SDL_FillRect(sdl_surface, &rect, SDL_MapRGB(sdl_surface->format,
397 int(float(top.red) + redstep * y),
398 int(float(top.green) + greenstep * y),
399 int(float(top.blue) + bluestep * y)));
406 //---------------------------------------------------------------------------
408 SurfaceImpl::SurfaceImpl()
411 SurfaceImpl::~SurfaceImpl()
413 SDL_FreeSurface(sdl_surface);
416 SDL_Surface* SurfaceImpl::get_sdl_surface() const
421 int SurfaceImpl::resize(int w_, int h_)
430 int ret = SDL_SoftStretch(sdl_surface, NULL,
436 SurfaceOpenGL::SurfaceOpenGL(SDL_Surface* surf, bool use_alpha)
438 sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha);
439 create_gl(sdl_surface,&gl_texture);
445 SurfaceOpenGL::SurfaceOpenGL(const std::string& file, bool use_alpha)
447 sdl_surface = sdl_surface_from_file(file, use_alpha);
448 create_gl(sdl_surface,&gl_texture);
454 SurfaceOpenGL::SurfaceOpenGL(const std::string& file_, int x_, int y_, int w_, int h_, bool use_alpha_)
456 sdl_surface = sdl_surface_part_from_file(file_,x_,y_,w_,h_,use_alpha_);
458 create_gl(sdl_surface, &gl_texture);
464 SurfaceOpenGL::SurfaceOpenGL(Color top_gradient, Color bottom_gradient, int w, int h)
466 sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient, w, h);
467 create_gl(sdl_surface, &gl_texture);
473 SurfaceOpenGL::~SurfaceOpenGL()
475 glDeleteTextures(1, &gl_texture);
479 SurfaceOpenGL::create_gl(SDL_Surface * surf, GLuint * tex)
486 w = power_of_two(surf->w);
487 h = power_of_two(surf->h),
489 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
490 conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
491 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
493 conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
494 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
497 /* Save the alpha blending attributes */
498 saved_flags = surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
499 saved_alpha = surf->format->alpha;
500 if ( (saved_flags & SDL_SRCALPHA)
503 SDL_SetAlpha(surf, 0, 0);
506 SDL_BlitSurface(surf, 0, conv, 0);
508 /* Restore the alpha blending attributes */
509 if ( (saved_flags & SDL_SRCALPHA)
512 SDL_SetAlpha(surf, saved_flags, saved_alpha);
515 // We check all the pixels of the surface to figure out which
516 // internal format OpenGL should use for storing it, ie. if no alpha
517 // is present store in RGB instead of RGBA, this saves a few bytes
518 // of memory, but much more importantly it makes the game look
519 // *much* better in 16bit color mode
520 int internal_format = GL_RGB10_A2;
521 bool has_alpha = false;
523 unsigned char* buf = static_cast<unsigned char*>(conv->pixels);
524 for (int y = 0; y < surf->h; ++y)
525 for (int x = 0; x < surf->w; ++x)
527 if (buf[(conv->pitch*y + x*4) + 3] != 255)
536 internal_format = GL_RGB;
539 glGenTextures(1, &*tex);
540 glBindTexture(GL_TEXTURE_2D , *tex);
541 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
542 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
543 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
544 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
545 glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel);
546 glTexImage2D(GL_TEXTURE_2D, 0, internal_format, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels);
547 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
549 SDL_FreeSurface(conv);
553 SurfaceOpenGL::draw(float x, float y, Uint8 alpha, Uint32 effect)
555 float pw = power_of_two(w);
556 float ph = power_of_two(h);
558 if(effect & SEMI_TRANSPARENT)
561 glEnable(GL_TEXTURE_2D);
563 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
565 glColor4ub(alpha, alpha, alpha, alpha);
567 glBindTexture(GL_TEXTURE_2D, gl_texture);
571 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
574 glVertex2f((float)w+x, (float)h+y);
576 glTexCoord2f((float)w / pw, 0);
577 glVertex2f(x, (float)h+y);
579 glTexCoord2f((float)w / pw, (float)h / ph);
582 glTexCoord2f(0, (float)h / ph);
583 glVertex2f((float)w+x, y);
585 else if(effect & VERTICAL_FLIP)
588 glVertex2f(x, (float)h+y);
590 glTexCoord2f((float)w / pw, 0);
591 glVertex2f((float)w+x, (float)h+y);
593 glTexCoord2f((float)w / pw, (float)h / ph);
594 glVertex2f((float)w+x, y);
596 glTexCoord2f(0, (float)h / ph);
599 else if(effect & HORIZONTAL_FLIP)
602 glVertex2f((float)w+x, y);
604 glTexCoord2f((float)w / pw, 0);
607 glTexCoord2f((float)w / pw, (float)h / ph);
608 glVertex2f(x, (float)h+y);
610 glTexCoord2f(0, (float)h / ph);
611 glVertex2f((float)w+x, (float)h+y);
618 glTexCoord2f((float)w / pw, 0);
619 glVertex2f((float)w+x, y);
621 glTexCoord2f((float)w / pw, (float)h / ph);
622 glVertex2f((float)w+x, (float)h+y);
624 glTexCoord2f(0, (float)h / ph);
625 glVertex2f(x, (float)h+y);
629 glDisable(GL_TEXTURE_2D);
636 SurfaceOpenGL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect)
638 float pw = power_of_two(int(this->w));
639 float ph = power_of_two(int(this->h));
641 if(effect & SEMI_TRANSPARENT)
644 glBindTexture(GL_TEXTURE_2D, gl_texture);
647 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
649 glColor4ub(alpha, alpha, alpha, alpha);
651 glEnable(GL_TEXTURE_2D);
656 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
658 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
659 glVertex2f((float)w+x, (float)h+y);
661 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
662 glVertex2f(x, (float)h+y);
664 glTexCoord2f((float)(sx + w) / pw, sy / ph);
667 glTexCoord2f(sx / pw, sy / ph);
668 glVertex2f((float)w+x, y);
670 else if(effect & VERTICAL_FLIP)
672 glTexCoord2f(sx / pw, sy / ph);
675 glTexCoord2f((float)(sx + w) / pw, sy / ph);
678 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
679 glVertex2f(w +x, h+y);
681 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
684 else if(effect & HORIZONTAL_FLIP)
686 glTexCoord2f(sx / pw, sy / ph);
687 glVertex2f((float)w+x, y);
689 glTexCoord2f((float)(sx + w) / pw, sy / ph);
692 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
693 glVertex2f(x, (float)h+y);
695 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
696 glVertex2f((float)w+x, (float)h+y);
700 glTexCoord2f(sx / pw, (float)(sy+h) / ph);
703 glTexCoord2f((sx+w) / pw, (sy+h) / ph);
704 glVertex2f(w +x, h+y);
706 glTexCoord2f((float)(sx + w) / pw, sy / ph);
709 glTexCoord2f(sx / pw, sy / ph);
715 glDisable(GL_TEXTURE_2D);
722 SurfaceOpenGL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uint32 effect)
724 if(effect & SEMI_TRANSPARENT)
727 float pw = power_of_two(sw);
728 float ph = power_of_two(sh);
730 if(effect & SEMI_TRANSPARENT)
733 glEnable(GL_TEXTURE_2D);
735 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
737 glColor4ub(alpha, alpha, alpha, alpha);
739 glBindTexture(GL_TEXTURE_2D, gl_texture);
743 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
746 glVertex2f((float)sw+x, (float)sh+y);
748 glTexCoord2f((float)w / pw, 0);
749 glVertex2f(x, (float)sh+y);
751 glTexCoord2f((float)w / pw, (float)h / ph);
754 glTexCoord2f(0, (float)h / ph);
755 glVertex2f((float)sw+x, y);
757 else if(effect & VERTICAL_FLIP)
760 glVertex2f(x, (float)sh+y);
762 glTexCoord2f((float)w / pw, 0);
763 glVertex2f((float)sw+x, (float)sh+y);
765 glTexCoord2f((float)w / pw, (float)h / ph);
766 glVertex2f((float)sw+x, y);
768 glTexCoord2f(0, (float)h / ph);
771 else if(effect & HORIZONTAL_FLIP)
774 glVertex2f((float)sw+x, y);
776 glTexCoord2f((float)w / pw, 0);
779 glTexCoord2f((float)w / pw, (float)h / ph);
780 glVertex2f(x, (float)sh+y);
782 glTexCoord2f(0, (float)h / ph);
783 glVertex2f((float)sw+x, (float)sh+y);
790 glTexCoord2f((float)w / pw, 0);
791 glVertex2f((float)sw+x, y);
793 glTexCoord2f((float)w / pw, (float)h / ph);
794 glVertex2f((float)sw+x, (float)sh+y);
796 glTexCoord2f(0, (float)h / ph);
797 glVertex2f(x, (float)sh+y);
801 glDisable(GL_TEXTURE_2D);
809 SurfaceSDL::SurfaceSDL(SDL_Surface* surf, bool use_alpha)
811 sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha);
816 SurfaceSDL::SurfaceSDL(const std::string& file, bool use_alpha)
818 sdl_surface = sdl_surface_from_file(file, use_alpha);
823 SurfaceSDL::SurfaceSDL(const std::string& file, int x, int y, int w, int h, bool use_alpha)
825 sdl_surface = sdl_surface_part_from_file(file, x, y, w, h, use_alpha);
830 SurfaceSDL::SurfaceSDL(Color top_gradient, Color bottom_gradient, int w, int h)
832 sdl_surface = sdl_surface_from_gradient(top_gradient, bottom_gradient, w, h);
838 SurfaceSDL::draw(float x, float y, Uint8 alpha, Uint32 effect)
847 if(effect & SEMI_TRANSPARENT)
850 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
852 // FIXME: this hack is damn slow. Just keep it cause it isn't that used.
853 for(float sx = 0; sx < w; sx++)
854 for(float sy = 0; sy < h; sy++)
855 if(draw_part(sx, sy, x+(w-sx), y+(h-sy), 1, 1, alpha, NONE_EFFECT) == -2)
859 else if(effect & VERTICAL_FLIP) // FIXME: feel free to replace this hack
861 for(float sy = 0; sy < h; sy++)
862 if(draw_part(0, sy, x, y+(h-sy), w, 1, alpha, NONE_EFFECT) == -2)
866 else if(effect & HORIZONTAL_FLIP) // FIXME: feel free to replace this hack
868 for(float sx = 0; sx < w; sx++)
869 if(draw_part(sx, 0, x+(w-sx), y, 1, h, alpha, NONE_EFFECT) == -2)
876 /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha
877 to temp sur, blit the temp into the screen */
878 /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that
879 already have an alpha mask yet... */
881 SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
882 sdl_surface->w, sdl_surface->h, sdl_surface->format->BitsPerPixel,
883 sdl_surface->format->Rmask, sdl_surface->format->Gmask,
884 sdl_surface->format->Bmask,
886 int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255);
887 SDL_FillRect(sdl_surface_copy, NULL, colorkey);
888 SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey);
891 SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
892 SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha);
894 int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest);
896 SDL_FreeSurface (sdl_surface_copy);
900 int ret = SDL_BlitSurface(sdl_surface, NULL, screen, &dest);
906 SurfaceSDL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, Uint32 effect)
920 if(effect & SEMI_TRANSPARENT)
923 if(effect & VERTICAL_FLIP & HORIZONTAL_FLIP)
925 // FIXME: this hack is damn slow. Just keep it cause it isn't that used.
926 for(float sx_ = 0; sx_ < w; sx++)
927 for(float sy_ = 0; sy_ < h; sy++)
928 if(draw_part(sx_, sy_, sx+(w-sx_), sy+(h-sy_), 1, 1, alpha, NONE_EFFECT) == -2)
932 else if(effect & VERTICAL_FLIP) // FIXME: feel free to replace this hack
934 for(float sy_ = sy; sy_ < h; sy_++)
935 if(draw_part(sx, sy_, x, y+(h-sy_), w, 1, alpha, NONE_EFFECT) == -2)
939 else if(effect & HORIZONTAL_FLIP) // FIXME: feel free to replace this hack
941 for(float sx_ = 0; sx_ < w; sx_++)
942 if(draw_part(sx_, 0, sx+(w-sx_), sy, 1, h, alpha, NONE_EFFECT) == -2)
949 /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha
950 to temp sur, blit the temp into the screen */
951 /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that
952 already have an alpha mask yet... */
954 SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
955 sdl_surface->w, sdl_surface->h, sdl_surface->format->BitsPerPixel,
956 sdl_surface->format->Rmask, sdl_surface->format->Gmask,
957 sdl_surface->format->Bmask,
959 int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255);
960 SDL_FillRect(sdl_surface_copy, NULL, colorkey);
961 SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey);
964 SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
965 SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha);
967 int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest);
969 SDL_FreeSurface (sdl_surface_copy);
973 int ret = SDL_BlitSurface(sdl_surface, &src, screen, &dest);
979 SurfaceSDL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, Uint32 effect)
988 if(effect & SEMI_TRANSPARENT)
991 SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
992 sw, sh, sdl_surface->format->BitsPerPixel,
993 sdl_surface->format->Rmask, sdl_surface->format->Gmask,
994 sdl_surface->format->Bmask,
997 SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
998 SDL_SoftStretch(sdl_surface_copy, NULL, sdl_surface_copy, &dest);
1001 SDL_SetAlpha(sdl_surface_copy,SDL_SRCALPHA,alpha);
1003 int ret = SDL_BlitSurface(sdl_surface_copy,NULL,screen,&dest);
1004 SDL_FreeSurface(sdl_surface_copy);
1009 SurfaceSDL::~SurfaceSDL()