Pico Libraries
Classes | Typedefs | Enumerations | Functions
pico_gl.h File Reference

A powerful OpenGL-based graphics library written in C99. More...

#include <stdbool.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
Include dependency graph for pico_gl.h:

Go to the source code of this file.

Classes

struct  pgl_blend_mode_t
 Blend mode. More...
 
struct  pgl_vertex_t
 A vertex describes a point and the data associated with it (color and texture coordinates) More...
 

Typedefs

typedef uint32_t pgl_size_t
 OpenGL compatible size type. More...
 
typedef float pgl_v2f_t[2]
 2D floating point vector More...
 
typedef float pgl_v3f_t[3]
 3D floating point vector More...
 
typedef float pgl_v4f_t[4]
 4D floating point vector More...
 
typedef int32_t pgl_v2i_t[2]
 2D integer vector More...
 
typedef int32_t pgl_v3i_t[3]
 3D integer vector More...
 
typedef int32_t pgl_v4i_t[4]
 4D integer vector More...
 
typedef float pgl_m2_t[4]
 2x2 floating point matrix More...
 
typedef float pgl_m3_t[9]
 3x3 floating point matrix More...
 
typedef float pgl_m4_t[16]
 4x4 floating point matrix More...
 
typedef struct pgl_ctx_t pgl_ctx_t
 Contains core data/state for an instance of the renderer. More...
 
typedef struct pgl_shader_t pgl_shader_t
 Contains shader data/state. More...
 
typedef struct pgl_texture_t pgl_texture_t
 Contains texture data/state. More...
 
typedef struct pgl_buffer_t pgl_buffer_t
 Contains vertex buffer data/state. More...
 
typedef void *(* pgl_loader_fn) (const char *name)
 Defines an OpenGL (GLAD) function loader. More...
 

Enumerations

enum  pgl_error_t {
  PGL_NO_ERROR , PGL_INVALID_ENUM , PGL_INVALID_VALUE , PGL_INVALID_OPERATION ,
  PGL_OUT_OF_MEMORY , PGL_INVALID_FRAMEBUFFER_OPERATION , PGL_FRAMEBUFFER_INCOMPLETE , PGL_SHADER_COMPILATION_ERROR ,
  PGL_SHADER_LINKING_ERROR , PGL_INVALID_TEXTURE_SIZE , PGL_INVALID_TEXTURE_FORMAT , PGL_INVALID_ATTRIBUTE_COUNT ,
  PGL_INVALID_UNIFORM_COUNT , PGL_INVALID_UNIFORM_NAME , PGL_UNKNOWN_ERROR , PGL_ERROR_COUNT
}
 Runtime error codes. More...
 
enum  pgl_version_t { PGL_GL3 , PGL_GLES3 , PGL_VERSION_UNSUPPORTED }
 OpenGL versions used by the library. More...
 
enum  pgl_format_t {
  PGL_RED , PGL_RGB , PGL_RGBA , PGL_BGR ,
  PGL_BGRA , PGL_FORMAT_COUNT
}
 Pixel formats. More...
 
enum  pgl_blend_factor_t {
  PGL_ZERO , PGL_ONE , PGL_SRC_COLOR , PGL_ONE_MINUS_SRC_COLOR ,
  PGL_DST_COLOR , PGL_ONE_MINUS_DST_COLOR , PGL_SRC_ALPHA , PGL_ONE_MINUS_SRC_ALPHA ,
  PGL_DST_ALPHA , PGL_ONE_MINUS_DST_ALPHA , PGL_FACTOR_COUNT
}
 Blend factors. More...
 
enum  pgl_blend_eq_t {
  PGL_FUNC_ADD , PGL_FUNC_SUBTRACT , PGL_FUNC_REVERSE_SUBTRACT , PGL_MIN ,
  PGL_MAX , PGL_EQ_COUNT
}
 Blend equations. More...
 
enum  pgl_primitive_t {
  PGL_POINTS , PGL_LINES , PGL_LINE_STRIP , PGL_TRIANGLES ,
  PGL_TRIANGLE_STRIP
}
 Drawing primitives. More...
 

Functions

int pgl_global_init (pgl_loader_fn loader_fp, bool gles)
 Loads all supported OpenGL functions via GLAD. More...
 
pgl_error_t pgl_get_error (pgl_ctx_t *ctx)
 Returns the current error code. More...
 
const char * pgl_get_error_str (pgl_error_t code)
 Returns the string associated with the specified error code. More...
 
pgl_version_t pgl_get_version ()
 Returns the current OpenGL version in use by the library. More...
 
void pgl_print_info ()
 Prints system info. More...
 
pgl_ctx_tpgl_create_context (uint32_t w, uint32_t h, bool depth, uint32_t samples, bool srgb, void *mem_ctx)
 Creates an instance of the renderer. More...
 
void pgl_destroy_context (pgl_ctx_t *ctx)
 Destroys a renderer context, releasing it's resources. More...
 
void pgl_resize (pgl_ctx_t *ctx, uint32_t w, uint32_t h, bool reset_vp)
 Resizes the drawable dimensions. More...
 
