SNES Color Math (Blending/Transparency) More...
#include <snes/types.h>Go to the source code of this file.
Macros | |
| #define | COLDATA_ALL (COLDATA_RED | COLDATA_GREEN | COLDATA_BLUE) |
| Apply fixed color to all channels. | |
| #define | COLDATA_BLUE 0x80 |
| Apply fixed color to blue channel. | |
| #define | COLDATA_GREEN 0x40 |
| Apply fixed color to green channel. | |
| #define | COLDATA_RED 0x20 |
| Apply fixed color to red channel. | |
| #define | COLORMATH_ADD 0 |
| Add colors (brightens) | |
| #define | COLORMATH_ALL 0x3F |
| Apply color math to all layers. | |
| #define | COLORMATH_ALWAYS 0 |
| Always enable color math. | |
| #define | COLORMATH_BACKDROP BIT(5) |
| Apply color math to backdrop (color 0) | |
| #define | COLORMATH_BG1 BIT(0) |
| Apply color math to BG1. | |
| #define | COLORMATH_BG2 BIT(1) |
| Apply color math to BG2. | |
| #define | COLORMATH_BG3 BIT(2) |
| Apply color math to BG3. | |
| #define | COLORMATH_BG4 BIT(3) |
| Apply color math to BG4. | |
| #define | COLORMATH_INSIDE 1 |
| Enable inside window only. | |
| #define | COLORMATH_NEVER 3 |
| Never enable color math. | |
| #define | COLORMATH_OBJ BIT(4) |
| Apply color math to sprites (OBJ) | |
| #define | COLORMATH_OUTSIDE 2 |
| Enable outside window only. | |
| #define | COLORMATH_SRC_FIXED 1 |
| Use fixed color as color source. | |
| #define | COLORMATH_SRC_SUBSCREEN 0 |
| Use sub screen as color source. | |
| #define | COLORMATH_SUB 1 |
| Subtract colors (darkens) | |
Functions | |
| void | colorMathDisable (void) |
| Disable all color math. | |
| void | colorMathEnable (u8 layers) |
| Enable color math for specified layers. | |
| void | colorMathInit (void) |
| Initialize color math to defaults. | |
| void | colorMathSetBrightness (u8 brightness) |
| Set brightness for fade effects. | |
| void | colorMathSetChannel (u8 channel, u8 intensity) |
| Set a single fixed color channel. | |
| void | colorMathSetCondition (u8 condition) |
| Set when color math is enabled (window control) | |
| void | colorMathSetFixedColor (u8 r, u8 g, u8 b) |
| Set fixed color for blending. | |
| void | colorMathSetHalf (u8 enable) |
| Enable or disable half mode. | |
| void | colorMathSetOp (u8 op) |
| Set color math operation (add or subtract) | |
| void | colorMathSetSource (u8 source) |
| Set color math source. | |
| void | colorMathShadow (u8 layers, u8 intensity) |
| Set up shadow/darkening effect. | |
| void | colorMathTint (u8 layers, u8 r, u8 g, u8 b) |
| Set up color tint effect. | |
| void | colorMathTransparency50 (u8 layers) |
| Set up 50% transparency for layers. | |
SNES Color Math (Blending/Transparency)
Color math enables blending between the main screen and sub screen or a fixed color. This creates effects like transparency, shadows, fading, and underwater tints.
The SNES can add or subtract colors:
Half mode divides the result by 2, useful for 50% transparency.
For transparency, put the background on main screen and the transparent layer on sub screen.
| #define COLDATA_ALL (COLDATA_RED | COLDATA_GREEN | COLDATA_BLUE) |
Apply fixed color to all channels.
| #define COLDATA_BLUE 0x80 |
Apply fixed color to blue channel.
| #define COLDATA_GREEN 0x40 |
Apply fixed color to green channel.
| #define COLDATA_RED 0x20 |
Apply fixed color to red channel.
| #define COLORMATH_ADD 0 |
Add colors (brightens)
| #define COLORMATH_ALL 0x3F |
Apply color math to all layers.
| #define COLORMATH_ALWAYS 0 |
Always enable color math.
| #define COLORMATH_BACKDROP BIT(5) |
Apply color math to backdrop (color 0)
| #define COLORMATH_BG1 BIT(0) |
Apply color math to BG1.
| #define COLORMATH_BG2 BIT(1) |
Apply color math to BG2.
| #define COLORMATH_BG3 BIT(2) |
Apply color math to BG3.
| #define COLORMATH_BG4 BIT(3) |
Apply color math to BG4.
| #define COLORMATH_INSIDE 1 |
Enable inside window only.
| #define COLORMATH_NEVER 3 |
Never enable color math.
| #define COLORMATH_OBJ BIT(4) |
Apply color math to sprites (OBJ)
| #define COLORMATH_OUTSIDE 2 |
Enable outside window only.
| #define COLORMATH_SRC_FIXED 1 |
Use fixed color as color source.
| #define COLORMATH_SRC_SUBSCREEN 0 |
Use sub screen as color source.
| #define COLORMATH_SUB 1 |
Subtract colors (darkens)
| void colorMathDisable | ( | void | ) |
Disable all color math.
| void colorMathEnable | ( | u8 | layers | ) |
Enable color math for specified layers.
Enables color math blending for the given layers.
| layers | Layer mask (COLORMATH_BG1, COLORMATH_BG2, etc.) |
| void colorMathInit | ( | void | ) |
Initialize color math to defaults.
Disables all color math effects.
| void colorMathSetBrightness | ( | u8 | brightness | ) |
Set brightness for fade effects.
Sets the fixed color for use in fading. Use with colorMathSetOp() to fade to white (add) or black (subtract).
| brightness | Fade level (0 = no effect, 31 = full white/black) |
Set a single fixed color channel.
| channel | Channel mask (COLDATA_RED, COLDATA_GREEN, COLDATA_BLUE) |
| intensity | Intensity (0-31) |
| void colorMathSetCondition | ( | u8 | condition | ) |
Set when color math is enabled (window control)
| condition | COLORMATH_ALWAYS, COLORMATH_INSIDE, COLORMATH_OUTSIDE, or COLORMATH_NEVER |
Set fixed color for blending.
Sets the fixed color used when source is COLORMATH_SRC_FIXED.
| r | Red intensity (0-31) |
| g | Green intensity (0-31) |
| b | Blue intensity (0-31) |
| void colorMathSetHalf | ( | u8 | enable | ) |
Enable or disable half mode.
When enabled, the color math result is divided by 2. This creates 50% transparency/blending.
| enable | 1 = divide by 2, 0 = full result |
| void colorMathSetOp | ( | u8 | op | ) |
Set color math operation (add or subtract)
| op | Operation (COLORMATH_ADD or COLORMATH_SUB) |
| void colorMathSetSource | ( | u8 | source | ) |
Set color math source.
Chooses whether to blend with the sub screen or a fixed color.
| source | COLORMATH_SRC_SUBSCREEN or COLORMATH_SRC_FIXED |
Set up shadow/darkening effect.
Subtracts fixed color from layers to darken them.
| layers | Layers to darken |
| intensity | Darkness level (0-31, higher = darker) |
Set up color tint effect.
Adds a fixed color tint to layers.
| layers | Layers to tint |
| r | Red tint (0-31) |
| g | Green tint (0-31) |
| b | Blue tint (0-31) |
| void colorMathTransparency50 | ( | u8 | layers | ) |
Set up 50% transparency for layers.
Quick setup for semi-transparent layers. The transparent layers should be on both main and sub screen.
| layers | Layers to make 50% transparent |