surface_get_format

This function returns the format of the given surface. All formats are listed here.

 

Syntax:

surface_get_format(surface_id);

ArgumentTypeDescription
surface_idSurfaceThe surface to get the format of

 

Returns:

Surface Format Constant

 

Example:

var _format = surface_get_format(my_surf);
if (_format == surface_rgba8unorm)
{
    var _buffer = buffer_create(1, buffer_grow, 1);
    buffer_get_surface(_buffer, my_surf, 0);
    buffer_seek(_buffer, buffer_seek_start, 0);
    show_debug_message(buffer_read(_buffer, buffer_u8));
    show_debug_message(buffer_read(_buffer, buffer_u8));
    show_debug_message(buffer_read(_buffer, buffer_u8));
    show_debug_message(buffer_read(_buffer, buffer_u8));
}

This gets the format of a surface, and checks if it's surface_rgba8unorm, meaning each pixel has 4 channels (RGBA) with each channel having 8 bits (1 byte).

If the format matches, it creates a buffer and writes the surface to that buffer. It then seeks to the start of the buffer and reads the first four bytes, i.e. the RGBA values for the first pixel. It prints each channel's value to the output log.