![]() |
LibGame
v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
|
=== A few 2D structs and graphical funcsPlus colors funcs === Plus colors funcs Quite messy, also a lot of convenience conversion funcs
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 coords sys (logical coords, ie inside [0 -> env->top_win_logical_w] x [0 -> env->top_win_logical_h])
x1 | Origin x coord |
y1 | Origin y coord |
x2 | Dest x coord |
y2 | Dest y coord |
c | A LG_Color_u |
void lg_draw_rect | ( | Rec2Di | r, |
LG_Color_u | c | ||
) |
Draw a rectangle
Expect SDL coords sys (logical coords, ie inside [0 -> env->top_win_logical_w] x [0 -> env->top_win_logical_h])
r | A Rec2Di |
c | A LG_Color_u |
void lg_fill_rect | ( | Rec2Di | r, |
LG_Color_u | c | ||
) |
Fill a rectangle with color - now just call lg_render_rect_2d()
Expect SDL coords 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
r | A Rec2Di |
c | A LG_Color_u |
void lg_clear_rect | ( | Rec2Di | r, |
LG_Color_u | c | ||
) |
Clear a rectangle with color
Expect SDL coords 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)
r | A Rec2Di |
c | A LG_Color_u |
Return FALSE if rect is fully outside clip. Otherwise, set clipped_rect (rect is unchanged) and return TRUE.
TODO: should be lg_copy_rect(dest, src) for consistency sake
DEPRECATED anyways
src | |
dest |
Rec2Df lg_rec_f | ( | float | x, |
float | y, | ||
float | w, | ||
float | h | ||
) |
Point2Di lg_point2d_i | ( | int32_t | x, |
int32_t | y | ||
) |
void gl_coords_from_screen_coords | ( | float * | x2, |
float * | y2, | ||
int | x1, | ||
int | y1, | ||
int | viewport_w, | ||
int | viewport_h | ||
) |
Get GL coords (more exactly NDC) in range [-1, 1] x [-1, 1] with origin at center from some screen coords in range [0, some screen width] x [0, some screen height] with origin at top left corner
On Linux, useful to get mouse pointer NDC coords for ray picking or whatever
x2 | (GL coord) |
y2 | (GL coord) |
x1 | (Screen coord) |
y1 | (Screen coord) |
viewport_w | Usually env->viewport_rect.w |
viewport_h | Usually env->viewport_rect.h |
void logical_coords_from_viewport_coords | ( | int * | x2, |
int * | y2, | ||
int | x1, | ||
int | y1 | ||
) |
Get logical coords in range [0, env->top_win_logical_w] x [0, env->top_win_logical_h] from viewport coords in range [0, env->viewport_rect.w] x [0, env->viewport_rect.h] from current LG_Env
On Linux, useful to get 'logical' mouse pointer coords (you may need to use logical_coords_from_viewport_coords_btaskbar_adjustment() to get accurate results)
x2 | (Logical coord) |
y2 | (Logical coord) |
x1 | (Viewport coord) |
y1 | (Viewport coord) |
void logical_coords_from_viewport_coords_btaskbar_adjustment | ( | int | bth_adj | ) |
Set (static int) bottom_taskbar_height_adjustment to correct logical_coords_from_viewport_coords() y2 inaccuracy
Linux only - should find how to get bottom taskbar height
bth_adj | Bottom taskbar height adjustment |
void logical_coords_from_touchscreen_coords | ( | int * | x2, |
int * | y2, | ||
float | x1, | ||
float | y1 | ||
) |
Get logical coords in range [0, env->top_win_logical_w] x [0, env->top_win_logical_h] from touchscreen coords in range [0.0, 1.0] x [0.0, 1.0]
Useful to get 'logical' touch coords on Android
x2 | (Logical coord) |
y2 | (Logical coord) |
x1 | (Viewport coord) |
y1 | (Viewport coord) |
void lg_set_touchscreen_coords_margins | ( | float | left, |
float | top | ||
) |
Used by logical_coords_from_touchscreen_coords() to adjust stuff
Use this func only if you know what you're doing
left | Left margin value |
top | Top margin value |
int32_t sdl_to_gl_int_x | ( | int32_t | x | ) |
Convert from SDL coords to OpenGL coords
x |
int32_t sdl_to_gl_int_y | ( | int32_t | y | ) |
Convert from SDL coords to OpenGL coords
y |
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
x |
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
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 | ||
) |
Bla bla (self-explanatory)
SDL_Color lg_get_sdl_color_from_str | ( | const char * | str | ) |
Bla bla (self-explanatory)
LG_Color_u* lg_set_lg_color_u_from_str | ( | LG_Color_u * | c, |
const char * | str | ||
) |
Bla bla (self-explanatory)
LG_Color_u lg_get_lg_color_u_from_str | ( | const char * | str | ) |
Bla bla (self-explanatory)
int lg_get_n_color_str | ( | ) |
Bla bla (self-explanatory)
const char* lg_get_color_str_from_color_index | ( | int | i | ) |
Bla bla (self-explanatory)
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 ?)