Added alpha support for SDL. Dunno if works, wasn't able to test.
authorRicardo Cruz <rick2@aeiou.pt>
Sat, 1 May 2004 11:14:40 +0000 (11:14 +0000)
committerRicardo Cruz <rick2@aeiou.pt>
Sat, 1 May 2004 11:14:40 +0000 (11:14 +0000)
SVN-Revision: 886

src/texture.cpp

index 7773b7f..f708113 100644 (file)
@@ -571,10 +571,27 @@ SurfaceSDL::draw(float x, float y, Uint8 alpha, bool update)
   dest.w = w;
   dest.h = h;
   
-  if(alpha != 255) /* SDL isn't capable of this kind of alpha :( therefore we'll leave now. */
-    return -1;
+  if(alpha != 255)
+    {
+    /* Copy the SDL surface, then make it using alpha and use it to blit into the screen */
+    SDL_Surface* sdl_surface_copy = SDL_CreateRGBSurface (sdl_surface->flags,
+      sdl_surface->w, sdl_surface->h, sdl_surface->format->BitsPerPixel,
+      sdl_surface->format->Rmask, sdl_surface->format->Gmask, sdl_surface->format->Bmask,
+      sdl_surface->format->Amask);
+
+    SDL_BlitSurface(sdl_surface, NULL, sdl_surface_copy, NULL);
+      
+    SDL_SetAlpha(sdl_surface_copy ,SDL_SRCALPHA,alpha);
+
+    int ret = SDL_BlitSurface(sdl_surface_copy, NULL, screen, &dest);
   
-  SDL_SetAlpha(sdl_surface ,SDL_SRCALPHA,alpha);
+    if (update == UPDATE)
+      SDL_UpdateRect(screen, dest.x, dest.y, dest.w, dest.h);
+    
+    SDL_FreeSurface (sdl_surface_copy) ;
+    return ret;
+    }
   int ret = SDL_BlitSurface(sdl_surface, NULL, screen, &dest);
   
   if (update == UPDATE)