LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
lg_gr_func.c File Reference

Functions

void lg_draw_line (int32_t x1, int32_t y1, int32_t x2, int32_t y2, LG_Color_u c)
 
void lg_draw_rect (Rec2Di r, LG_Color_u c)
 
void lg_fill_rect (Rec2Di r, LG_Color_u c)
 
void lg_clear_rect (Rec2Di r, LG_Color_u c)
 
zboolean lg_clip_rect (Rec2Di clip, Rec2Di rect, Rec2Di *clipped_rect)
 
zboolean lg_recs_overlap (Rec2Df *r1, Rec2Df *r2)
 
void lg_copy_rect (Rec2Di src, Rec2Di *dest)
 
void lg_rec_i_copy (Rec2Di *dest, Rec2Di src)
 
void lg_rec_f_copy (Rec2Df *dest, Rec2Df src)
 
Rec2Di lg_rec_i (int x, int y, int w, int h)
 
Rec2Df lg_rec_f (float x, float y, float w, float h)
 
Rec2Df lg_rec_f_from_rec_i (Rec2Di r)
 
Rec2Di lg_rec_i_from_rec_f (Rec2Df r)
 
Point2Di lg_point2d_i (int32_t x, int32_t y)
 
Point2Df lg_point2d_f (float x, float y)
 
Point2Di lg_rec_i_center (Rec2Di r)
 
Point2Df lg_rec_f_center (Rec2Df r)
 
int32_t sdl_to_gl_int_x (int32_t x)
 
int32_t sdl_to_gl_int_y (int32_t y)
 
float sdl_to_gl_float_x (int32_t x)
 
float sdl_to_gl_float_y (int32_t y)
 
LG_Color_u lg_color_u_from_sdl_color (SDL_Color c)
 
SDL_Color lg_sdl_color_from_lg_color_u (LG_Color_u c)
 
SDL_Color * lg_set_sdl_color_from_str (SDL_Color *c, const char *str)
 
SDL_Color lg_get_sdl_color_from_str (const char *str)
 
LG_Color_ulg_set_lg_color_u_from_str (LG_Color_u *c, const char *str)
 
LG_Color_u lg_get_lg_color_u_from_str (const char *str)
 
int lg_get_n_color_str ()
 
const char * lg_get_color_str_from_color_index (int i)
 
void v_flip_sdl_surf (SDL_Surface *surf)
 

Detailed Description

 === A few 2D structs and graphical funcs ===

 Quite messy, also a lot of convenience conversion funcs

Function Documentation

◆ lg_draw_line()

void lg_draw_line ( int32_t  x1,
int32_t  y1,
int32_t  x2,
int32_t  y2,
LG_Color_u  c 
)

Draw a line from (x1, y1) to (x2, y2)

Expect SDL coord sys (logical coords, ie inside [0 -> env->top_win_logical_w] x [0 -> env->top_win_logical_h])

Parameters
x1Origin x coord
y1Origin y coord
x2Dest x coord
y2Dest y coord
cA LG_Color_u

◆ lg_draw_rect()

void lg_draw_rect ( Rec2Di  r,
LG_Color_u  c 
)

Draw a rectangle

Expect SDL coord sys (logical coords, ie inside [0 -> env->top_win_logical_w] x [0 -> env->top_win_logical_h])

Parameters
rA Rec2Di
cA LG_Color_u

◆ lg_fill_rect()

void lg_fill_rect ( Rec2Di  r,
LG_Color_u  c 
)

Fill a rectangle with color - now just call lg_render_rect_2d()

Expect SDL coord sys (logical coords, ie inside [0 -> env->top_win_logical_w] x [0 -> env->top_win_logical_h])

lg_fill_rect() is about three times faster than lg_clear_rect()

 In test/test.c: test_lg_draw_fill_rect()):
 - Time to draw with lg_clear_rect() = 6.582 ms
 - Time to draw with lg_fill_rect() = 1.925 ms
Parameters
rA Rec2Di
cA LG_Color_u

◆ lg_clear_rect()

void lg_clear_rect ( Rec2Di  r,
LG_Color_u  c 
)

Clear a rectangle with color

Expect SDL coord sys (logical coords, ie inside [0 -> env->top_win_logical_w] x [0 -> env->top_win_logical_h])

lg_clear_rect() is about three times slower than lg_fill_rect() (see above)

Parameters
rA Rec2Di
cA LG_Color_u

◆ lg_clip_rect()

zboolean lg_clip_rect ( Rec2Di  clip,
Rec2Di  rect,
Rec2Di clipped_rect 
)

Return FALSE if rect is fully outside clip. Otherwise, set clipped_rect (rect is unchanged) and return TRUE.

◆ lg_recs_overlap()

zboolean lg_recs_overlap ( Rec2Df r1,
Rec2Df r2 
)

Test if 2 rects (Rec2Df) overlap

Using Rec2Df with OpenGL coord sys orientation