pgl_shader_tpgl_create_shader (pgl_ctx_t *ctx, const char *vert_src, const char *frag_src)
 Creates a shader program. More...
 
void pgl_destroy_shader (pgl_shader_t *shader)
 Destroys a shader program. More...
 
void pgl_bind_shader (pgl_ctx_t *ctx, pgl_shader_t *shader)
 Activates a shader program for rendering. More...
 
uint64_t pgl_get_shader_id (const pgl_shader_t *shader)
 Return the implementation specific shader ID. More...
 
pgl_texture_tpgl_create_texture (pgl_ctx_t *ctx, bool target, pgl_format_t fmt, bool srgb, int32_t w, int32_t h, bool smooth, bool repeat)
 Creates an empty texture. More...
 
pgl_texture_tpgl_texture_from_bitmap (pgl_ctx_t *ctx, pgl_format_t fmt, bool srgb, int32_t w, int32_t h, bool smooth, bool repeat, const uint8_t *bitmap)
 Creates a texture from a bitmap. More...
 
int pgl_upload_texture (pgl_ctx_t *ctx, pgl_texture_t *texture, int32_t w, int32_t h, const uint8_t *bitmap)
 Uploads data from a bitmap into a texture. More...
 
void pgl_update_texture (pgl_ctx_t *ctx, pgl_texture_t *texture, int x, int y, int w, int h, const uint8_t *bitmap)
 Updates a region of an existing texture. More...
 
int pgl_generate_mipmap (pgl_texture_t *texture, bool linear)
 Generate mipmaps for the specified texture. More...
 
void pgl_destroy_texture (pgl_texture_t *texture)
 Destroys a texture. More...
 
void pgl_get_texture_size (const pgl_texture_t *texture, int *w, int *h)
 Gets texture size. More...
 
void pgl_get_max_texture_size (int *w, int *h)
 
uint64_t pgl_get_texture_id (const pgl_texture_t *texture)
 Return the implementation specific texture ID. More...
 
void pgl_bind_texture (pgl_ctx_t *ctx, pgl_texture_t *texture)
 Activates a texture for rendering. More...
 
int pgl_set_render_target (pgl_ctx_t *ctx, pgl_texture_t *texture)
 Draw to texture. More...
 
void pgl_clear (float r, float g, float b, float a)
 Clears the framebuffer to the specified color. More...
 
void pgl_draw_array (pgl_ctx_t *ctx, pgl_primitive_t primitive, const pgl_vertex_t *vertices, pgl_size_t count, pgl_texture_t *texture, pgl_shader_t *shader)
 
void pgl_draw_indexed_array (pgl_ctx_t *ctx, pgl_primitive_t primitive, const pgl_vertex_t *vertices, pgl_size_t vertex_count, const uint32_t *indices, pgl_size_t index_count, pgl_texture_t *texture, pgl_shader_t *shader)
 
pgl_buffer_tpgl_create_buffer (pgl_ctx_t *ctx, pgl_primitive_t primitive, const pgl_vertex_t *vertices, pgl_size_t count)
 Creates a buffer in VRAM to store an array of vertices that can then be rendered without having upload the vertices every time they are drawn. More...
 
void pgl_destroy_buffer (pgl_buffer_t *buffer)
 Destroys a previously created buffer. More...
 
void pgl_draw_buffer (pgl_ctx_t *ctx, const pgl_buffer_t *buffer, pgl_size_t start, pgl_size_t count, pgl_texture_t *texture, pgl_shader_t *shader)
 Draw a previously created buffer. More...
 
void pgl_set_transpose (pgl_ctx_t *ctx, bool enabled)
 Turns matrix transposition on/off. More...
 
void pgl_set_blend_mode (pgl_ctx_t *ctx, pgl_blend_mode_t mode)
 Set the blending mode. More...
 
void pgl_reset_blend_mode (pgl_ctx_t *ctx)
 Resets the blend mode to standard alpha blending. More...
 
void pgl_set_transform (pgl_ctx_t *ctx, const pgl_m4_t matrix)
 Sets the context's global tranformation matrix. More...
 
void pgl_set_transform_3d (pgl_ctx_t *ctx, const pgl_m3_t matrix)
 3D variant of pgl_set_transform More...
 
void pgl_reset_transform (pgl_ctx_t *ctx)
 Resets the context's transform to the identity matrix. More...
 
void pgl_set_projection (pgl_ctx_t *ctx, const pgl_m4_t matrix)
 Sets a context's global projecton matrix. More...
 
void pgl_set_projection_3d (pgl_ctx_t *ctx, const pgl_m3_t matrix)
 3D variant of pgl_set_projection More...
 
void pgl_reset_projection (pgl_ctx_t *ctx)
 Resets the context's project to the identity matrix. More...
 
void pgl_set_viewport (pgl_ctx_t *ctx, int32_t x, int32_t y, int32_t w, int32_t h)
 Sets the location and dimensions of the rendering viewport. More...
 
