OldSchool Library
Drawbuffers

Macros

#define oslGetDrawBuffer()
 
#define OSL_DEFAULT_BUFFER   (&osl_defaultBufferImage)
 
#define OSL_SECONDARY_BUFFER   (&osl_secondaryBufferImage)
 
#define OSL_SCREEN_WIDTH   (osl_curBuf->sizeX)
 
#define OSL_SCREEN_HEIGHT   (osl_curBuf->sizeY)
 

Enumerations

enum  OSL_FX_ALPHAWRITE { OSL_FXAW_NONE , OSL_FXAW_SET }
 
enum  OSL_FX_ALPHATEST {
  OSL_FXAT_NEVER = GU_NEVER , OSL_FXAT_ALWAYS = GU_ALWAYS , OSL_FXAT_EQUAL = GU_EQUAL , OSL_FXAT_NOTEQUAL = GU_NOTEQUAL ,
  OSL_FXAT_LESS = GU_LESS , OSL_FXAT_LEQUAL = GU_LEQUAL , OSL_FXAT_GREATER = GU_GREATER , OSL_FXAT_GEQUAL = GU_GEQUAL
}
 

Functions

void oslSetDrawBuffer (OSL_IMAGE *img)
 
void oslSetAlphaWrite (int action, int value1, int value2)
 Controls writing to the alpha channel of the draw buffer.
 
void oslSetAlphaTest (int condition, int value)
 
void oslDisableAlphaTest ()
 

Variables

int osl_alphaTestEnabled
 

Detailed Description

Drawbuffers is an advanced and powerful capability of OSLib images. It allows you to draw directly on an image exactly as if you were drawing on the screen! See oslSetDrawBuffer for a basic code sample.

Macro Definition Documentation

◆ oslGetDrawBuffer

#define oslGetDrawBuffer ( )
Value:
osl_curBuf

Returns the current drawbuffer as an OSL_IMAGE. You can save it to restore it later.

Returns
A pointer to the current drawbuffer image.

◆ OSL_DEFAULT_BUFFER

#define OSL_DEFAULT_BUFFER   (&osl_defaultBufferImage)

An image representing the primary buffer image, which is the buffer to which you are currently writing.

Note
This buffer is managed by oslSwapBuffers. In single buffering mode, OSL_DEFAULT_BUFFER is identical to OSL_SECONDARY_BUFFER.

◆ OSL_SECONDARY_BUFFER

#define OSL_SECONDARY_BUFFER   (&osl_secondaryBufferImage)

An image representing the secondary buffer image, which is the buffer currently displayed to the user.

Note
In single buffering mode, OSL_DEFAULT_BUFFER is identical to OSL_SECONDARY_BUFFER. This buffer is updated and managed by oslSwapBuffers.

◆ OSL_SCREEN_WIDTH

#define OSL_SCREEN_WIDTH   (osl_curBuf->sizeX)

Returns the width of the current drawbuffer.

Returns
The width of the current drawbuffer in pixels. For the default drawbuffer (i.e., the screen), it will be 480 pixels, which is the resolution of the PSP LCD.

◆ OSL_SCREEN_HEIGHT

#define OSL_SCREEN_HEIGHT   (osl_curBuf->sizeY)

Returns the height of the current drawbuffer.

Returns
The height of the current drawbuffer in pixels. For the default drawbuffer (i.e., the screen), it will be 272 pixels, which is the resolution of the PSP LCD.

Enumeration Type Documentation

◆ OSL_FX_ALPHAWRITE

Available effects for oslSetAlphaWrite.

Enumerator
OSL_FXAW_NONE 

Does not write alpha.

OSL_FXAW_SET 

Sets alpha to value1 if the alpha channel of the pixel is not equal to value2.

◆ OSL_FX_ALPHATEST

Alpha test comparison operators. Used with oslSetAlphaTest to define the conditions for alpha testing.

Enumerator
OSL_FXAT_NEVER 

Never passes the alpha test.

OSL_FXAT_ALWAYS 

Always passes the alpha test.

OSL_FXAT_EQUAL 

Passes the alpha test if the alpha value is equal to the reference value.

OSL_FXAT_NOTEQUAL 

Passes the alpha test if the alpha value is not equal to the reference value.

OSL_FXAT_LESS 

Passes the alpha test if the alpha value is less than the reference value.

OSL_FXAT_LEQUAL 

Passes the alpha test if the alpha value is less than or equal to the reference value.

OSL_FXAT_GREATER 

Passes the alpha test if the alpha value is greater than the reference value.

OSL_FXAT_GEQUAL 

Passes the alpha test if the alpha value is greater than or equal to the reference value.

Function Documentation

◆ oslSetDrawBuffer()