typedef struct {
float x;
float y;
float w;
float h;
^
|
x,y+h |--------
| |
| |
------------->
x,y x+w,y
Parameters
r1Pointer to a Rec2Df
r2Pointer to a Rec2Df
Returns
TRUE if the rects overlap, FALSE otherwise

◆ lg_copy_rect()

void lg_copy_rect ( Rec2Di  src,
Rec2Di dest 
)

TODO: should be lg_copy_rect(dest, src) for consistency sake

DEPRECATED anyways

Parameters
src
dest

◆ lg_rec_i_copy()

void lg_rec_i_copy ( Rec2Di dest,
Rec2Di  src 
)

Copy src Rec2Di to dest Rec2Di

Parameters
destA pointer to a Rec2Di
srcA Rec2Di

◆ lg_rec_f_copy()

void lg_rec_f_copy ( Rec2Df dest,
Rec2Df  src 
)

Copy src Rec2Df to dest Rec2Df

Parameters
destA pointer to a Rec2Df
srcA Rec2Df

◆ lg_rec_i()

Rec2Di lg_rec_i ( int  x,
int  y,
int  w,
int  h 
)

Set a Rec2Di

Parameters
x
y
w
h
Returns
A Rec2Di

◆ lg_rec_f()

Rec2Df lg_rec_f ( float  x,
float  y,
float  w,
float  h 
)

Set a Rec2Df

Parameters
x
y
w
h
Returns
A Rec2Df

◆ lg_rec_f_from_rec_i()

Rec2Df lg_rec_f_from_rec_i ( Rec2Di  r)

Get Rec2Df from Rec2Di

Parameters
rA Rec2Di
Returns
A Rec2Df

◆ lg_rec_i_from_rec_f()

Rec2Di lg_rec_i_from_rec_f ( Rec2Df  r)

Get Rec2Di from Rec2Df

This func uses roundf()

Parameters
rA Rec2Df
Returns
A Rec2Di

◆ lg_point2d_i()

Point2Di lg_point2d_i ( int32_t  x,
int32_t  y 
)

Create a Point2Di

Parameters
x
y
Returns
A new Point2Di

◆ lg_point2d_f()

Point2Df lg_point2d_f ( float  x,
float  y 
)

Create a Point2Df

Parameters
x
y
Returns
A new Point2Df

◆ lg_rec_i_center()

Point2Di lg_rec_i_center ( Rec2Di  r)

Compute center of rectangle

This func uses roundf()

Parameters
rA Rec2Di
Returns
The center as a Rec2Di

◆ lg_rec_f_center()

Point2Df lg_rec_f_center ( Rec2Df  r)

Compute center of rectangle

Parameters
rA Rec2Df
Returns
The center as a Point2Df

◆ sdl_to_gl_int_x()

int32_t sdl_to_gl_int_x ( int32_t  x)

Convert from SDL coords to OpenGL coords

Parameters
x
Returns
New value as an int

◆ sdl_to_gl_int_y()

int32_t sdl_to_gl_int_y ( int32_t  y)

Convert from SDL coords to OpenGL coords

Parameters
y
Returns
New value as an int

◆ sdl_to_gl_float_x()

float sdl_to_gl_float_x ( int32_t  x)

Convert from SDL coords to OpenGL coords

About the 0.375 value, see: https://www.opengl.org/archives/resources/faq/technical/transformations.htm

Parameters
x
Returns
New value as a float

◆ sdl_to_gl_float_y()

float sdl_to_gl_float_y ( int32_t  y)

Convert from SDL coords to OpenGL coords

About the 0.375 value, see: https://www.opengl.org/archives/resources/faq/technical/transformations.htm

Parameters
y
Returns
New value as a float

◆ lg_color_u_from_sdl_color()

LG_Color_u lg_color_u_from_sdl_color ( SDL_Color  c)

Get LG_Color_u from SDL_Color

Parameters
cA SDL_Color
Returns
A LG_Color_u

◆ lg_sdl_color_from_lg_color_u()

SDL_Color lg_sdl_color_from_lg_color_u ( LG_Color_u  c)

Get SDL_Color from LG_Color_u

Parameters
cLG_Color_u
Returns
A SDL_Color

◆ lg_set_sdl_color_from_str()

SDL_Color* lg_set_sdl_color_from_str ( SDL_Color *  c,
const char *  str 
)

Bla bla (self-explanatory)

◆ lg_get_sdl_color_from_str()

SDL_Color lg_get_sdl_color_from_str ( const char *  str)

Bla bla (self-explanatory)

◆ lg_set_lg_color_u_from_str()

LG_Color_u* lg_set_lg_color_u_from_str ( LG_Color_u c,
const char *  str 
)

Bla bla (self-explanatory)

◆ lg_get_lg_color_u_from_str()

LG_Color_u lg_get_lg_color_u_from_str ( const char *  str)

Bla bla (self-explanatory)

◆ lg_get_n_color_str()

int lg_get_n_color_str ( )

Bla bla (self-explanatory)

◆ lg_get_color_str_from_color_index()

const char* lg_get_color_str_from_color_index ( int  i)

Bla bla (self-explanatory)

◆ v_flip_sdl_surf()

void v_flip_sdl_surf ( SDL_Surface *  surf)

Flip (vertical one) SDL surf

TODO: fix the compilation warning

(From gcc doc) === gcc option -Wpointer-arith ===

Warn about anything that depends on the “size of” a function type or of void. GNU C assigns these types a size of 1, for convenience in calculations with void * pointers and pointers to functions.

(WTF ?)

Rec2Df
Definition: lg_gr_func.h:54