From: Ingo Ruhnke Date: Thu, 31 Jul 2014 03:21:32 +0000 (+0200) Subject: Implemented Texture color modification X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=88effe6802b76fad47308d312969ef6455134078;p=supertux.git Implemented Texture color modification --- diff --git a/src/video/sdl/sdl_renderer.cpp b/src/video/sdl/sdl_renderer.cpp index 654e729b5..a83a14f9e 100644 --- a/src/video/sdl/sdl_renderer.cpp +++ b/src/video/sdl/sdl_renderer.cpp @@ -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 = boost::dynamic_pointer_cast(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(request.color.red * 255); + Uint8 g = static_cast(request.color.green * 255); + Uint8 b = static_cast(request.color.blue * 255); + Uint8 a = static_cast(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(request.color.red * 255); + Uint8 g = static_cast(request.color.green * 255); + Uint8 b = static_cast(request.color.blue * 255); + Uint8 a = static_cast(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);