void oslSetDrawBuffer ( OSL_IMAGE * img)
extern

Define an image as the current drawbuffer. Use this function to specify the image to which drawing operations will be directed. Remember to restore the original drawbuffer after you have finished drawing.

\code
OSL_IMAGE *drawBuf = oslCreateImage(320, 182, OSL_IN_VRAM, OSL_PF_5650);
// Clear the image to black
oslClearImage(drawBuf, RGB16(0, 0, 0));
// Set that image as the drawbuffer
oslSetDrawBuffer(drawBuf);
// Draw a red filled rectangle on the image
oslDrawFillRect(0, 0, 100, 100, RGB(255, 0, 0));
// Restore the default drawbuffer
oslSetDrawBuffer(OSL_DEFAULT_BUFFER);
// Draw that image somewhere on the screen
oslDrawImageXY(drawBuf, 80, 45);
\endcode

\b Important:
- The image pixel format must be non-paletted. Supported formats are 4444, 5551, 5650, and 8888. Note that 8888 mode (32-bit) is slower and results in a larger image size.
- The image must be in video memory (OSL_IN_VRAM). The GPU can only write to video memory and can only read from regular RAM.
- A common issue is that the image may not be displayed if its alpha is null. To avoid this, either clear the image after creation or temporarily disable alpha blending by calling `oslSetAlpha(OSL_FX_NONE, 0)`.

@param img
    The image to set as the current drawbuffer.

@return
    None.

◆ oslSetAlphaWrite()

void oslSetAlphaWrite ( int action,
int value1,
int value2 )
extern

Controls writing to the alpha channel of the draw buffer.

This function is useful when rendering to an image rather than the standard draw buffer. By default, alpha values are not modified in the draw buffer. This function allows you to specify how alpha values should be written based on the given action. It also provides the ability to enable or disable stencil testing, which can control the regions of the buffer where alpha values are written.

Parameters
actionSpecifies the action to take:
  • OSL_FXAW_SET: Sets the alpha channel to value1. Every pixel written to the draw buffer will set its alpha value to value1. Even fully transparent pixels will have their alpha values set unless additional alpha testing is enabled.
  • OSL_FXAW_NONE: Disables stencil testing, leaving the alpha channel unchanged.
value1If action is OSL_FXAW_SET, this specifies the alpha value to be written, ranging from 0 (transparent) to 255 (opaque).
value2Currently not used; should be set to 0.

Example:

// Clear the image to fully transparent (alpha = 0)
oslClearImage(buffer, RGBA(0, 0, 0, 0));
// Set the cleared image as the draw buffer
// Enable alpha writing with full opacity (alpha = 255)
// Only draw pixels with an alpha value greater than 0, preventing fully transparent pixels from being written
// Continue rendering...
#define RGBA(r, v, b, a)
Creates a 32-bit color with alpha (transparency).
Definition drawing.h:451
void oslSetAlphaWrite(int action, int value1, int value2)
Controls writing to the alpha channel of the draw buffer.
void oslSetDrawBuffer(OSL_IMAGE *img)
void oslSetAlphaTest(int condition, int value)
@ OSL_FXAW_SET
Definition drawing.h:3061
@ OSL_FXAT_GREATER
Definition drawing.h:3086
void oslClearImage(OSL_IMAGE *img, int color)

◆ oslSetAlphaTest()

void oslSetAlphaTest ( int condition,
int value )
extern

Sets alpha testing parameters.

Configures the alpha test, which determines whether a pixel should be drawn based on its alpha value. If the test passes, the pixel is written to the screen; otherwise, it is ignored.

Parameters
conditionThe condition for the test to pass. Can be one of the following:
  • OSL_FXAT_NEVER: Never passes.
  • OSL_FXAT_ALWAYS: Always passes.
  • OSL_FXAT_EQUAL: Alpha is equal to the value.
  • OSL_FXAT_NOTEQUAL: Alpha is not equal to the value.
  • OSL_FXAT_LESS: Alpha is less than the value.
  • OSL_FXAT_LEQUAL: Alpha is less than or equal to the value.
  • OSL_FXAT_GREATER: Alpha is greater than the value.
  • OSL_FXAT_GEQUAL: Alpha is greater than or equal to the value.
valueThe reference value for comparison.
Note
Pixels from an OSL_PF_5650 image do not initially contain alpha. The alpha value is automatically set to opaque (alpha = 255).

◆ oslDisableAlphaTest()

void oslDisableAlphaTest ( )
extern

Disables alpha testing.

Alpha testing is a method of controlling the visibility of pixels based on their alpha values.

Variable Documentation

◆ osl_alphaTestEnabled

int osl_alphaTestEnabled
extern

Holds whether alpha testing is currently enabled.