Gama C Library
Gama C API Documentation
gapi.h File Reference

Graphics API (GAPI) abstraction layer for Gama. More...

#include "color.h"
#include <stdint.h>

Go to the source code of this file.

Functions

void gapi_set_title (const char *title)
 Sets the title of the application window.
void gapi_resize (const int32_t width, const int32_t height)
 Resizes the application window.
void gapi_set_background_color (const gmColor background)
 Sets the background color of the application window.
void gapi_fullscreen (const int32_t fullscreen)
 Toggles fullscreen mode for the application window.
void gapi_log (const char *message)
 Logs a message to the platform's console.
int32_t gapi_init (const int32_t width, const int32_t height, const char *title)
 Initializes the Graphics API and the application window.
int32_t gapi_yield (double *dt)
 Yields control to the platform, processes events, and updates timing.
void gapi_quit ()
 Requests the application to quit.
int32_t gapi_runs ()
 Checks if the application is still running.
int32_t gapi_draw_line (double x1, double y1, double x2, double y2, double thickness, gmColor col)
 Draws a line segment on the screen.
int32_t gapi_draw_rect (double x, double y, double w, double h, gmColor col)
 Draws a filled rectangle on the screen.
int32_t gapi_draw_rounded_rect (double x, double y, double w, double h, double r, gmColor col)
 Draws a filled rectangle with rounded corners on the screen.
int32_t gapi_draw_circle (double center_x, double center_y, double radius, gmColor col)
 Draws a filled circle on the screen.
int32_t gapi_draw_ellipse (double x, double y, double w, double h, gmColor col)
 Draws a filled ellipse on the screen.
int32_t gapi_draw_triangle (double x1, double y1, double x2, double y2, double x3, double y3, gmColor col)
 Draws a filled triangle on the screen.
int32_t gapi_draw_triangles (uint32_t n_triangles, double *points, gmColor *colors)
 Draws a batch of triangles on the screen.
uint32_t gapi_create_image (const unsigned char *data, uint32_t width, uint32_t height)
 Creates a platform-specific image handle from raw pixel data.
int32_t gapi_draw_image (uint32_t handle, double x, double y, double width, double height)
 Draws an image referenced by its handle on the screen.
int32_t gapi_draw_image_part (uint32_t handle, uint32_t slice_x, uint32_t slice_y, uint32_t slice_width, uint32_t slice_height, double x, double y, double width, double height)
 Draws a part of an image referenced by its handle on the screen.
int32_t gapi_draw_text (double x, double y, double height, const char *txt, const char *font, uint8_t style, gmColor col)
 Draws text on the screen.
int32_t gapi_key_down (char t, char k)
 Checks if a specific key is currently pressed.
int32_t gapi_mouse_down ()
 Checks if the mouse button is currently pressed.
int32_t gapi_mouse_get (double *x, double *y)
 Retrieves the current mouse cursor position.

Variables

double _gm_dt = 0
double _gm_t = 0

Detailed Description

Graphics API (GAPI) abstraction layer for Gama.

This file declares the interface for platform-specific graphics operations. It provides a set of gapi_ prefixed functions that are implemented differently for each target platform (e.g., native desktop, WebAssembly). This abstraction allows the core Gama engine code to remain platform-agnostic.

Function Documentation

◆ gapi_create_image()

uint32_t gapi_create_image ( const unsigned char * data,
uint32_t width,
uint32_t height )
extern

Creates a platform-specific image handle from raw pixel data.

This function is used to upload image data to the GPU or create a drawable surface that can be used by gapi_draw_image functions.

Parameters
dataA pointer to the raw RGBA pixel data.
widthThe width of the image.
heightThe height of the image.
Returns
A unique handle (ID) for the created image on success, 0 on failure.

◆ gapi_draw_circle()

int32_t gapi_draw_circle ( double center_x,
double center_y,
double radius,
gmColor col )
extern

Draws a filled circle on the screen.

