OldSchool Library
General

Data Structures

struct  OSL_ALPHA_PARAMS
 Structure containing data for a special alpha effect. More...
 

Macros

#define oslResetScreenClipping()
 Resets the screen clipping region to the entire screen.
 
#define OSL_FX_DEFAULT   OSL_FX_RGBA
 Default effect that combines RGBA channels.
 
#define OSL_FX_OPAQUE   OSL_FX_NONE
 Opaque effect with no special processing.
 
#define OSL_FX_TINT   (OSL_FX_ALPHA | OSL_FX_COLOR)
 Tint effect that combines alpha blending and color.
 

Enumerations

enum  {
  OSL_FX_NONE = 0 , OSL_FX_FLAT , OSL_FX_ALPHA , OSL_FX_ADD ,
  OSL_FX_SUB
}
 

Functions

void oslClearScreen (int backColor)
 
void oslSetScreenClipping (int x0, int y0, int x1, int y1)
 
void oslSetDepthTest (int enabled)
 
void oslSetAlpha2 (u32 effect, u32 coeff1, u32 coeff2)
 Configures the current alpha effect parameters for subsequent drawing operations.
 
void oslSetBilinearFilter (int enabled)
 
void oslSetDithering (int enabled)
 
void oslSetTransparentColor (OSL_COLOR color)
 Enables color keying, making a specific color transparent.
 
void oslDisableTransparentColor ()
 Disables color keying, preventing any color-based transparency.
 

Variables

int osl_currentAlphaEffect
 Current global alpha effect.
 
OSL_COLOR osl_currentAlphaCoeff
 Current first coefficient for the global alpha effect.
 
OSL_COLOR osl_currentAlphaCoeff2
 Current second coefficient for the global alpha effect.
 
int osl_bilinearFilterEnabled
 Indicates whether bilinear filtering is currently enabled.
 
int osl_ditheringEnabled
 Indicates whether dithering is currently enabled.
 
int osl_colorKeyEnabled
 Indicates whether color keying is currently enabled.
 

Detailed Description

General drawing tasks in OSLib.

Macro Definition Documentation

◆ oslResetScreenClipping

#define oslResetScreenClipping ( )
Value:
oslSetScreenClipping(0, 0, osl_curBuf->sizeX, osl_curBuf->sizeY)
void oslSetScreenClipping(int x0, int y0, int x1, int y1)
u16 sizeY
Displayable size.
Definition drawing.h:929

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

#define OSL_FX_OPAQUE   OSL_FX_NONE

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

#define OSL_FX_TINT   (OSL_FX_ALPHA | OSL_FX_COLOR)

Tint effect that combines alpha blending and color.

This macro applies an alpha blending effect combined with a color effect, useful for tinting.

Enumeration Type Documentation

◆ anonymous enum

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.

Function Documentation

◆ oslClearScreen()

void oslClearScreen ( int backColor)
extern

Clears the entire screen with the specified color.

This function fills the screen with the given color.

Parameters
backColorThe 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
x0The x-coordinate of the top-left corner of the clipping region.
y0The y-coordinate of the top-left corner of the clipping region.
x1The x-coordinate of the bottom-right corner of the clipping region.
y1The 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
enabledSet 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
effectSpecifies 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.
coeff1A coefficient used in the blending operation, either as an alpha value (0 to 255) or a 32-bit color (0x00000000 to 0xFFFFFFFF).
coeff2An extended coefficient used in the additive or subtractive blending modes, either as an alpha value or a 32-bit color.

Examples:

// Default alpha blending
oslSetAlpha(OSL_FX_DEFAULT, 0);
// Tint an image with red
oslSetAlpha(OSL_FX_COLOR, RGBA(255, 0, 0, 255));
// Render the image semi-transparent
oslSetAlpha(OSL_FX_ALPHA, 128);
// Apply both tinting and semi-transparency
oslSetAlpha(OSL_FX_ALPHA | OSL_FX_COLOR, RGBA(255, 0, 0, 128));
// Additive blending, similar to effects seen on older consoles
#define RGBA(r, v, b, a)
Creates a 32-bit color with alpha (transparency).
Definition drawing.h:451
#define OSL_FX_DEFAULT
Default effect that combines RGBA channels.
Definition drawing.h:388
void oslSetAlpha2(u32 effect, u32 coeff1, u32 coeff2)
Configures the current alpha effect parameters for subsequent drawing operations.
@ OSL_FX_ADD
Additive blending effect.
Definition drawing.h:379
@ OSL_FX_ALPHA
Alpha blending effect.
Definition drawing.h:378

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.

◆ 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
enabledSet 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
enabledSet 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

// Set bright pink as the transparent color
// Load an image with transparency, ensuring to use a pixel format that supports alpha (e.g., OSL_PF_5551)
// Disable color keying to avoid affecting further drawing operations
#define RGB(r, v, b)
Creates a 32-bit opaque color.
Definition drawing.h:438
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:976
@ OSL_PF_5551
15 bits, 5 bits per component, 1 alpha bit
Definition drawing.h:1010
Structure representing an image loaded in memory.
Definition drawing.h:927

Example 2: Drawing with color keying enabled

// Drawing a pink rectangle won't display anything, as pink is currently masked out
oslDrawFillRect(0, 0, 100, 100, RGB(255, 0, 255));
void oslDrawFillRect(int x0, int y0, int x1, int y1, OSL_COLOR color)
Draws a filled rectangle from (x0, y0) to (x1, y1).
Parameters
colorThe 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.

Variable Documentation

◆ osl_currentAlphaEffect

int osl_currentAlphaEffect
extern

Current global alpha effect.

This variable holds the identifier of the alpha effect currently in use.

◆ osl_currentAlphaCoeff

OSL_COLOR osl_currentAlphaCoeff
extern

Current first coefficient for the global alpha effect.

This variable holds the first coefficient used by the current global alpha effect.

◆ osl_currentAlphaCoeff2

OSL_COLOR osl_currentAlphaCoeff2
extern

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

int osl_ditheringEnabled
extern

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

int osl_colorKeyEnabled
extern

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.