void pgl_reset_viewport (pgl_ctx_t *ctx)
 Reset the viewport to the drawable dimensions of the context. More...
 
void pgl_set_line_width (pgl_ctx_t *ctx, float line_width)
 Sets the line primitive width. More...
 
void pgl_reset_line_width (pgl_ctx_t *ctx)
 Resets the line width to 1.0f. More...
 
void pgl_reset_state (pgl_ctx_t *ctx)
 Resets the current state of the context. More...
 
void pgl_push_state (pgl_ctx_t *ctx)
 Pushes the current state onto the state stack, allowing it to be restored later. More...
 
void pgl_pop_state (pgl_ctx_t *ctx)
 Pops a state off of the state stack and makes it the current state. More...
 
void pgl_clear_stack (pgl_ctx_t *ctx)
 Removes all states from the state stack. More...
 
void pgl_set_bool (pgl_shader_t *shader, const char *name, bool value)
 Sets a boolean uniform. More...
 
void pgl_set_1i (pgl_shader_t *shader, const char *name, int32_t a)
 Sets an integer uniform. More...
 
void pgl_set_2i (pgl_shader_t *shader, const char *name, int32_t a, int32_t b)
 Sets a 2D integer uniform. More...
 
void pgl_set_3i (pgl_shader_t *shader, const char *name, int32_t a, int32_t b, int32_t c)
 Sets a 3D integer uniform. More...
 
void pgl_set_4i (pgl_shader_t *shader, const char *name, int32_t a, int32_t b, int32_t c, int32_t d)
 Sets a 4D integer uniform. More...
 
void pgl_set_v2i (pgl_shader_t *shader, const char *name, const pgl_v2i_t vec)
 Sets a 2D integer uniform by vector. More...
 
void pgl_set_v3i (pgl_shader_t *shader, const char *name, const pgl_v3i_t vec)
 Sets a 3D integer uniform by vector. More...
 
void pgl_set_v4i (pgl_shader_t *shader, const char *name, const pgl_v4i_t vec)
 Sets a 4D integer uniform by vector. More...
 
void pgl_set_1f (pgl_shader_t *shader, const char *name, float x)
 Sets an floating point uniform. More...
 
void pgl_set_2f (pgl_shader_t *shader, const char *name, float x, float y)
 Sets a 2D floating point uniform. More...
 
void pgl_set_3f (pgl_shader_t *shader, const char *name, float x, float y, float z)
 Sets a 3D floating point uniform. More...
 
void pgl_set_4f (pgl_shader_t *shader, const char *name, float x, float y, float z, float w)
 Sets a 4D floating point uniform. More...
 
void pgl_set_v2f (pgl_shader_t *shader, const char *name, const pgl_v2f_t vec)
 Sets a 2D floating point uniform by vector. More...
 
void pgl_set_v3f (pgl_shader_t *shader, const char *name, const pgl_v3f_t vec)
 Sets a 3D floating point uniform by vector. More...
 
void pgl_set_v4f (pgl_shader_t *shader, const char *name, const pgl_v4f_t vec)
 Sets a 4D floating point uniform by vector. More...
 
void pgl_set_a1f (pgl_shader_t *shader, const char *name, const float array[], pgl_size_t count)
 Sends an array of floating point numbers. More...
 
void pgl_set_a2f (pgl_shader_t *shader, const char *name, const pgl_v2f_t array[], pgl_size_t count)
 Sends an array of 2D floating point vectors. More...
 
void pgl_set_a3f (pgl_shader_t *shader, const char *name, const pgl_v3f_t array[], pgl_size_t count)
 Sends an array of 3D floating point vectors. More...
 
void pgl_set_a4f (pgl_shader_t *shader, const char *name, const pgl_v4f_t array[], pgl_size_t count)
 Sends an array of 4D floating point vectors. More...
 
void pgl_set_m2 (pgl_shader_t *shader, const char *name, const pgl_m2_t matrix)
 Sets a 2x2 floating point matrix. More...
 
void pgl_set_m3 (pgl_shader_t *shader, const char *name, const pgl_m3_t matrix)
 Sets a 3x3 floating point matrix. More...
 
void pgl_set_m4 (pgl_shader_t *shader, const char *name, const pgl_m4_t matrix)
 Sets a 4x4 floating point matrix. More...
 
void pgl_set_s2d (pgl_shader_t *shader, const char *name, int32_t value)
 Sets a 2D sampler uniform. More...
 

Detailed Description

A powerful OpenGL-based graphics library written in C99.

============================================================================= WARNING: This file was automatically generated on 21/04/2023 14:29:16.

DO NOT EDIT!


Licensing information at end of header

Features:

Summary:

This library is an advanced 2D renderer built on top of OpenGL. It currently supports OpenGL 3.0+ and OpenGL ES 3+ as well.

The basic workflow is to initialize the library, create a context, load any shaders and/or textures needed, specify some geometry (vertices) and draw the buffer or array of vertices. A vertex consists of position, color, and uv coordinates.

There is a default shader that makes sensible assumptions about how vertices and textures will be used. It is likely to be sufficient unless performing advanced VFX.