Parameters
center_xThe x-coordinate of the center of the circle.
center_yThe y-coordinate of the center of the circle.
radiusThe radius of the circle.
colThe gmColor of the circle.
Returns
0 on success.

◆ gapi_draw_ellipse()

int32_t gapi_draw_ellipse ( double x,
double y,
double w,
double h,
gmColor col )
extern

Draws a filled ellipse on the screen.

Parameters
xThe x-coordinate of the center of the ellipse.
yThe y-coordinate of the center of the ellipse.
wThe width of the ellipse.
hThe height of the ellipse.
colThe gmColor of the ellipse.
Returns
0 on success.

◆ gapi_draw_image()

int32_t gapi_draw_image ( uint32_t handle,
double x,
double y,
double width,
double height )
extern

Draws an image referenced by its handle on the screen.

Parameters
handleThe handle of the image to draw, obtained from gapi_create_image.
xThe x-coordinate of the center of the image.
yThe y-coordinate of the center of the image.
widthThe width to draw the image.
heightThe height to draw the image.
Returns
0 on success.

◆ gapi_draw_image_part()

int32_t gapi_draw_image_part ( uint32_t handle,
uint32_t slice_x,
uint32_t slice_y,
uint32_t slice_width,
uint32_t slice_height,
double x,
double y,
double width,
double height )
extern

Draws a part of an image referenced by its handle on the screen.

Parameters
handleThe handle of the image to draw from.
slice_xThe x-coordinate of the top-left corner of the source slice.
slice_yThe y-coordinate of the top-left corner of the source slice.
slice_widthThe width of the source slice.
slice_heightThe height of the source slice.
xThe x-coordinate of the center of the destination rectangle.
yThe y-coordinate of the center of the destination rectangle.
widthThe width to draw the slice.
heightThe height to draw the slice.
Returns
0 on success.

◆ gapi_draw_line()

int32_t gapi_draw_line ( double x1,
double y1,
double x2,
double y2,
double thickness,
gmColor col )
extern

Draws a line segment on the screen.

Parameters
x1The x-coordinate of the start point.
y1The y-coordinate of the start point.
x2The x-coordinate of the end point.
y2The y-coordinate of the end point.
thicknessThe thickness of the line.
colThe gmColor of the line.
Returns
0 on success.

◆ gapi_draw_rect()

int32_t gapi_draw_rect ( double x,
double y,
double w,
double h,
gmColor col )
extern

Draws a filled rectangle on the screen.

Parameters
xThe x-coordinate of the center of the rectangle.
yThe y-coordinate of the center of the rectangle.
wThe width of the rectangle.
hThe height of the rectangle.
colThe gmColor of the rectangle.
Returns
0 on success.

◆ gapi_draw_rounded_rect()

int32_t gapi_draw_rounded_rect ( double x,
double y,
double w,
double h,
double r,
gmColor col )
extern

Draws a filled rectangle with rounded corners on the screen.

Parameters
xThe x-coordinate of the center of the rectangle.
yThe y-coordinate of the center of the rectangle.
wThe width of the rectangle.
hThe height of the rectangle.
rThe corner radius.
colThe gmColor of the rectangle.
Returns
0 on success.

◆ gapi_draw_text()

int32_t gapi_draw_text ( double x,
double y,
double height,
const char * txt,
const char * font,
uint8_t style,
gmColor col )
extern

Draws text on the screen.

Parameters
xThe x-coordinate of the center of the text.
yThe y-coordinate of the center of the text.
heightThe height/size of the text.
txtThe null-terminated string to draw.
fontThe null-terminated font name to use.
styleA bitmask for text style (e.g., bold, italic).
colThe gmColor of the text.
Returns
0 on success.

◆ gapi_draw_triangle()

int32_t gapi_draw_triangle ( double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
gmColor col )
extern

Draws a filled triangle on the screen.

Parameters
x1The x-coordinate of the first vertex.
y1The y-coordinate of the first vertex.
x2The x-coordinate of the second vertex.
y2The y-coordinate of the second vertex.
x3The x-coordinate of the third vertex.
y3The y-coordinate of the third vertex.
colThe gmColor of the triangle.
Returns
0 on success.

