GSDP:GAM100/CProcessing/blendMode()
From Inside
< GSDP:GAM100 | CProcessing
blendMode()
Description
Set the blend mode for subsequent draw calls. See CP_BLEND_MODE for the different blend modes you can set and use.
Parameters
blendMode(CP_BLEND_MODE blendMode)
- blendMode - (CP_BLEND_MODE) The new blend mode to set the program to.
Example
static int currBlendMode = CP_BLEND_ALPHA;
static bool IsCMY = false;
static bool IsAlpha = false;
void DrawBackground()
{
// draw background with normal alpha blending, half dark, half light
blendMode(CP_BLEND_ALPHA);
background(color(50, 50, 50, 255));
fill(color(200, 200, 200, 255));
rect(0, 0, canvasWidth * 0.5f, (float)canvasHeight);
}
void DrawCircles()
{
// setup position, size and color values
float centerX = canvasWidth * 0.5f;
float centerY = canvasHeight * 0.5f;
float circleRadius = 100.0f;
float offset = 60.0f;
int bonusColor = 0;
if (IsCMY == true)
{
bonusColor = 255;
}
int A = 255;
if (IsAlpha == true)
{
A = 128;
}
// set current blend mode for circle drawing
blendMode(currBlendMode);
// red circle
fill(color(255, bonusColor, 0, A));
circle(centerX - offset, centerY - offset, circleRadius);
// green circle
fill(color(0, 255, bonusColor, A));
circle(centerX + offset, centerY - offset, circleRadius);
// blue circle
fill(color(bonusColor, 0, 255, A));
circle(centerX, centerY + offset, circleRadius);
}
void PrintBlendMode()
{
char* names[] =
{
"CP_BLEND_ALPHA",
"CP_BLEND_ADD",
"CP_BLEND_SUBTRACT",
"CP_BLEND_MULTIPLY",
"CP_BLEND_MIN",
"CP_BLEND_MAX"
};
blendMode(CP_BLEND_ALPHA);
fill(color(150, 0, 150, 255));
text(names[currBlendMode], 20, 50);
}
void HandleInput()
{
// Press "C" to toggle RGB to CMY circle colors
if (keyReleased(KEY_C))
{
IsCMY = !IsCMY;
}
// Press "A" to toggle alpha value to draw semi-transparent circles
if (keyReleased(KEY_A))
{
IsAlpha = !IsAlpha;
}
// Press "]" to switch blend mode
if (keyReleased(KEY_RIGHT_BRACKET))
{
++currBlendMode;
}
// Press "[" to switch blend mode
else if (keyReleased(KEY_LEFT_BRACKET))
{
--currBlendMode;
}
// keep blend mode within valid range
currBlendMode = clampInt(currBlendMode, 0, CP_BLEND_MAX);
}
void init()
{
noStroke();
textSize(40);
}
void update()
{
// draw background, half dark, half light
DrawBackground();
// draw red, green and blue circles
DrawCircles();
// print blend modes to screen
PrintBlendMode();
// handle input for changing blend modes
HandleInput();
}