The default shader exposes two uniform variables: 1) a projection matrix; and 2) an affine transformation matrix. These two matrices are multipled together to form the mapping from vertices to the screen.

State including blend mode, the projection and transform matrices, and the viewport parameters are managed using the state stack. This enables state changes to be isolated. Push the current state on the top of the stack, make some local changes, and pop the stack to restore the original state.

Uniforms can be set using a simple, fast, and concise API.

Please see the examples for more details.

To use this library in your project, add

#define PICO_GL_IMPLEMENTATION #include "pico_gl.h"

to a source file.

Constants:

Must be defined before PICO_GL_IMPLEMENTATION

Todo:

Typedef Documentation

◆ pgl_size_t

typedef uint32_t pgl_size_t

OpenGL compatible size type.

◆ pgl_v2f_t

typedef float pgl_v2f_t[2]

2D floating point vector

◆ pgl_v3f_t

typedef float pgl_v3f_t[3]

3D floating point vector

◆ pgl_v4f_t

typedef float pgl_v4f_t[4]

4D floating point vector

◆ pgl_v2i_t

typedef int32_t pgl_v2i_t[2]

2D integer vector

◆ pgl_v3i_t

typedef int32_t pgl_v3i_t[3]

3D integer vector

◆ pgl_v4i_t

typedef int32_t pgl_v4i_t[4]

4D integer vector

◆ pgl_m2_t

typedef float pgl_m2_t[4]

2x2 floating point matrix

◆ pgl_m3_t

typedef float pgl_m3_t[9]

3x3 floating point matrix

◆ pgl_m4_t

typedef float pgl_m4_t[16]

4x4 floating point matrix

◆ pgl_ctx_t

typedef struct pgl_ctx_t pgl_ctx_t

Contains core data/state for an instance of the renderer.

◆ pgl_shader_t

typedef struct pgl_shader_t pgl_shader_t

Contains shader data/state.

◆ pgl_texture_t

typedef struct pgl_texture_t pgl_texture_t

Contains texture data/state.

◆ pgl_buffer_t

typedef struct pgl_buffer_t pgl_buffer_t

Contains vertex buffer data/state.

◆ pgl_loader_fn

typedef void*(* pgl_loader_fn) (const char *name)

Defines an OpenGL (GLAD) function loader.

Parameters
nameThe name of the function to load

Enumeration Type Documentation

◆ pgl_error_t

Runtime error codes.

Enumerator
PGL_NO_ERROR 

No error.

PGL_INVALID_ENUM 

Invalid enumeration value.

PGL_INVALID_VALUE 

Invalid value.

PGL_INVALID_OPERATION 

Invalid operation.

PGL_OUT_OF_MEMORY 

Out of memory.

PGL_INVALID_FRAMEBUFFER_OPERATION 

Invalid framebuffer operation.

PGL_FRAMEBUFFER_INCOMPLETE 

Framebuffer is incomplete.

PGL_SHADER_COMPILATION_ERROR 

Shader compilation error.

PGL_SHADER_LINKING_ERROR 

Shader linking error.

PGL_INVALID_TEXTURE_SIZE 

Invalid texture dimensions.

PGL_INVALID_TEXTURE_FORMAT 

Invalid texture format.

PGL_INVALID_ATTRIBUTE_COUNT 

Invalid number of attributes.

PGL_INVALID_UNIFORM_COUNT 

Invalid number of uniforms.

PGL_INVALID_UNIFORM_NAME 

Invalid uniform name.

PGL_UNKNOWN_ERROR 

Unknown error.

PGL_ERROR_COUNT 

◆ pgl_version_t

OpenGL versions used by the library.

Enumerator
PGL_GL3 
PGL_GLES3 
PGL_VERSION_UNSUPPORTED 

◆ pgl_format_t

Pixel formats.

Enumerator
PGL_RED 

(red, 0, 0, 1)

PGL_RGB 

(red, green, blue, 1)

PGL_RGBA 

(red, green, blue, alpha)

PGL_BGR 

(blue, green, red, 1)

PGL_BGRA 

(blue, green, red, alpha)

PGL_FORMAT_COUNT 

◆ pgl_blend_factor_t

Blend factors.

Enumerator
PGL_ZERO 

(0, 0, 0, 0)

PGL_ONE 

(1, 1, 1, 1)

PGL_SRC_COLOR 

(src.r, src.g, src.b, src.a)

PGL_ONE_MINUS_SRC_COLOR 

(1, 1, 1, 1) - (src.r, src.g, src.b, src.a)

PGL_DST_COLOR 

(dst.r, dst.g, dst.b, dst.a)

PGL_ONE_MINUS_DST_COLOR 

(1, 1, 1, 1) - (dst.r, dst.g, dst.b, dst.a)

PGL_SRC_ALPHA 

(src.a, src.a, src.a, src.a)

PGL_ONE_MINUS_SRC_ALPHA 

(1, 1, 1, 1) - (src.a, src.a, src.a, src.a)

PGL_DST_ALPHA 

(dst.a, dst.a, dst.a, dst.a)