◆ gapi_draw_triangles()

int32_t gapi_draw_triangles ( uint32_t n_triangles,
double * points,
gmColor * colors )
extern

Draws a batch of triangles on the screen.

Parameters
n_trianglesThe number of triangles in the batch.
pointsAn array of doubles representing the vertices (x1,y1, x2,y2, x3,y3 for each triangle).
colorsAn array of gmColors, one for each triangle.
Returns
0 on success.

◆ gapi_fullscreen()

void gapi_fullscreen ( const int32_t fullscreen)
extern

Toggles fullscreen mode for the application window.

Parameters
fullscreen1 to enable fullscreen, 0 to disable.
Examples
/home/engon/gama/gama/lib/gama/gama.h.

◆ gapi_init()

int32_t gapi_init ( const int32_t width,
const int32_t height,
const char * title )
extern

Initializes the Graphics API and the application window.

This function must be called once at the start of the application.

Parameters
widthThe desired width of the window.
heightThe desired height of the window.
titleThe title of the window.
Returns
0 on success, non-zero on failure.
Examples
/home/engon/gama/gama/lib/gama/gama.h.

◆ gapi_key_down()

int32_t gapi_key_down ( char t,
char k )
extern

Checks if a specific key is currently pressed.

Parameters
tThe type of key ('c' for character, 'a' for arrow, 's' for special).
kThe key code.
Returns
1 if the key is down, 0 otherwise.

◆ gapi_log()

void gapi_log ( const char * message)
extern

Logs a message to the platform's console.

Parameters
messageThe null-terminated string to log.
Examples
/home/engon/gama/gama/lib/gama/gama.h.

◆ gapi_mouse_down()

int32_t gapi_mouse_down ( )
extern

Checks if the mouse button is currently pressed.

Returns
1 if the mouse button is down, 0 otherwise.
Examples
/home/engon/gama/gama/lib/gama/gama.h.

◆ gapi_mouse_get()

int32_t gapi_mouse_get ( double * x,
double * y )
extern

Retrieves the current mouse cursor position.

Parameters
xA pointer to a double to store the x-coordinate.
yA pointer to a double to store the y-coordinate.
Returns
0 on success.
Examples
/home/engon/gama/gama/lib/gama/gama.h.

◆ gapi_quit()

void gapi_quit ( )
extern

Requests the application to quit.

Examples
/home/engon/gama/gama/lib/gama/gama.h.

◆ gapi_resize()

void gapi_resize ( const int32_t width,
const int32_t height )
extern

Resizes the application window.

Parameters
widthThe new width of the window in pixels.
heightThe new height of the window in pixels.
Examples
/home/engon/gama/gama/lib/gama/gama.h.

◆ gapi_runs()

int32_t gapi_runs ( )
extern

Checks if the application is still running.

Returns
1 if running, 0 if quit was requested.
Examples
/home/engon/gama/gama/lib/gama/gama.h.

◆ gapi_set_background_color()

void gapi_set_background_color ( const gmColor background)
extern

Sets the background color of the application window.

Parameters
backgroundThe gmColor to set as the background.
Examples
/home/engon/gama/gama/lib/gama/gama.h.

◆ gapi_set_title()

void gapi_set_title ( const char * title)
extern

Sets the title of the application window.

Parameters
titleThe null-terminated string for the new window title.

◆ gapi_yield()

int32_t gapi_yield ( double * dt)
extern

Yields control to the platform, processes events, and updates timing.

This function should be called at the end of each frame. It handles window events, updates input states, swaps buffers, and calculates _gm_dt.

Parameters
dtA pointer to a double where the calculated delta time will be stored.
Returns
1 if the application should continue, 0 if it should exit.
Examples
/home/engon/gama/gama/lib/gama/gama.h.

Variable Documentation

◆ _gm_dt

double _gm_dt = 0

◆ _gm_t

double _gm_t = 0