Added support for drawing effects again.
[supertux.git] / src / screen / texture.cpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
5 //
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.
10 //
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.
15 //
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
19 //  02111-1307, USA.
20
21 #include <assert.h>
22 #include <iostream>
23 #include <algorithm>
24 #include "SDL.h"
25 #include "SDL_image.h"
26 #include "texture.h"
27 #include "globals.h"
28 #include "setup.h"
29
30 Surface::Surfaces Surface::surfaces;
31
32 SurfaceData::SurfaceData(SDL_Surface* temp, int use_alpha_)
33     : type(SURFACE), surface(0), use_alpha(use_alpha_)
34 {
35   // Copy the given surface and make sure that it is not stored in
36   // video memory
37   surface = SDL_CreateRGBSurface(temp->flags & (~SDL_HWSURFACE),
38                                  temp->w, temp->h,
39                                  temp->format->BitsPerPixel,
40                                  temp->format->Rmask,
41                                  temp->format->Gmask,
42                                  temp->format->Bmask,
43                                  temp->format->Amask);
44   if(!surface)
45     st_abort("No memory left.", "");
46   SDL_SetAlpha(temp,0,0);
47   SDL_BlitSurface(temp, NULL, surface, NULL);
48 }
49
50 SurfaceData::SurfaceData(const std::string& file_, int use_alpha_)
51     : type(LOAD), surface(0), file(file_), use_alpha(use_alpha_)
52 {}
53
54 SurfaceData::SurfaceData(const std::string& file_, int x_, int y_, int w_, int h_, int use_alpha_)
55     : type(LOAD_PART), surface(0), file(file_), use_alpha(use_alpha_),
56     x(x_), y(y_), w(w_), h(h_)
57 {}
58
59 SurfaceData::~SurfaceData()
60 {
61   SDL_FreeSurface(surface);
62 }
63
64 SurfaceImpl*
65 SurfaceData::create()
66 {
67 #ifndef NOOPENGL
68   if (use_gl)
69     return create_SurfaceOpenGL();
70   else
71     return create_SurfaceSDL();
72 #else
73   return create_SurfaceSDL();
74 #endif
75 }
76
77 SurfaceSDL*
78 SurfaceData::create_SurfaceSDL()
79 {
80   switch(type)
81   {
82   case LOAD:
83     return new SurfaceSDL(file, use_alpha);
84   case LOAD_PART:
85     return new SurfaceSDL(file, x, y, w, h, use_alpha);
86   case SURFACE:
87     return new SurfaceSDL(surface, use_alpha);
88   }
89   assert(0);
90 }
91
92 SurfaceOpenGL*
93 SurfaceData::create_SurfaceOpenGL()
94 {
95 #ifndef NOOPENGL
96   switch(type)
97   {
98   case LOAD:
99     return new SurfaceOpenGL(file, use_alpha);
100   case LOAD_PART:
101     return new SurfaceOpenGL(file, x, y, w, h, use_alpha);
102   case SURFACE:
103     return new SurfaceOpenGL(surface, use_alpha);
104   }
105 #endif
106   assert(0);
107 }
108
109 #ifndef NOOPENGL
110 /* Quick utility function for texture creation */
111 static int power_of_two(int input)
112 {
113   int value = 1;
114
115   while ( value < input )
116   {
117     value <<= 1;
118   }
119   return value;
120 }
121 #endif
122
123 Surface::Surface(SDL_Surface* surf, int use_alpha)
124     : data(surf, use_alpha), w(0), h(0)
125 {
126   impl = data.create();
127   if (impl)
128   {
129     w = impl->w;
130     h = impl->h;
131   }
132   surfaces.push_back(this);
133 }
134
135 Surface::Surface(const std::string& file, int use_alpha)
136     : data(file, use_alpha), w(0), h(0)
137 {
138   impl = data.create();
139   if (impl)
140   {
141     w = impl->w;
142     h = impl->h;
143   }
144   surfaces.push_back(this);
145 }
146
147 Surface::Surface(const std::string& file, int x, int y, int w, int h, int use_alpha)
148     : data(file, x, y, w, h, use_alpha), w(0), h(0)
149 {
150   impl = data.create();
151   if (impl)
152   {
153     w = impl->w;
154     h = impl->h;
155   }
156   surfaces.push_back(this);
157 }
158
159 void
160 Surface::reload()
161 {
162   delete impl;
163   impl = data.create();
164   if (impl)
165   {
166     w = impl->w;
167     h = impl->h;
168   }
169 }
170
171 Surface::~Surface()
172 {
173 #ifdef DEBUG
174   bool found = false;
175   for(std::list<Surface*>::iterator i = surfaces.begin(); i != surfaces.end();
176       ++i)
177   {
178     if(*i == this)
179     {
180       found = true; break;
181     }
182   }
183   if(!found)
184     printf("Error: Surface freed twice!!!\n");
185 #endif
186   surfaces.remove(this);
187   delete impl;
188 }
189
190 void
191 Surface::reload_all()
192 {
193   for(Surfaces::iterator i = surfaces.begin(); i != surfaces.end(); ++i)
194   {
195     (*i)->reload();
196   }
197 }
198
199 void
200 Surface::debug_check()
201 {
202   for(Surfaces::iterator i = surfaces.begin(); i != surfaces.end(); ++i)
203   {
204     printf("Surface not freed: T:%d F:%s.\n", (*i)->data.type,
205            (*i)->data.file.c_str());
206   }
207 }
208
209 void
210 Surface::resize(int w_, int h_)
211 {
212   if (impl)
213   {
214     w = w_;
215     h = h_;
216     if (impl->resize(w_,h_) == -2)
217       reload();
218   }
219 }
220
221 SDL_Surface*
222 sdl_surface_part_from_file(const std::string& file, int x, int y, int w, int h,  int use_alpha)
223 {
224   SDL_Rect src;
225   SDL_Surface * sdl_surface;
226   SDL_Surface * temp;
227   SDL_Surface * conv;
228
229   temp = IMG_Load(file.c_str());
230
231   if (temp == NULL)
232     st_abort("Can't load", file);
233
234   /* Set source rectangle for conv: */
235
236   src.x = x;
237   src.y = y;
238   src.w = w;
239   src.h = h;
240
241   conv = SDL_CreateRGBSurface(temp->flags, w, h, temp->format->BitsPerPixel,
242                               temp->format->Rmask,
243                               temp->format->Gmask,
244                               temp->format->Bmask,
245                               temp->format->Amask);
246
247   /* #if SDL_BYTEORDER == SDL_BIG_ENDIAN
248      0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
249      #else
250
251      0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
252      #endif*/
253
254   SDL_SetAlpha(temp,0,0);
255
256   SDL_BlitSurface(temp, &src, conv, NULL);
257   if(use_alpha == IGNORE_ALPHA && !use_gl)
258     sdl_surface = SDL_DisplayFormat(conv);
259   else
260     sdl_surface = SDL_DisplayFormatAlpha(conv);
261
262   if (sdl_surface == NULL)
263     st_abort("Can't covert to display format", file);
264
265   if (use_alpha == IGNORE_ALPHA && !use_gl)
266     SDL_SetAlpha(sdl_surface, 0, 0);
267
268   SDL_FreeSurface(temp);
269   SDL_FreeSurface(conv);
270
271   return sdl_surface;
272 }
273
274 SDL_Surface*
275 sdl_surface_from_file(const std::string& file, int use_alpha)
276 {
277   SDL_Surface* sdl_surface;
278   SDL_Surface* temp;
279
280   temp = IMG_Load(file.c_str());
281
282   if (temp == NULL)
283     st_abort("Can't load", file);
284
285   if(use_alpha == IGNORE_ALPHA && !use_gl)
286     sdl_surface = SDL_DisplayFormat(temp);
287   else
288     sdl_surface = SDL_DisplayFormatAlpha(temp);
289
290   if (sdl_surface == NULL)
291     st_abort("Can't covert to display format", file);
292
293   if (use_alpha == IGNORE_ALPHA && !use_gl)
294     SDL_SetAlpha(sdl_surface, 0, 0);
295
296   SDL_FreeSurface(temp);
297
298   return sdl_surface;
299 }
300
301 SDL_Surface*
302 sdl_surface_from_sdl_surface(SDL_Surface* sdl_surf, int use_alpha)
303 {
304   SDL_Surface* sdl_surface;
305   Uint32 saved_flags;
306   Uint8  saved_alpha;
307
308   /* Save the alpha blending attributes */
309   saved_flags = sdl_surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
310   saved_alpha = sdl_surf->format->alpha;
311   if ( (saved_flags & SDL_SRCALPHA)
312        == SDL_SRCALPHA )
313   {
314     SDL_SetAlpha(sdl_surf, 0, 0);
315   }
316
317   if(use_alpha == IGNORE_ALPHA && !use_gl)
318     sdl_surface = SDL_DisplayFormat(sdl_surf);
319   else
320     sdl_surface = SDL_DisplayFormatAlpha(sdl_surf);
321
322   /* Restore the alpha blending attributes */
323   if ( (saved_flags & SDL_SRCALPHA)
324        == SDL_SRCALPHA )
325   {
326     SDL_SetAlpha(sdl_surface, saved_flags, saved_alpha);
327   }
328
329   if (sdl_surface == NULL)
330     st_abort("Can't covert to display format", "SURFACE");
331
332   if (use_alpha == IGNORE_ALPHA && !use_gl)
333     SDL_SetAlpha(sdl_surface, 0, 0);
334
335   return sdl_surface;
336 }
337
338 //---------------------------------------------------------------------------
339
340 SurfaceImpl::SurfaceImpl()
341 {}
342
343 SurfaceImpl::~SurfaceImpl()
344 {
345   SDL_FreeSurface(sdl_surface);
346 }
347
348 SDL_Surface* SurfaceImpl::get_sdl_surface() const
349 {
350   return sdl_surface;
351 }
352
353 int SurfaceImpl::resize(int w_, int h_)
354 {
355   w = w_;
356   h = h_;
357   SDL_Rect dest;
358   dest.x = 0;
359   dest.y = 0;
360   dest.w = w;
361   dest.h = h;
362   int ret = SDL_SoftStretch(sdl_surface, NULL,
363                             sdl_surface, &dest);
364   return ret;
365 }
366
367 #ifndef NOOPENGL
368 SurfaceOpenGL::SurfaceOpenGL(SDL_Surface* surf, int use_alpha)
369 {
370   sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha);
371   create_gl(sdl_surface,&gl_texture);
372
373   w = sdl_surface->w;
374   h = sdl_surface->h;
375 }
376
377 SurfaceOpenGL::SurfaceOpenGL(const std::string& file, int use_alpha)
378 {
379   sdl_surface = sdl_surface_from_file(file, use_alpha);
380   create_gl(sdl_surface,&gl_texture);
381
382   w = sdl_surface->w;
383   h = sdl_surface->h;
384 }
385
386 SurfaceOpenGL::SurfaceOpenGL(const std::string& file, int x, int y, int w, int h, int use_alpha)
387 {
388   sdl_surface = sdl_surface_part_from_file(file,x,y,w,h,use_alpha);
389   create_gl(sdl_surface, &gl_texture);
390
391   w = sdl_surface->w;
392   h = sdl_surface->h;
393 }
394
395 SurfaceOpenGL::~SurfaceOpenGL()
396 {
397   glDeleteTextures(1, &gl_texture);
398 }
399
400 void
401 SurfaceOpenGL::create_gl(SDL_Surface * surf, GLuint * tex)
402 {
403   Uint32 saved_flags;
404   Uint8  saved_alpha;
405   int w, h;
406   SDL_Surface *conv;
407
408   w = power_of_two(surf->w);
409   h = power_of_two(surf->h),
410
411 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
412       conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
413                                   0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
414 #else
415       conv = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, surf->format->BitsPerPixel,
416                                   0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);
417 #endif
418
419   /* Save the alpha blending attributes */
420   saved_flags = surf->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
421   saved_alpha = surf->format->alpha;
422   if ( (saved_flags & SDL_SRCALPHA)
423        == SDL_SRCALPHA )
424   {
425     SDL_SetAlpha(surf, 0, 0);
426   }
427
428   SDL_BlitSurface(surf, 0, conv, 0);
429
430   /* Restore the alpha blending attributes */
431   if ( (saved_flags & SDL_SRCALPHA)
432        == SDL_SRCALPHA )
433   {
434     SDL_SetAlpha(surf, saved_flags, saved_alpha);
435   }
436
437   glGenTextures(1, &*tex);
438   glBindTexture(GL_TEXTURE_2D , *tex);
439   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
440   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
441   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
442   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
443   glPixelStorei(GL_UNPACK_ROW_LENGTH, conv->pitch / conv->format->BytesPerPixel);
444   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10_A2, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, conv->pixels);
445   glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
446
447   SDL_FreeSurface(conv);
448 }
449
450 int
451 SurfaceOpenGL::draw(float x, float y, Uint8 alpha, uint32_t effect)
452 {
453   float pw = power_of_two(w);
454   float ph = power_of_two(h);
455
456   if(effect & SEMI_TRANSPARENT)
457     alpha = 128;
458
459   glEnable(GL_TEXTURE_2D);
460   glEnable(GL_BLEND);
461   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
462
463   glColor4ub(alpha, alpha, alpha, alpha);
464
465   glBindTexture(GL_TEXTURE_2D, gl_texture);
466
467   glBegin(GL_QUADS);
468
469   if(effect & VERTICAL_FLIP)
470     {
471     glTexCoord2f(0, 0);
472     glVertex2f(x, (float)h+y);
473
474     glTexCoord2f((float)w / pw, 0);
475     glVertex2f((float)w+x, (float)h+y);
476
477     glTexCoord2f((float)w / pw, (float)h / ph);
478     glVertex2f((float)w+x, y);
479     
480     glTexCoord2f(0, (float)h / ph);
481     glVertex2f(x, y);
482     }
483   else
484     {
485     glTexCoord2f(0, 0);
486     glVertex2f(x, y);
487
488     glTexCoord2f((float)w / pw, 0);
489     glVertex2f((float)w+x, y);
490
491     glTexCoord2f((float)w / pw, (float)h / ph);
492     glVertex2f((float)w+x, (float)h+y);
493
494     glTexCoord2f(0, (float)h / ph);
495     glVertex2f(x, (float)h+y);
496     }
497   glEnd();
498
499   glDisable(GL_TEXTURE_2D);
500   glDisable(GL_BLEND);
501
502   return 0;
503 }
504
505 int
506 SurfaceOpenGL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, uint32_t effect)
507 {
508   float pw = power_of_two(int(this->w));
509   float ph = power_of_two(int(this->h));
510
511   if(effect & SEMI_TRANSPARENT)
512     alpha = 128;
513
514   glBindTexture(GL_TEXTURE_2D, gl_texture);
515
516   glEnable(GL_BLEND);
517   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
518
519   glColor4ub(alpha, alpha, alpha, alpha);
520
521   glEnable(GL_TEXTURE_2D);
522
523
524   glBegin(GL_QUADS);
525
526   if(effect & VERTICAL_FLIP)
527     {
528     glTexCoord2f(sx / pw, sy / ph);
529     glVertex2f(x, y);
530
531     glTexCoord2f((float)(sx + w) / pw, sy / ph);
532     glVertex2f(w+x, y);
533
534     glTexCoord2f((sx+w) / pw, (sy+h) / ph);
535     glVertex2f(w +x, h+y);
536
537     glTexCoord2f(sx / pw, (float)(sy+h) / ph);
538     glVertex2f(x, h+y);
539     }
540   else
541     {
542     glTexCoord2f(sx / pw, (float)(sy+h) / ph);
543     glVertex2f(x, h+y);
544
545     glTexCoord2f((sx+w) / pw, (sy+h) / ph);
546     glVertex2f(w +x, h+y);
547
548     glTexCoord2f((float)(sx + w) / pw, sy / ph);
549     glVertex2f(w+x, y);
550
551     glTexCoord2f(sx / pw, sy / ph);
552     glVertex2f(x, y);
553     }
554
555   glEnd();
556
557   glDisable(GL_TEXTURE_2D);
558   glDisable(GL_BLEND);
559
560   return 0;
561 }
562
563 #if 0
564 int
565 SurfaceOpenGL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha)
566 {
567   float pw = power_of_two(int(this->w));
568   float ph = power_of_two(int(this->h));
569
570   glBindTexture(GL_TEXTURE_2D, gl_texture);
571
572   glEnable(GL_BLEND);
573   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
574
575   glColor4ub(alpha, alpha, alpha, alpha);
576
577   glEnable(GL_TEXTURE_2D);
578
579
580   glBegin(GL_QUADS);
581   glTexCoord2f(0, 0);
582   glVertex2f(x, y);
583   glTexCoord2f((float)w / pw, 0);
584   glVertex2f(sw+x, y);
585   glTexCoord2f((float)w / pw, (float)h / ph);  glVertex2f((float)sw+x, (float)sh+y);
586   glVertex2f(sw +x, sh+y);
587   glTexCoord2f(0, (float)h / ph);
588   glVertex2f(x, sh+y);
589   glEnd();
590
591   glDisable(GL_TEXTURE_2D);
592   glDisable(GL_BLEND);
593
594   return 0;
595 }
596 #endif
597
598 #endif
599
600 SurfaceSDL::SurfaceSDL(SDL_Surface* surf, int use_alpha)
601 {
602   sdl_surface = sdl_surface_from_sdl_surface(surf, use_alpha);
603   w = sdl_surface->w;
604   h = sdl_surface->h;
605 }
606
607 SurfaceSDL::SurfaceSDL(const std::string& file, int use_alpha)
608 {
609   sdl_surface = sdl_surface_from_file(file, use_alpha);
610   w = sdl_surface->w;
611   h = sdl_surface->h;
612 }
613
614 SurfaceSDL::SurfaceSDL(const std::string& file, int x, int y, int w, int h,  int use_alpha)
615 {
616   sdl_surface = sdl_surface_part_from_file(file, x, y, w, h, use_alpha);
617   w = sdl_surface->w;
618   h = sdl_surface->h;
619 }
620
621 int
622 SurfaceSDL::draw(float x, float y, Uint8 alpha, uint32_t effect)
623 {
624   SDL_Rect dest;
625
626   dest.x = (int)x;
627   dest.y = (int)y;
628   dest.w = w;
629   dest.h = h;
630
631   if(effect & SEMI_TRANSPARENT)
632     alpha = 128;
633
634   if(effect & VERTICAL_FLIP)    // FIXME: feel free to replace this hack
635     {
636     for(float sy = 0; sy < h; sy++)
637       if(draw_part(0, sy, x, y+(h-sy), w, 1, alpha, NONE_EFFECT) == -2)
638         return -2;
639     return 0;
640     }
641
642   if(alpha != 255)
643     {
644     /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha
645       to temp sur, blit the temp into the screen */
646     /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that
647       already have an alpha mask yet... */
648
649     SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
650                                     sdl_surface->w, sdl_surface->h, sdl_surface->format->BitsPerPixel,
651                                     sdl_surface->format->Rmask, sdl_surface->format->Gmask,
652                                     sdl_surface->format->Bmask,
653                                     0);
654     int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255);
655     SDL_FillRect(sdl_surface_copy, NULL, colorkey);
656     SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey);
657
658
659     SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
660     SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha);
661
662     int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest);
663
664     SDL_FreeSurface (sdl_surface_copy);
665     return ret;
666     }
667
668   int ret = SDL_BlitSurface(sdl_surface, NULL, screen, &dest);
669
670   return ret;
671 }
672
673 int
674 SurfaceSDL::draw_part(float sx, float sy, float x, float y, float w, float h, Uint8 alpha, uint32_t effect)
675 {
676   SDL_Rect src, dest;
677
678   src.x = (int)sx;
679   src.y = (int)sy;
680   src.w = (int)w;
681   src.h = (int)h;
682
683   dest.x = (int)x;
684   dest.y = (int)y;
685   dest.w = (int)w;
686   dest.h = (int)h;
687
688   if(effect & SEMI_TRANSPARENT)
689     alpha = 128;
690
691   if(effect & VERTICAL_FLIP)    // FIXME: feel free to replace this hack
692     {
693     for(float sy_ = sy; sy_ < h; sy_++)
694       if(draw_part(sx, sy_, x, y+(h-sy_), w, 1, alpha, NONE_EFFECT) == -2)
695         return -2;
696     return 0;
697     }
698
699   if(alpha != 255)
700     {
701     /* Create a Surface, make it using colorkey, blit surface into temp, apply alpha
702       to temp sur, blit the temp into the screen */
703     /* Note: this has to be done, since SDL doesn't allow to set alpha to surfaces that
704       already have an alpha mask yet... */
705
706     SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
707                                     sdl_surface->w, sdl_surface->h, sdl_surface->format->BitsPerPixel,
708                                     sdl_surface->format->Rmask, sdl_surface->format->Gmask,
709                                     sdl_surface->format->Bmask,
710                                     0);
711     int colorkey = SDL_MapRGB(sdl_surface_copy->format, 255, 0, 255);
712     SDL_FillRect(sdl_surface_copy, NULL, colorkey);
713     SDL_SetColorKey(sdl_surface_copy, SDL_SRCCOLORKEY, colorkey);
714
715
716     SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
717     SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha);
718
719     int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest);
720
721     SDL_FreeSurface (sdl_surface_copy);
722     return ret;
723     }
724
725   int ret = SDL_BlitSurface(sdl_surface, &src, screen, &dest);
726
727   return ret;
728 }
729
730 #if 0
731 int
732 SurfaceSDL::draw_stretched(float x, float y, int sw, int sh, Uint8 alpha, bool update)
733 {
734   SDL_Rect dest;
735
736   dest.x = (int)x;
737   dest.y = (int)y;
738   dest.w = (int)sw;
739   dest.h = (int)sh;
740
741   if(alpha != 255)
742     SDL_SetAlpha(sdl_surface ,SDL_SRCALPHA,alpha);
743
744
745   SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
746                                   sw, sh, sdl_surface->format->BitsPerPixel,
747                                   sdl_surface->format->Rmask, sdl_surface->format->Gmask,
748                                   sdl_surface->format->Bmask,
749                                   0);
750
751   SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
752   SDL_SoftStretch(sdl_surface_copy, NULL, sdl_surface_copy, &dest);
753
754   int ret = SDL_BlitSurface(sdl_surface_copy,NULL,screen,&dest);
755   SDL_FreeSurface(sdl_surface_copy);
756
757   if (update == UPDATE)
758     update_rect(screen, dest.x, dest.y, dest.w, dest.h);
759
760   return ret;
761 }
762 #endif
763
764 SurfaceSDL::~SurfaceSDL()
765 {}
766
767 /* EOF */