PGL_ONE_MINUS_DST_ALPHA 

(1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a)

PGL_FACTOR_COUNT 

◆ pgl_blend_eq_t

Blend equations.

Enumerator
PGL_FUNC_ADD 

result = src * src_factor + dst * dst_factor

PGL_FUNC_SUBTRACT 

result = src * src_factor - dst * dst_factor

PGL_FUNC_REVERSE_SUBTRACT 

result = dst * dst_factor - src * src_factor

PGL_MIN 

result = min(src, dst)

PGL_MAX 

result = max(src, dst)

PGL_EQ_COUNT 

◆ pgl_primitive_t

Drawing primitives.

Enumerator
PGL_POINTS 

Array of points.

PGL_LINES 

Each adjacent pair of points forms a line.

PGL_LINE_STRIP 

Array of points where every pair forms a lines.

PGL_TRIANGLES 

Each adjacent triple forms an individual triangle.

PGL_TRIANGLE_STRIP 

Array of points where every triple forms a triangle.

Function Documentation

◆ pgl_global_init()

int pgl_global_init ( pgl_loader_fn  loader_fp,
bool  gles 
)

Loads all supported OpenGL functions via GLAD.

IMPORTANT: A valid OpenGL context must exist for this function to succeed. This function must be called before any other PGL functions.

Parameters
loader_fpFunction loader (can be NULL except for GLES contexts)
glesSet to true if using OpenGL ES
Returns
-1 on failure and 0 otherwise

◆ pgl_get_error()

pgl_error_t pgl_get_error ( pgl_ctx_t ctx)

Returns the current error code.

◆ pgl_get_error_str()

const char* pgl_get_error_str ( pgl_error_t  code)

Returns the string associated with the specified error code.

Parameters
codeThe error code to query
Returns
The string representation of the error code

◆ pgl_get_version()

pgl_version_t pgl_get_version ( )

Returns the current OpenGL version in use by the library.

Currently the library does not use OpenGL features outside of 3.0 and ES 3.0. This unlikely to change unless there is an incompatibility with more recent versions or the library is ported to OpenGL 2.1.

Returns
PGL_VERSION_UNSUPPORTED if the version of OpenGL is not supported

◆ pgl_print_info()

void pgl_print_info ( )

Prints system info.

◆ pgl_create_context()

pgl_ctx_t* pgl_create_context ( uint32_t  w,
uint32_t  h,
bool  depth,
uint32_t  samples,
bool  srgb,
void *  mem_ctx 
)

Creates an instance of the renderer.

Parameters
wThe drawable width of the window in pixels
hThe drawable height of the window in pixels
depthDepth test is enabled if true
samplesThe number of MSAA (anti-alising) samples (disabled if 0)
srgbEnables support for the sRGB colorspace
mem_ctxUser data provided to custom allocators
Returns
The context pointer or NULL on error

◆ pgl_destroy_context()

void pgl_destroy_context ( pgl_ctx_t ctx)

Destroys a renderer context, releasing it's resources.

Parameters
ctxA pointer to the context

◆ pgl_resize()

void pgl_resize ( pgl_ctx_t ctx,
uint32_t  w,
uint32_t  h,
bool  reset_vp 
)

Resizes the drawable dimensions.

Parameters
ctxA pointer to the context
wThe drawable width of the window in pixels
hThe drawable height of the window in pixels @pawram reset_vp Resets the viewport if true

◆ pgl_create_shader()

pgl_shader_t* pgl_create_shader ( pgl_ctx_t ctx,
const char *  vert_src,
const char *  frag_src 
)

Creates a shader program.

If vert_src and frag_src are both NULL, then the shader is compiled from the default vertex and fragment sources. If either vert_src or frag_src are NULL, then the shader is compiled from the (respective) default vertex or fragment source, together with the non-NULL argument.

Parameters
ctxThe relevant context
vert_srcVertex shader source
frag_srcFragment shader source
Returns
Pointer to the shader program, or NULL on error

◆ pgl_destroy_shader()

void pgl_destroy_shader ( pgl_shader_t shader)

Destroys a shader program.

Parameters
shaderPointer to the shader program

◆ pgl_bind_shader()

void pgl_bind_shader ( pgl_ctx_t ctx,
pgl_shader_t shader 
)

Activates a shader program for rendering.

This function sets the context's currently active shader. If shader is NULL the current shader is deactivated.

Parameters
ctxThe relevant context
shaderThe shader program to activate, or NULL to deactivate

◆ pgl_get_shader_id()

uint64_t pgl_get_shader_id ( const pgl_shader_t shader)

Return the implementation specific shader ID.

Parameters
shaderThe target shader
Returns
An unsigned 64-bit ID value

◆ pgl_create_texture()

pgl_texture_t* pgl_create_texture ( pgl_ctx_t ctx,
bool  target,
pgl_format_t  fmt,
bool  srgb,
int32_t  w,
int32_t  h,
bool  smooth,
bool  repeat 
)

Creates an empty texture.

