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

Functions for drawing shapes, text, and images. More...

#include "body.h"
#include "color.h"
#include "gapi.h"
#include "image.h"
#include <stdint.h>

Go to the source code of this file.

Functions

int gm_cache (unsigned int id)
int32_t gm_draw_line (double x1, double y1, double x2, double y2, double thickness, gmColor c)
 Draws a line segment.
int32_t gm_draw_rectangle (double x, double y, double w, double h, gmColor c)
 Draws a rectangle centered at a point.
int32_t gm_draw_rounded_rectangle (double x, double y, double w, double h, double r, gmColor c)
 Draws a rectangle with rounded corners centered at a point.
int32_t gm_draw_circle (double center_x, double center_y, double radius, gmColor c)
 Draws a circle.
int32_t gm_draw_ellipse (double x, double y, double w, double h, gmColor c)
 Draws an ellipse centered at a point.
int32_t gm_draw_triangle (double x1, double y1, double x2, double y2, double x3, double y3, gmColor c)
 Draws a triangle.
int32_t gm_draw_image (gmImage img, double x, double y, double w, double h)
 Draws an image centered at a point.
int32_t gm_draw_text (double x, double y, const char *text, const char *font, double font_size, gmColor c)
 Draws text centered at a point.
void gm_draw_body (const gmBody *body, gmColor c)
 Draws a physics body based on its collider type.
void gm_draw_rect_body (const gmBody *body, gmColor c)
 Draws a rectangular physics body.
void gm_draw_rect_bodies (const gmBody *bodies, size_t number, gmColor c)
 Draws an array of rectangular physics bodies.
void gm_draw_round_rect_body (const gmBody *body, double radius, gmColor c)
 Draws a rectangular physics body with rounded corners.
void gm_draw_circle_body (const gmBody *body, gmColor c)
 Draws a circular physics body.
void gm_draw_circle_bodies (const gmBody *bodies, size_t number, gmColor c)
 Draws an array of circular physics bodies.
void gm_draw_ellipse_body (const gmBody *body, gmColor c)
 Draws an elliptical physics body.
void gm_draw_ellipse_bodies (const gmBody *bodies, size_t number, gmColor c)
 Draws an array of elliptical physics bodies.
void gm_draw_triangle_body (const gmBody *body, double x2_offset, double y2_offset, double x3_offset, double y3_offset, gmColor c)
 Draws a triangular physics body.
void gm_draw_triangle_bodies (const gmBody *bodies, size_t number, double x2_offset, double y2_offset, double x3_offset, double y3_offset, gmColor c)
 Draws an array of triangular physics bodies.
void gm_draw_image_body (const gmBody *body, gmImage img)
 Draws an image at a physics body's position.
void gm_draw_image_bodies (const gmBody *bodies, size_t number, gmImage img)
 Draws the same image for an array of physics bodies.
void gm_draw_text_body (const gmBody *body, const char *text, const char *font, double font_size, gmColor c)
 Draws text at a physics body's position.
void gm_draw_text_bodies (const gmBody *bodies, size_t number, const char *text, const char *font, double font_size, gmColor c)
 Draws the same text for an array of physics bodies.

Detailed Description

Functions for drawing shapes, text, and images.

This file provides a set of functions for immediate-mode rendering of various primitives, as well as helper functions to draw physics bodies (gmBody). All coordinates are in world space.

Function Documentation

◆ gm_cache()

int gm_cache ( unsigned int id)

◆ gm_draw_body()

void gm_draw_body ( const gmBody * body,
gmColor c )

Draws a physics body based on its collider type.

This function checks the body's collider type and calls the appropriate drawing function (e.g., gm_draw_rectangle for GM_COLLIDER_RECT).

Parameters
bodyA pointer to the body to draw.
cThe color to draw the body.

◆ gm_draw_circle()

int32_t gm_draw_circle ( double center_x,
double center_y,
double radius,
gmColor c )

Draws a circle.

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.
cThe color of the circle.
Returns
An identifier for the drawing command.

◆ gm_draw_circle_bodies()

void gm_draw_circle_bodies ( const gmBody * bodies,
size_t number,
gmColor c )

Draws an array of circular physics bodies.

Parameters
bodiesA pointer to the array of bodies.
numberThe number of bodies in the array.
cThe color to draw the bodies.

◆ gm_draw_circle_body()

void gm_draw_circle_body ( const gmBody * body,
gmColor c )

Draws a circular physics body.

If the body is not a circle collider, it approximates the radius.

Parameters
bodyA pointer to the body to draw.
cThe color to draw the body.

◆ gm_draw_ellipse()

int32_t gm_draw_ellipse ( double x,
double y,
double w,
double h,
gmColor c )

Draws an ellipse centered at a point.

Parameters
xThe x-coordinate of the center of the ellipse.
yThe y-coordinate of the center of the ellipse.
wThe total width of the ellipse.
hThe total height of the ellipse.
cThe color of the ellipse.
Returns
An identifier for the drawing command.

◆ gm_draw_ellipse_bodies()

void gm_draw_ellipse_bodies ( const gmBody * bodies,
size_t number,
gmColor c )

Draws an array of elliptical physics bodies.

Parameters
bodiesA pointer to the array of bodies.
numberThe number of bodies in the array.
cThe color to draw the bodies.

◆ gm_draw_ellipse_body()

void gm_draw_ellipse_body ( const gmBody * body,
gmColor c )

Draws an elliptical physics body.

Parameters
bodyA pointer to the body to draw.
cThe color to draw the body.

