Implemented Texture color modification
authorIngo Ruhnke <grumbel@gmail.com>
Thu, 31 Jul 2014 03:21:32 +0000 (05:21 +0200)
committerIngo Ruhnke <grumbel@gmail.com>
Thu, 31 Jul 2014 03:21:32 +0000 (05:21 +0200)
src/video/sdl/sdl_renderer.cpp

index 654e729..a83a14f 100644 (file)
@@ -93,7 +93,7 @@ SDLRenderer::~SDLRenderer()
 void
 SDLRenderer::draw_surface(const DrawingRequest& request)
 {
-  //FIXME: support parameters request.alpha, request.angle, request.blend
+  //FIXME: support parameters request.angle, request.blend
   const Surface* surface = (const Surface*) request.request_data;
   boost::shared_ptr<SDLTexture> sdltexture = boost::dynamic_pointer_cast<SDLTexture>(surface->get_texture());
 
@@ -103,6 +103,13 @@ SDLRenderer::draw_surface(const DrawingRequest& request)
   dst_rect.w = sdltexture->get_image_width();
   dst_rect.h = sdltexture->get_image_height();
 
+  Uint8 r = static_cast<Uint8>(request.color.red * 255);
+  Uint8 g = static_cast<Uint8>(request.color.green * 255);
+  Uint8 b = static_cast<Uint8>(request.color.blue * 255);
+  Uint8 a = static_cast<Uint8>(request.color.alpha * request.alpha * 255);
+  SDL_SetTextureColorMod(sdltexture->get_texture(), r, g, b);
+  SDL_SetTextureAlphaMod(sdltexture->get_texture(), a);
+
   if (surface->get_flipx())
   {
     SDL_RenderCopyEx(renderer, sdltexture->get_texture(), NULL, &dst_rect, 0, NULL, SDL_FLIP_HORIZONTAL);
@@ -130,7 +137,7 @@ SDLRenderer::draw_surface(const DrawingRequest& request)
 void
 SDLRenderer::draw_surface_part(const DrawingRequest& request)
 {
-  //FIXME: support parameters request.alpha, request.angle, request.blend
+  //FIXME: support parameters request.angle, request.blend
   const SurfacePartRequest* surface = (const SurfacePartRequest*) request.request_data;
   const SurfacePartRequest* surfacepartrequest = (SurfacePartRequest*) request.request_data;
 
@@ -148,6 +155,13 @@ SDLRenderer::draw_surface_part(const DrawingRequest& request)
   dst_rect.w = surfacepartrequest->size.x;
   dst_rect.h = surfacepartrequest->size.y;
 
+  Uint8 r = static_cast<Uint8>(request.color.red * 255);
+  Uint8 g = static_cast<Uint8>(request.color.green * 255);
+  Uint8 b = static_cast<Uint8>(request.color.blue * 255);
+  Uint8 a = static_cast<Uint8>(request.color.alpha * request.alpha * 255);
+  SDL_SetTextureColorMod(sdltexture->get_texture(), r, g, b);
+  SDL_SetTextureAlphaMod(sdltexture->get_texture(), a);
+
   if (surface->surface->get_flipx())
   {
     SDL_RenderCopyEx(renderer, sdltexture->get_texture(), &src_rect, &dst_rect, 0, NULL, SDL_FLIP_HORIZONTAL);