From 8f781e9f135d942432cdce2e9a2a3f89ac12f63d Mon Sep 17 00:00:00 2001 From: Bill Meltsner Date: Thu, 26 Jan 2012 15:00:40 -0500 Subject: [PATCH] Add "combine" color mode, for colorizing images (see https://love2d.org/forums/viewtopic.php?f=4&t=7648 ) --- src/modules/graphics/Graphics.cpp | 1 + src/modules/graphics/Graphics.h | 1 + src/modules/graphics/opengl/Graphics.cpp | 9 ++++++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 9dbc2d825..345e0113f 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -130,6 +130,7 @@ namespace graphics { { "replace", Graphics::COLOR_REPLACE }, { "modulate", Graphics::COLOR_MODULATE }, + { "combine", Graphics::COLOR_COMBINE }, }; StringMap Graphics::colorModes(Graphics::colorModeEntries, sizeof(Graphics::colorModeEntries)); diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 874057c42..bb4a64be8 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -62,6 +62,7 @@ namespace graphics { COLOR_MODULATE = 1, COLOR_REPLACE, + COLOR_COMBINE, COLOR_MAX_ENUM }; diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 1e0f15eb6..8ee3a6ba2 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -530,6 +530,11 @@ namespace opengl { if (mode == COLOR_MODULATE) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + else if (mode == COLOR_COMBINE) { + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_ADD_SIGNED); + glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE); + } else // mode = COLOR_REPLACE glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); } @@ -567,7 +572,9 @@ namespace opengl if (mode == GL_MODULATE) return COLOR_MODULATE; - else // // mode == GL_REPLACE + else if (mode == GL_COMBINE) + return COLOR_COMBINE; + else // mode == GL_REPLACE return COLOR_REPLACE; }