mirror of
https://github.com/love2d/love.git
synced 2026-08-19 20:19:42 +02:00
Added subtractive and multiplicative blend modes (thanks vrld)
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2006-2010 LOVE Development Team
|
* Copyright (c) 2006-2010 LOVE Development Team
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
* arising from the use of this software.
|
* arising from the use of this software.
|
||||||
*
|
*
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
* including commercial applications, and to alter it and redistribute it
|
* including commercial applications, and to alter it and redistribute it
|
||||||
* freely, subject to the following restrictions:
|
* freely, subject to the following restrictions:
|
||||||
*
|
*
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
* 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
|
* claim that you wrote the original software. If you use this software
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
@@ -88,7 +88,7 @@ namespace graphics
|
|||||||
return pointStyles.find(in, out);
|
return pointStyles.find(in, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM>::Entry Graphics::drawModeEntries[] =
|
StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM>::Entry Graphics::drawModeEntries[] =
|
||||||
{
|
{
|
||||||
{ "line", Graphics::DRAW_LINE },
|
{ "line", Graphics::DRAW_LINE },
|
||||||
{ "fill", Graphics::DRAW_FILL },
|
{ "fill", Graphics::DRAW_FILL },
|
||||||
@@ -96,7 +96,7 @@ namespace graphics
|
|||||||
|
|
||||||
StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM> Graphics::drawModes(Graphics::drawModeEntries, sizeof(Graphics::drawModeEntries));
|
StringMap<Graphics::DrawMode, Graphics::DRAW_MAX_ENUM> Graphics::drawModes(Graphics::drawModeEntries, sizeof(Graphics::drawModeEntries));
|
||||||
|
|
||||||
StringMap<Graphics::AlignMode, Graphics::ALIGN_MAX_ENUM>::Entry Graphics::alignModeEntries[] =
|
StringMap<Graphics::AlignMode, Graphics::ALIGN_MAX_ENUM>::Entry Graphics::alignModeEntries[] =
|
||||||
{
|
{
|
||||||
{ "left", Graphics::ALIGN_LEFT },
|
{ "left", Graphics::ALIGN_LEFT },
|
||||||
{ "right", Graphics::ALIGN_RIGHT },
|
{ "right", Graphics::ALIGN_RIGHT },
|
||||||
@@ -105,15 +105,17 @@ namespace graphics
|
|||||||
|
|
||||||
StringMap<Graphics::AlignMode, Graphics::ALIGN_MAX_ENUM> Graphics::alignModes(Graphics::alignModeEntries, sizeof(Graphics::alignModeEntries));
|
StringMap<Graphics::AlignMode, Graphics::ALIGN_MAX_ENUM> Graphics::alignModes(Graphics::alignModeEntries, sizeof(Graphics::alignModeEntries));
|
||||||
|
|
||||||
StringMap<Graphics::BlendMode, Graphics::BLEND_MAX_ENUM>::Entry Graphics::blendModeEntries[] =
|
StringMap<Graphics::BlendMode, Graphics::BLEND_MAX_ENUM>::Entry Graphics::blendModeEntries[] =
|
||||||
{
|
{
|
||||||
{ "alpha", Graphics::BLEND_ALPHA },
|
{ "alpha", Graphics::BLEND_ALPHA },
|
||||||
{ "additive", Graphics::BLEND_ADDITIVE },
|
{ "additive", Graphics::BLEND_ADDITIVE },
|
||||||
|
{ "subtractive", Graphics::BLEND_SUBTRACTIVE },
|
||||||
|
{ "multiplicative", Graphics::BLEND_MULTIPLICATIVE },
|
||||||
};
|
};
|
||||||
|
|
||||||
StringMap<Graphics::BlendMode, Graphics::BLEND_MAX_ENUM> Graphics::blendModes(Graphics::blendModeEntries, sizeof(Graphics::blendModeEntries));
|
StringMap<Graphics::BlendMode, Graphics::BLEND_MAX_ENUM> Graphics::blendModes(Graphics::blendModeEntries, sizeof(Graphics::blendModeEntries));
|
||||||
|
|
||||||
StringMap<Graphics::ColorMode, Graphics::COLOR_MAX_ENUM>::Entry Graphics::colorModeEntries[] =
|
StringMap<Graphics::ColorMode, Graphics::COLOR_MAX_ENUM>::Entry Graphics::colorModeEntries[] =
|
||||||
{
|
{
|
||||||
{ "replace", Graphics::COLOR_REPLACE },
|
{ "replace", Graphics::COLOR_REPLACE },
|
||||||
{ "modulate", Graphics::COLOR_MODULATE },
|
{ "modulate", Graphics::COLOR_MODULATE },
|
||||||
@@ -121,7 +123,7 @@ namespace graphics
|
|||||||
|
|
||||||
StringMap<Graphics::ColorMode, Graphics::COLOR_MAX_ENUM> Graphics::colorModes(Graphics::colorModeEntries, sizeof(Graphics::colorModeEntries));
|
StringMap<Graphics::ColorMode, Graphics::COLOR_MAX_ENUM> Graphics::colorModes(Graphics::colorModeEntries, sizeof(Graphics::colorModeEntries));
|
||||||
|
|
||||||
StringMap<Graphics::LineStyle, Graphics::LINE_MAX_ENUM>::Entry Graphics::lineStyleEntries[] =
|
StringMap<Graphics::LineStyle, Graphics::LINE_MAX_ENUM>::Entry Graphics::lineStyleEntries[] =
|
||||||
{
|
{
|
||||||
{ "smooth", Graphics::LINE_SMOOTH },
|
{ "smooth", Graphics::LINE_SMOOTH },
|
||||||
{ "rough", Graphics::LINE_ROUGH }
|
{ "rough", Graphics::LINE_ROUGH }
|
||||||
@@ -129,7 +131,7 @@ namespace graphics
|
|||||||
|
|
||||||
StringMap<Graphics::LineStyle, Graphics::LINE_MAX_ENUM> Graphics::lineStyles(Graphics::lineStyleEntries, sizeof(Graphics::lineStyleEntries));
|
StringMap<Graphics::LineStyle, Graphics::LINE_MAX_ENUM> Graphics::lineStyles(Graphics::lineStyleEntries, sizeof(Graphics::lineStyleEntries));
|
||||||
|
|
||||||
StringMap<Graphics::PointStyle, Graphics::POINT_MAX_ENUM>::Entry Graphics::pointStyleEntries[] =
|
StringMap<Graphics::PointStyle, Graphics::POINT_MAX_ENUM>::Entry Graphics::pointStyleEntries[] =
|
||||||
{
|
{
|
||||||
{ "smooth", Graphics::POINT_SMOOTH },
|
{ "smooth", Graphics::POINT_SMOOTH },
|
||||||
{ "rough", Graphics::POINT_ROUGH }
|
{ "rough", Graphics::POINT_ROUGH }
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright (c) 2006-2010 LOVE Development Team
|
* Copyright (c) 2006-2010 LOVE Development Team
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
* arising from the use of this software.
|
* arising from the use of this software.
|
||||||
*
|
*
|
||||||
* Permission is granted to anyone to use this software for any purpose,
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
* including commercial applications, and to alter it and redistribute it
|
* including commercial applications, and to alter it and redistribute it
|
||||||
* freely, subject to the following restrictions:
|
* freely, subject to the following restrictions:
|
||||||
*
|
*
|
||||||
* 1. The origin of this software must not be misrepresented; you must not
|
* 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
|
* claim that you wrote the original software. If you use this software
|
||||||
* in a product, an acknowledgment in the product documentation would be
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
@@ -35,36 +35,38 @@ namespace graphics
|
|||||||
|
|
||||||
enum DrawMode
|
enum DrawMode
|
||||||
{
|
{
|
||||||
DRAW_LINE = 1,
|
DRAW_LINE = 1,
|
||||||
DRAW_FILL,
|
DRAW_FILL,
|
||||||
DRAW_MAX_ENUM
|
DRAW_MAX_ENUM
|
||||||
};
|
};
|
||||||
|
|
||||||
enum AlignMode
|
enum AlignMode
|
||||||
{
|
{
|
||||||
ALIGN_LEFT = 1,
|
ALIGN_LEFT = 1,
|
||||||
ALIGN_CENTER,
|
ALIGN_CENTER,
|
||||||
ALIGN_RIGHT,
|
ALIGN_RIGHT,
|
||||||
ALIGN_MAX_ENUM
|
ALIGN_MAX_ENUM
|
||||||
};
|
};
|
||||||
|
|
||||||
enum BlendMode
|
enum BlendMode
|
||||||
{
|
{
|
||||||
BLEND_ALPHA = 1,
|
BLEND_ALPHA = 1,
|
||||||
BLEND_ADDITIVE,
|
BLEND_ADDITIVE,
|
||||||
|
BLEND_SUBTRACTIVE,
|
||||||
|
BLEND_MULTIPLICATIVE,
|
||||||
BLEND_MAX_ENUM
|
BLEND_MAX_ENUM
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ColorMode
|
enum ColorMode
|
||||||
{
|
{
|
||||||
COLOR_MODULATE = 1,
|
COLOR_MODULATE = 1,
|
||||||
COLOR_REPLACE,
|
COLOR_REPLACE,
|
||||||
COLOR_MAX_ENUM
|
COLOR_MAX_ENUM
|
||||||
};
|
};
|
||||||
|
|
||||||
enum LineStyle
|
enum LineStyle
|
||||||
{
|
{
|
||||||
LINE_ROUGH = 1,
|
LINE_ROUGH = 1,
|
||||||
LINE_SMOOTH,
|
LINE_SMOOTH,
|
||||||
LINE_MAX_ENUM
|
LINE_MAX_ENUM
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -533,10 +533,19 @@ namespace opengl
|
|||||||
|
|
||||||
void Graphics::setBlendMode( Graphics::BlendMode mode )
|
void Graphics::setBlendMode( Graphics::BlendMode mode )
|
||||||
{
|
{
|
||||||
if(mode == BLEND_ADDITIVE)
|
glAlphaFunc(GL_GEQUAL, 0);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
|
||||||
else // mode == BLEND_ALPHA
|
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);
|
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 )
|
void Graphics::setColorMode ( Graphics::ColorMode mode )
|
||||||
|
|||||||
Reference in New Issue
Block a user