lib2d is a fast and simple 2D sprite rendering library for games licensed under the MIT.




int lib2d_init(enum lib2d_render_backend render_backend, void* render_context)

Returns 0 on success and a negative number on failure. Call lib2d_get_error() for more information if this call fails.

Depending on the rendering backend used you may need to pass in relevant context information. This is platform specific. For OpenGL make sure the context is currently bound when you call this function and pass NULL to render_context.

void lib2d_shutdown()

Free resources created in lib2d_init(). All other lib2d resources previously created, such as images, should be deleted before calling this function.

void lib2d_clear(float r, float g, float b, float a)

Clears screen with the given color.

void lib2d_viewport(int width, int height)

Call this with the size of your render target (e.g. your game's window.)

void lib2d_render()

Executes all draw commands issued with lib2d_draw() since the last call to this function.

int lib2d_image_load_buffer(unsigned char* data, lib2d_image* image, int w, int h, int bpp)
const char* lib2d_get_error()

Retrieves the error message for the last failure.


if (lib2d_init(LIB2D_RENDER_BACKEND_GL, 0) != 0) {
    fprintf(stderr, "%s\n", lib2d_get_error());