Parameters
ctxThe relevant context
targetIf true, the texture can be used as a render target
wThe texture's width
hThe texture's height
srgbTrue if the internal format is sRGB
smoothHigh (true) or low (false) quality filtering
repeatRepeats or clamps when uv coordinates exceed 1.0

◆ pgl_texture_from_bitmap()

pgl_texture_t* pgl_texture_from_bitmap ( pgl_ctx_t ctx,
pgl_format_t  fmt,
bool  srgb,
int32_t  w,
int32_t  h,
bool  smooth,
bool  repeat,
const uint8_t *  bitmap 
)

Creates a texture from a bitmap.

Parameters
ctxThe relevant context
wThe texture's width
hThe texture's height
srgbTrue if the internal format is sRGB
smoothHigh (true) or low (false) quality filtering
repeatRepeats or clamps when uv coordinates exceed 1.0
bitmapPixel data in RGBA format

◆ pgl_upload_texture()

int pgl_upload_texture ( pgl_ctx_t ctx,
pgl_texture_t texture,
int32_t  w,
int32_t  h,
const uint8_t *  bitmap 
)

Uploads data from a bitmap into a texture.

Parameters
ctxThe relevant context
textureThe target texture
wThe texture's width
hThe texture's height
bitmapThe pixel data in RGBA

◆ pgl_update_texture()

void pgl_update_texture ( pgl_ctx_t ctx,
pgl_texture_t texture,
int  x,
int  y,
int  w,
int  h,
const uint8_t *  bitmap 
)

Updates a region of an existing texture.

Parameters
ctxThe relevant context
textureThe texture to update
xThe x offset of the region
yThe y offset of the region
wThe width of the region
hThe height of the region
bitmapThe pixel data in RGBA

◆ pgl_generate_mipmap()

int pgl_generate_mipmap ( pgl_texture_t texture,
bool  linear 
)

Generate mipmaps for the specified texture.

Generates a sequence of smaller pre-filtered / pre-optimized textures intended to reduce the effects of aliasing when rendering smaller versions of the texture.

Parameters
texturePointer to the target texture
linearDetermines the selection of the which mipmap to blend
Returns
0 on success and -1 on failure

◆ pgl_destroy_texture()

void pgl_destroy_texture ( pgl_texture_t texture)

Destroys a texture.

Parameters
textureTexture to destroy

◆ pgl_get_texture_size()

void pgl_get_texture_size ( const pgl_texture_t texture,
int *  w,
int *  h 
)

Gets texture size.

Parameters
textureThe texture
wPointer to width (output)
hPointer to height (output)

◆ pgl_get_max_texture_size()

void pgl_get_max_texture_size ( int *  w,
int *  h 
)

Gets maximum texture size as reported by OpenGL

Parameters
wPointer to width (output)
hPoineter to height (output)

◆ pgl_get_texture_id()

uint64_t pgl_get_texture_id ( const pgl_texture_t texture)

Return the implementation specific texture ID.

Parameters
textureThe target texture
Returns
An unsigned 64-bit ID value

◆ pgl_bind_texture()

void pgl_bind_texture ( pgl_ctx_t ctx,
pgl_texture_t texture 
)

Activates a texture for rendering.

This function sets the context's currently texture. If texture is NULL the current texture is deactivated.

Parameters
ctxThe relevant context
textureThe texture to activate, or NULL to deactivate

◆ pgl_set_render_target()

int pgl_set_render_target ( pgl_ctx_t ctx,
pgl_texture_t texture 
)

Draw to texture.

The function set a texture to be the target for rendering until the texture if replaced by another or set to NULL.

Parameters
ctxThe relevant context
textureThe render target
Returns
0 on success and -1 on failure

◆ pgl_clear()

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

Clears the framebuffer to the specified color.

All of the parameters are in [0.0, 1.0]

◆ pgl_draw_array()

void pgl_draw_array ( pgl_ctx_t ctx,
pgl_primitive_t  primitive,
const pgl_vertex_t vertices,
pgl_size_t  count,
pgl_texture_t texture,
pgl_shader_t shader 
)

Draws primitives according to a vertex array

Parameters
ctxThe relevant context
primitiveThe type of geometry to draw
verticesA vertex array
countThe number of vertices
textureThe texture to draw from (can be NULL)
shaderThe shader used to draw the array (cannot be NULL)

◆ pgl_draw_indexed_array()

void pgl_draw_indexed_array ( pgl_ctx_t ctx,
pgl_primitive_t  primitive,
const pgl_vertex_t vertices,
pgl_size_t  vertex_count,
const uint32_t *  indices,
pgl_size_t  index_count,
pgl_texture_t texture,
pgl_shader_t shader 
)

Draws primvities according to vertex and index arrays

Parameters
ctxThe relevant context
primitiveThe type of geometry to draw
verticesAn array of vertices
vertex_countThe number of vertices
indicesAn array of indices
index_count The number of indicies
textureThe texture to draw from (can be NULL)
shaderThe shader used to draw the array (cannot be NULL)

◆ pgl_create_buffer()

