General drawing tasks in OSLib.
◆ oslResetScreenClipping
Resets the screen clipping region to the entire screen.
This macro resets the clipping region, ensuring that drawing operations affect the whole screen.
◆ OSL_FX_DEFAULT
| #define OSL_FX_DEFAULT OSL_FX_RGBA |
Default effect that combines RGBA channels.
This macro is used as the default alpha effect, combining red, green, blue, and alpha channels.
◆ OSL_FX_OPAQUE
Opaque effect with no special processing.
This macro sets the alpha effect to none, resulting in full opacity with no special processing.
◆ OSL_FX_TINT
Tint effect that combines alpha blending and color.
This macro applies an alpha blending effect combined with a color effect, useful for tinting.
◆ anonymous enum
| Enumerator |
|---|
| OSL_FX_NONE | No special effect.
|
| OSL_FX_FLAT | Flat shading effect.
|
| OSL_FX_ALPHA | Alpha blending effect.
|
| OSL_FX_ADD | Additive blending effect.
|
| OSL_FX_SUB | Subtractive blending effect.
|
◆ oslClearScreen()
| void oslClearScreen |
( |
int |
backColor | ) |
|
|
extern |
Clears the entire screen with the specified color.
This function fills the screen with the given color.
- Parameters
-
| backColor | The color to fill the screen with. |
◆ oslSetScreenClipping()
| void oslSetScreenClipping |
( |
int |
x0, |
|
|
int |
y0, |
|
|
int |
x1, |
|
|
int |
y1 |
|
) |
| |
|
extern |
Sets the clipping region.
Defines a rectangular area on the screen within which rendering is allowed. Any drawing outside this rectangle will not appear on the screen. Initially, the clipping region is set to cover the entire screen.
- Parameters
-
| x0 | The x-coordinate of the top-left corner of the clipping region. |
| y0 | The y-coordinate of the top-left corner of the clipping region. |
| x1 | The x-coordinate of the bottom-right corner of the clipping region. |
| y1 | The y-coordinate of the bottom-right corner of the clipping region. |
- Note
- The clipping region is automatically adjusted to cover the entire draw buffer image when oslSetDrawBuffer is called.
◆ oslSetDepthTest()
| void oslSetDepthTest |
( |
int |
enabled | ) |
|
|
extern |
Sets the depth test.
Enables or disables depth testing, which determines whether a pixel should be drawn based on its depth value compared to what is currently in the depth buffer.
- Parameters
-
| enabled | Set to 1 to enable depth testing, or 0 to disable it. |
◆ oslSetAlpha2()
| void oslSetAlpha2 |
( |
u32 |
effect, |
|
|
u32 |
coeff1, |
|
|
u32 |
coeff2 |
|
) |
| |
|
extern |
Configures the current alpha effect parameters for subsequent drawing operations.
This function sets the blending mode and other related parameters that affect how images and shapes are rendered with alpha blending. The effect of this function persists for all subsequent draw calls until it is changed again.
- Parameters
-
| effect | Specifies the blending mode to use:
OSL_FX_NONE: Disables blending entirely.
OSL_FX_DEFAULT: Resets to the default blending mode (equivalent to OSL_FX_RGBA).
OSL_FX_RGBA: Standard RGBA blending, where the alpha channel is used to blend the source and destination colors.
OSL_FX_ALPHA: Alpha blending using coeff1 as the alpha value. The resulting color is dstColor = srcColor * coeff1 + dstColor * (1 - coeff1).
OSL_FX_ADD: Additive blending, where the resulting color is dstColor = dstColor * coeff2 + srcColor * coeff1.
OSL_FX_SUB: Subtractive blending, where the resulting color is dstColor = dstColor * coeff2 - srcColor * coeff1.
OSL_FX_COLOR: Optional flag that treats coeff1 and coeff2 as 32-bit colors instead of alpha values. This allows for color tinting effects.
|
| coeff1 | A coefficient used in the blending operation, either as an alpha value (0 to 255) or a 32-bit color (0x00000000 to 0xFFFFFFFF). |
| coeff2 | An extended coefficient used in the additive or subtractive blending modes, either as an alpha value or a 32-bit color. |
Examples:
#define RGBA(r, v, b, a)
Creates a 32-bit color with alpha (transparency).
Definition drawing.h:456
#define OSL_FX_DEFAULT
Default effect that combines RGBA channels.
Definition drawing.h:393
void oslSetAlpha2(u32 effect, u32 coeff1, u32 coeff2)
Configures the current alpha effect parameters for subsequent drawing operations.
static void oslSetAlpha(u32 effect, u32 coeff1)
A simplified version of oslSetAlpha2, where coeff2 is set to the maximum value.
Definition drawing.h:225
@ OSL_FX_ADD
Additive blending effect.
Definition drawing.h:384
@ OSL_FX_ALPHA
Alpha blending effect.
Definition drawing.h:383
Understanding how color multiplication works can help you achieve various effects. For example, multiplying colors generally darkens them, with black always resulting in black, while multiplying by white leaves the color unchanged.
◆ oslSetAlpha()
| static void oslSetAlpha |
( |
u32 |
effect, |
|
|
u32 |
coeff1 |
|
) |
| |
|
inlinestatic |
A simplified version of oslSetAlpha2, where coeff2 is set to the maximum value.
- Parameters
-
| effect | Blending mode to use (as described in oslSetAlpha2). |
| coeff1 | A coefficient used in the blending operation, either as an alpha value or a 32-bit color. |
◆ oslGetAlphaEx()
Stores the current alpha parameters into an OSL_ALPHA_PARAMS structure.
This function copies the current global alpha effect parameters, including the effect type and coefficients, into the provided OSL_ALPHA_PARAMS structure.
- Parameters
-
| alpha | Pointer to an OSL_ALPHA_PARAMS structure where the current alpha parameters will be stored. |
◆ oslSetAlphaEx()
Sets the current alpha parameters using an OSL_ALPHA_PARAMS structure.
This function updates the global alpha effect parameters based on the values stored in the provided OSL_ALPHA_PARAMS structure. It uses the oslSetAlpha2 function to apply these parameters.
- Parameters
-
| alpha | Pointer to an OSL_ALPHA_PARAMS structure containing the alpha parameters to be set. |
◆ oslSetBilinearFilter()
| void oslSetBilinearFilter |
( |
int |
enabled | ) |
|
|
extern |
Enables or disables bilinear filtering.
Bilinear filtering smoothes images, reducing edge aliasing when they are stretched or rotated. However, this can cause blurring in text or images that are not stretched, so it is generally not recommended to enable bilinear filtering permanently.
- Parameters
-
| enabled | Set to 1 to enable bilinear filtering, or 0 to disable it. |
◆ oslSetDithering()
| void oslSetDithering |
( |
int |
enabled | ) |
|
|
extern |
Enables or disables dithering.
Dithering is useful in 16-bit color modes or when drawing to a 16-bit image. If enabled, it blends colors that cannot be rendered exactly by using the nearest available colors and applying a pattern of small dots. This gives the illusion of intermediate colors, such as creating the appearance of orange by dithering red and yellow.
- Parameters
-
| enabled | Set to 1 to enable dithering, or 0 to disable it. |
◆ oslSetTransparentColor()
| void oslSetTransparentColor |
( |
OSL_COLOR |
color | ) |
|
|
extern |
Enables color keying, making a specific color transparent.
This function enables color keying, which makes any pixel matching the specified color (color) fully transparent. This is particularly useful when loading images with a specific background color that should be treated as transparent, such as bright pink backgrounds in sprite sheets.
The transparency effect persists even after disabling color keying, as it modifies the alpha channel of the image.
Example 1: Loading an image with a color key
#define RGB(r, v, b)
Creates a 32-bit opaque color.
Definition drawing.h:443
void oslDisableTransparentColor()
Disables color keying, preventing any color-based transparency.
void oslSetTransparentColor(OSL_COLOR color)
Enables color keying, making a specific color transparent.
OSL_IMAGE * oslLoadImageFilePNG(char *filename, int location, int pixelFormat)
Loads an image from a PNG file.
@ OSL_IN_RAM
In RAM.
Definition drawing.h:981
@ OSL_PF_5551
15 bits, 5 bits per component, 1 alpha bit
Definition drawing.h:1015
Structure representing an image loaded in memory.
Definition drawing.h:932
Example 2: Drawing with color keying enabled
void oslDrawFillRect(int x0, int y0, int x1, int y1, OSL_COLOR color)
Draws a filled rectangle from (x0, y0) to (x1, y1).
- Parameters
-
| color | The color to be treated as transparent. |
◆ oslDisableTransparentColor()
| void oslDisableTransparentColor |
( |
| ) |
|
|
extern |
Disables color keying, preventing any color-based transparency.
When color keying is disabled, all pixels will be drawn to the screen, including those that match the previously set transparent color. This function should be called after loading images with transparency or after drawing operations where color keying was used.
◆ osl_currentAlphaEffect
| int osl_currentAlphaEffect |
|
extern |
Current global alpha effect.
This variable holds the identifier of the alpha effect currently in use.
◆ osl_currentAlphaCoeff
Current first coefficient for the global alpha effect.
This variable holds the first coefficient used by the current global alpha effect.
◆ osl_currentAlphaCoeff2
Current second coefficient for the global alpha effect.
This variable holds the second coefficient used by the current global alpha effect.
◆ osl_bilinearFilterEnabled
| int osl_bilinearFilterEnabled |
|
extern |
Indicates whether bilinear filtering is currently enabled.
This variable holds the state of bilinear filtering, which affects the smoothing of textures when they are scaled or rotated. A non-zero value means bilinear filtering is enabled, while a value of zero means it is disabled.
◆ osl_ditheringEnabled
Indicates whether dithering is currently enabled.
This variable holds the state of dithering, which can be used to reduce the appearance of color banding by blending colors. A non-zero value means dithering is enabled, while a value of zero means it is disabled.
◆ osl_colorKeyEnabled
Indicates whether color keying is currently enabled.
This variable holds the state of color keying, a technique used to make certain colors transparent. A non-zero value means color keying is enabled, while a value of zero means it is disabled.