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