pgl_buffer_t* pgl_create_buffer ( pgl_ctx_t ctx,
pgl_primitive_t  primitive,
const pgl_vertex_t vertices,
pgl_size_t  count 
)

Creates a buffer in VRAM to store an array of vertices that can then be rendered without having upload the vertices every time they are drawn.

Parameters
ctxThe relevant context
primitiveThe type of geometry to draw
verticesA vertex array
countThe number of vertices to store in the buffer
Returns
A pointer to the buffer or NULL on error

◆ pgl_destroy_buffer()

void pgl_destroy_buffer ( pgl_buffer_t buffer)

Destroys a previously created buffer.

◆ pgl_draw_buffer()

void pgl_draw_buffer ( pgl_ctx_t ctx,
const pgl_buffer_t buffer,
pgl_size_t  start,
pgl_size_t  count,
pgl_texture_t texture,
pgl_shader_t shader 
)

Draw a previously created buffer.

Parameters
ctxThe relevant context
bufferThe buffer to draw
startThe base vertex index
countThe number of vertices to draw from start
textureThe texture to draw from (can be NULL)
shaderThe shader used to draw the array (cannot be NULL)

◆ pgl_set_transpose()

void pgl_set_transpose ( pgl_ctx_t ctx,
bool  enabled 
)

Turns matrix transposition on/off.

◆ pgl_set_blend_mode()

void pgl_set_blend_mode ( pgl_ctx_t ctx,
pgl_blend_mode_t  mode 
)

Set the blending mode.

Parameters
ctxThe relevant context
modeThe blending mode (
See also
pgl_blend_mode_t)

◆ pgl_reset_blend_mode()

void pgl_reset_blend_mode ( pgl_ctx_t ctx)

Resets the blend mode to standard alpha blending.

Parameters
ctxThe relevant context

◆ pgl_set_transform()

void pgl_set_transform ( pgl_ctx_t ctx,
const pgl_m4_t  matrix 
)

Sets the context's global tranformation matrix.

Parameters
ctxThe relevant context
matrixThe global transform matrix

◆ pgl_set_transform_3d()

void pgl_set_transform_3d ( pgl_ctx_t ctx,
const pgl_m3_t  matrix 
)

3D variant of pgl_set_transform

Parameters
ctxThe relevant context
matrixThe 3D global transform matrix

◆ pgl_reset_transform()

void pgl_reset_transform ( pgl_ctx_t ctx)

Resets the context's transform to the identity matrix.

Parameters
ctxThe relevant context

◆ pgl_set_projection()

void pgl_set_projection ( pgl_ctx_t ctx,
const pgl_m4_t  matrix 
)

Sets a context's global projecton matrix.

Parameters
ctxThe relevant context
matrixThe global projection matrix

◆ pgl_set_projection_3d()

void pgl_set_projection_3d ( pgl_ctx_t ctx,
const pgl_m3_t  matrix 
)

3D variant of pgl_set_projection

Parameters
ctxThe relevant context
matrixThe 3D global projection matrix

◆ pgl_reset_projection()

void pgl_reset_projection ( pgl_ctx_t ctx)

Resets the context's project to the identity matrix.

Parameters
ctxThe relevant context

◆ pgl_set_viewport()

void pgl_set_viewport ( pgl_ctx_t ctx,
int32_t  x,
int32_t  y,
int32_t  w,
int32_t  h 
)

Sets the location and dimensions of the rendering viewport.

Parameters
ctxThe relevant context
xThe left edge of the viewport
yThe bottom edge of the viewport
wThe width of the viewport
hThe height of the viewort

◆ pgl_reset_viewport()

void pgl_reset_viewport ( pgl_ctx_t ctx)

Reset the viewport to the drawable dimensions of the context.

Parameters
ctxThe relevant context

◆ pgl_set_line_width()

void pgl_set_line_width ( pgl_ctx_t ctx,
float  line_width 
)

Sets the line primitive width.

◆ pgl_reset_line_width()

void pgl_reset_line_width ( pgl_ctx_t ctx)

Resets the line width to 1.0f.

◆ pgl_reset_state()

void pgl_reset_state ( pgl_ctx_t ctx)

Resets the current state of the context.

Resets the global transform, projection, blend mode, and viewport.

Parameters
ctxThe relevant context

◆ pgl_push_state()

void pgl_push_state ( pgl_ctx_t ctx)

Pushes the current state onto the state stack, allowing it to be restored later.

Parameters
ctxThe relevant context

◆ pgl_pop_state()

void pgl_pop_state ( pgl_ctx_t ctx)

Pops a state off of the state stack and makes it the current state.

Parameters
ctxThe relevant context

◆ pgl_clear_stack()

void pgl_clear_stack ( pgl_ctx_t ctx)

Removes all states from the state stack.

Parameters
ctxThe relevant context

◆ pgl_set_bool()

void pgl_set_bool ( pgl_shader_t shader,
const char *  name,
bool  value 
)

Sets a boolean uniform.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
valueThe boolean value

◆ pgl_set_1i()

void pgl_set_1i ( pgl_shader_t shader,
const char *  name,
int32_t  a 
)