◆ gm_draw_image()

int32_t gm_draw_image ( gmImage img,
double x,
double y,
double w,
double h )

Draws an image centered at a point.

Parameters
imgThe image to draw.
xThe x-coordinate of the center of the image.
yThe y-coordinate of the center of the image.
wThe width to draw the image.
hThe height to draw the image.
Returns
An identifier for the drawing command.

◆ gm_draw_image_bodies()

void gm_draw_image_bodies ( const gmBody * bodies,
size_t number,
gmImage img )

Draws the same image for an array of physics bodies.

Parameters
bodiesA pointer to the array of bodies.
numberThe number of bodies in the array.
imgThe image to draw.

◆ gm_draw_image_body()

void gm_draw_image_body ( const gmBody * body,
gmImage img )

Draws an image at a physics body's position.

Parameters
bodyA pointer to the body.
imgThe image to draw.

◆ gm_draw_line()

int32_t gm_draw_line ( double x1,
double y1,
double x2,
double y2,
double thickness,
gmColor c )

Draws a line segment.

Parameters
x1The x-coordinate of the starting point.
y1The y-coordinate of the starting point.
x2The x-coordinate of the ending point.
y2The y-coordinate of the ending point.
thicknessThe thickness of the line in pixels.
cThe color of the line.
Returns
An identifier for the drawing command.

◆ gm_draw_rect_bodies()

void gm_draw_rect_bodies ( const gmBody * bodies,
size_t number,
gmColor c )

Draws an array of rectangular physics bodies.

Parameters
bodiesA pointer to the array of bodies.
numberThe number of bodies in the array.
cThe color to draw the bodies.

◆ gm_draw_rect_body()

void gm_draw_rect_body ( const gmBody * body,
gmColor c )

Draws a rectangular physics body.

Parameters
bodyA pointer to the body to draw.
cThe color to draw the body.

◆ gm_draw_rectangle()

int32_t gm_draw_rectangle ( double x,
double y,
double w,
double h,
gmColor c )

Draws a rectangle centered at a point.

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.
cThe color of the rectangle.
Returns
An identifier for the drawing command.
Examples
/home/engon/gama/gama/lib/gama/gama.h.

◆ gm_draw_round_rect_body()

void gm_draw_round_rect_body ( const gmBody * body,
double radius,
gmColor c )

Draws a rectangular physics body with rounded corners.

Parameters
bodyA pointer to the body to draw.
radiusThe corner radius.
cThe color to draw the body.

◆ gm_draw_rounded_rectangle()

int32_t gm_draw_rounded_rectangle ( double x,
double y,
double w,
double h,
double r,
gmColor c )

Draws a rectangle with rounded corners centered at a point.

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.
cThe color of the rectangle.
Returns
An identifier for the drawing command.

◆ gm_draw_text()

int32_t gm_draw_text ( double x,
double y,
const char * text,
const char * font,
double font_size,
gmColor c )

Draws text centered at a point.

Parameters
xThe x-coordinate for the center of the text.
yThe y-coordinate for the center of the text.
textThe null-terminated string to draw.
fontThe null-terminated font name to use (can be empty for default).
font_sizeThe size of the font.
cThe color of the text.
Returns
An identifier for the drawing command.
Examples
/home/engon/gama/gama/lib/gama/gama.h.

◆ gm_draw_text_bodies()

void gm_draw_text_bodies ( const gmBody * bodies,
size_t number,
const char * text,
const char * font,
double font_size,
gmColor c )

Draws the same text for an array of physics bodies.

Parameters
bodiesA pointer to the array of bodies.
numberThe number of bodies in the array.
textThe null-terminated string to draw.
font_sizeThe size of the font.
cThe color of the text.

◆ gm_draw_text_body()

void gm_draw_text_body ( const gmBody * body,
const char * text,
const char * font,
double font_size,
gmColor c )

Draws text at a physics body's position.

Parameters
bodyA pointer to the body.
textThe null-terminated string to draw.
font_sizeThe size of the font.
cThe color of the text.

◆ gm_draw_triangle()

int32_t gm_draw_triangle ( double x1,
double y1,
double x2,
double y2,
double x3,
double y3,
gmColor c )

Draws a triangle.

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.
cThe color of the triangle.
Returns
An identifier for the drawing command.

◆ gm_draw_triangle_bodies()

void gm_draw_triangle_bodies ( const gmBody * bodies,
size_t number,
double x2_offset,
double y2_offset,
double x3_offset,
double y3_offset,
gmColor c )

Draws an array of triangular physics bodies.

Parameters
bodiesA pointer to the array of bodies.
numberThe number of bodies in the array.
x2_offsetThe x-offset of the second vertex for all triangles.
y2_offsetThe y-offset of the second vertex for all triangles.
x3_offsetThe x-offset of the third vertex for all triangles.
y3_offsetThe y-offset of the third vertex for all triangles.
cThe color to draw the bodies.

◆ gm_draw_triangle_body()

void gm_draw_triangle_body ( const gmBody * body,
double x2_offset,
double y2_offset,
double x3_offset,
double y3_offset,
gmColor c )

Draws a triangular physics body.

The body's position is the first vertex. The other two vertices are specified as offsets from the first.

Parameters
bodyA pointer to the body to draw.
x2_offsetThe x-offset of the second vertex.
y2_offsetThe y-offset of the second vertex.
x3_offsetThe x-offset of the third vertex.
y3_offsetThe y-offset of the third vertex.
cThe color to draw the body.