From 9ba06d65f610523b9e77d832adb79464eea9f375 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Sat, 28 Aug 2010 17:27:35 +0200 Subject: [PATCH] Added subtractive and multiplicative blend modes (thanks vrld) --- src/modules/graphics/Graphics.cpp | 20 +++++++++++--------- src/modules/graphics/Graphics.h | 20 +++++++++++--------- src/modules/graphics/opengl/Graphics.cpp | 15 ++++++++++++--- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index aefa9f793..1e4f4baba 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -1,14 +1,14 @@ /** * Copyright (c) 2006-2010 LOVE Development Team -* +* * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. -* +* * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: -* +* * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be @@ -88,7 +88,7 @@ namespace graphics return pointStyles.find(in, out); } - StringMap::Entry Graphics::drawModeEntries[] = + StringMap::Entry Graphics::drawModeEntries[] = { { "line", Graphics::DRAW_LINE }, { "fill", Graphics::DRAW_FILL }, @@ -96,7 +96,7 @@ namespace graphics StringMap Graphics::drawModes(Graphics::drawModeEntries, sizeof(Graphics::drawModeEntries)); - StringMap::Entry Graphics::alignModeEntries[] = + StringMap::Entry Graphics::alignModeEntries[] = { { "left", Graphics::ALIGN_LEFT }, { "right", Graphics::ALIGN_RIGHT }, @@ -105,15 +105,17 @@ namespace graphics StringMap Graphics::alignModes(Graphics::alignModeEntries, sizeof(Graphics::alignModeEntries)); - StringMap::Entry Graphics::blendModeEntries[] = + StringMap::Entry Graphics::blendModeEntries[] = { { "alpha", Graphics::BLEND_ALPHA }, { "additive", Graphics::BLEND_ADDITIVE }, + { "subtractive", Graphics::BLEND_SUBTRACTIVE }, + { "multiplicative", Graphics::BLEND_MULTIPLICATIVE }, }; StringMap Graphics::blendModes(Graphics::blendModeEntries, sizeof(Graphics::blendModeEntries)); - StringMap::Entry Graphics::colorModeEntries[] = + StringMap::Entry Graphics::colorModeEntries[] = { { "replace", Graphics::COLOR_REPLACE }, { "modulate", Graphics::COLOR_MODULATE }, @@ -121,7 +123,7 @@ namespace graphics StringMap Graphics::colorModes(Graphics::colorModeEntries, sizeof(Graphics::colorModeEntries)); - StringMap::Entry Graphics::lineStyleEntries[] = + StringMap::Entry Graphics::lineStyleEntries[] = { { "smooth", Graphics::LINE_SMOOTH }, { "rough", Graphics::LINE_ROUGH } @@ -129,7 +131,7 @@ namespace graphics StringMap Graphics::lineStyles(Graphics::lineStyleEntries, sizeof(Graphics::lineStyleEntries)); - StringMap::Entry Graphics::pointStyleEntries[] = + StringMap::Entry Graphics::pointStyleEntries[] = { { "smooth", Graphics::POINT_SMOOTH }, { "rough", Graphics::POINT_ROUGH } diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 2382f0f36..5a31c2824 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -1,14 +1,14 @@ /** * Copyright (c) 2006-2010 LOVE Development Team -* +* * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. -* +* * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: -* +* * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be @@ -35,36 +35,38 @@ namespace graphics enum DrawMode { - DRAW_LINE = 1, + DRAW_LINE = 1, DRAW_FILL, DRAW_MAX_ENUM }; enum AlignMode { - ALIGN_LEFT = 1, - ALIGN_CENTER, + ALIGN_LEFT = 1, + ALIGN_CENTER, ALIGN_RIGHT, ALIGN_MAX_ENUM }; enum BlendMode { - BLEND_ALPHA = 1, + BLEND_ALPHA = 1, BLEND_ADDITIVE, + BLEND_SUBTRACTIVE, + BLEND_MULTIPLICATIVE, BLEND_MAX_ENUM }; enum ColorMode { - COLOR_MODULATE = 1, + COLOR_MODULATE = 1, COLOR_REPLACE, COLOR_MAX_ENUM }; enum LineStyle { - LINE_ROUGH = 1, + LINE_ROUGH = 1, LINE_SMOOTH, LINE_MAX_ENUM }; diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 28e58d283..8fc08a4cc 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -533,10 +533,19 @@ namespace opengl void Graphics::setBlendMode( Graphics::BlendMode mode ) { - if(mode == BLEND_ADDITIVE) - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - else // mode == BLEND_ALPHA + glAlphaFunc(GL_GEQUAL, 0); + + if (mode == BLEND_SUBTRACTIVE) + glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); + else + glBlendEquation(GL_FUNC_ADD); + + if (mode == BLEND_ALPHA) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + else if (mode == BLEND_MULTIPLICATIVE) + glBlendFunc(GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA); + else + glBlendFunc(GL_SRC_ALPHA, GL_ONE); } void Graphics::setColorMode ( Graphics::ColorMode mode )