Sets an integer uniform.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
valueThe integer value

◆ pgl_set_2i()

void pgl_set_2i ( pgl_shader_t shader,
const char *  name,
int32_t  a,
int32_t  b 
)

Sets a 2D integer uniform.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
aThe first value
bThe second value

◆ pgl_set_3i()

void pgl_set_3i ( pgl_shader_t shader,
const char *  name,
int32_t  a,
int32_t  b,
int32_t  c 
)

Sets a 3D integer uniform.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
aThe first value
bThe second value
cThe third value

◆ pgl_set_4i()

void pgl_set_4i ( pgl_shader_t shader,
const char *  name,
int32_t  a,
int32_t  b,
int32_t  c,
int32_t  d 
)

Sets a 4D integer uniform.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
aThe first value
bThe second value
cThe third value
dThe fourth value

◆ pgl_set_v2i()

void pgl_set_v2i ( pgl_shader_t shader,
const char *  name,
const pgl_v2i_t  vec 
)

Sets a 2D integer uniform by vector.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
vecThe vector

◆ pgl_set_v3i()

void pgl_set_v3i ( pgl_shader_t shader,
const char *  name,
const pgl_v3i_t  vec 
)

Sets a 3D integer uniform by vector.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
vecThe vector

◆ pgl_set_v4i()

void pgl_set_v4i ( pgl_shader_t shader,
const char *  name,
const pgl_v4i_t  vec 
)

Sets a 4D integer uniform by vector.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
vecThe vector

◆ pgl_set_1f()

void pgl_set_1f ( pgl_shader_t shader,
const char *  name,
float  x 
)

Sets an floating point uniform.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
xThe float value

◆ pgl_set_2f()

void pgl_set_2f ( pgl_shader_t shader,
const char *  name,
float  x,
float  y 
)

Sets a 2D floating point uniform.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
xThe first value
yThe second value

◆ pgl_set_3f()

void pgl_set_3f ( pgl_shader_t shader,
const char *  name,
float  x,
float  y,
float  z 
)

Sets a 3D floating point uniform.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
xThe first value
yThe second value
zThe third value

◆ pgl_set_4f()

void pgl_set_4f ( pgl_shader_t shader,
const char *  name,
float  x,
float  y,
float  z,
float  w 
)

Sets a 4D floating point uniform.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
xThe first value
yThe second value
wThe third value
zThe fourth value

◆ pgl_set_v2f()

void pgl_set_v2f ( pgl_shader_t shader,
const char *  name,
const pgl_v2f_t  vec 
)

Sets a 2D floating point uniform by vector.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
vecThe vector

◆ pgl_set_v3f()

void pgl_set_v3f ( pgl_shader_t shader,
const char *  name,
const pgl_v3f_t  vec 
)

Sets a 3D floating point uniform by vector.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
vecThe vector

◆ pgl_set_v4f()

void pgl_set_v4f ( pgl_shader_t shader,
const char *  name,
const pgl_v4f_t  vec 
)

Sets a 4D floating point uniform by vector.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
vecThe vector

◆ pgl_set_a1f()

void pgl_set_a1f ( pgl_shader_t shader,
const char *  name,
const float  array[],
pgl_size_t  count 
)

Sends an array of floating point numbers.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
arrayThe array of floats
countThe size of the array

◆ pgl_set_a2f()

void pgl_set_a2f ( pgl_shader_t shader,
const char *  name,
const pgl_v2f_t  array[],
pgl_size_t  count 
)

Sends an array of 2D floating point vectors.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
arrayThe array of vectors
countThe size of the array

◆ pgl_set_a3f()

void pgl_set_a3f ( pgl_shader_t shader,
const char *  name,
const pgl_v3f_t  array[],
pgl_size_t  count 
)

Sends an array of 3D floating point vectors.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
arrayThe array of vectors
countThe size of the array

◆ pgl_set_a4f()

void pgl_set_a4f ( pgl_shader_t shader,
const char *  name,
const pgl_v4f_t  array[],
pgl_size_t  count 
)

Sends an array of 4D floating point vectors.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
arrayThe array of vectors
countThe size of the array

◆ pgl_set_m2()

void pgl_set_m2 ( pgl_shader_t shader,
const char *  name,
const pgl_m2_t  matrix 
)

Sets a 2x2 floating point matrix.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
matrixThe matrix

◆ pgl_set_m3()

void pgl_set_m3 ( pgl_shader_t shader,
const char *  name,
const pgl_m3_t  matrix 
)

Sets a 3x3 floating point matrix.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
matrixThe matrix

◆ pgl_set_m4()

void pgl_set_m4 ( pgl_shader_t shader,
const char *  name,
const pgl_m4_t  matrix 
)

Sets a 4x4 floating point matrix.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
matrixThe matrix

◆ pgl_set_s2d()

void pgl_set_s2d ( pgl_shader_t shader,
const char *  name,
int32_t  value 
)

Sets a 2D sampler uniform.

Parameters
shaderThe uniform's shader program
nameThe name of the uniform
valueThe sampler's texture unit