LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
lg_gr_func.h
1 /*
2  * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2025
3  * All rights reserved
4  */
5 
6 #ifndef LG_GR_FUNC_H
7 #define LG_GR_FUNC_H
8 
9 /*
10  * === A few 2D structs and graphical funcs ===
11  *
12  * Plus colors funcs
13  */
14 
15 typedef struct {
16  int32_t x;
17  int32_t y;
18 } Point2Di;
19 
20 typedef struct {
21  float x;
22  float y;
23 } Point2Df;
24 
25 typedef struct {
26  int32_t x1;
27  int32_t y1;
28  int32_t x2;
29  int32_t y2;
30 } Line2Di;
31 
32 typedef struct {
33  float x1;
34  float y1;
35  float x2;
36  float y2;
37 } Line2Df;
38 
39 /*
40  * Rec = rectangle (floats) with OpenGL coords sys orientation
41  * ^
42  * |
43  * x,y+h |--------
44  * | |
45  * | |
46  * ------------->
47  * x,y x+w,y
48  */
49 typedef struct {
50  int32_t x;
51  int32_t y;
52  int32_t w;
53  int32_t h;
54 } Rec2Di;
55 
56 typedef struct {
57  float x;
58  float y;
59  float w;
60  float h;
61 } Rec2Df;
62 
63 void lg_draw_line(int32_t, int32_t, int32_t, int32_t, LG_Color_u);
64 
66 
67 void lg_fill_rect(Rec2Di r, LG_Color_u c);
68 
70 
71 zboolean lg_clip_rect(Rec2Di, Rec2Di, Rec2Di *);
72 
73 zboolean lg_recs_overlap(Rec2Df *, Rec2Df *);
74 
75 void lg_copy_rect(Rec2Di, Rec2Di *);
76 
77 void lg_rec_i_copy(Rec2Di *, Rec2Di);
78 
79 void lg_rec_f_copy(Rec2Df *, Rec2Df);
80 
81 Rec2Di lg_rec_i(int, int, int, int);
82 
83 Rec2Df lg_rec_f(float, float, float, float);
84 
86 
88 
89 Point2Di lg_point2d_i(int32_t, int32_t);
90 
91 Point2Df lg_point2d_f(float, float);
92 
94 
96 
97 int32_t sdl_to_gl_int_x(int32_t);
98 
99 int32_t sdl_to_gl_int_y(int32_t);
100 
101 float sdl_to_gl_float_x(int32_t);
102 
103 float sdl_to_gl_float_y(int32_t);
104 
106 
108 
109 SDL_Color *lg_set_sdl_color_from_str(SDL_Color *, const char *);
110 
111 SDL_Color lg_get_sdl_color_from_str(const char *);
112 
114 
116 
117 int lg_get_n_color_str();
118 
120 
121 void v_flip_sdl_surf(SDL_Surface *);
122 
123 #endif /* LG_GR_FUNC_H */
sdl_to_gl_int_x
int32_t sdl_to_gl_int_x(int32_t x)
Definition: lg_gr_func.c:399
lg_point2d_f
Point2Df lg_point2d_f(float x, float y)
Definition: lg_gr_func.c:364
lg_rec_f_center
Point2Df lg_rec_f_center(Rec2Df r)
Definition: lg_gr_func.c:388
Rec2Df
Definition: lg_gr_func.h:56
Point2Df
Definition: lg_gr_func.h:20
sdl_to_gl_int_y
int32_t sdl_to_gl_int_y(int32_t y)
Definition: lg_gr_func.c:410
lg_rec_f_copy
void lg_rec_f_copy(Rec2Df *dest, Rec2Df src)
Definition: lg_gr_func.c:264
lg_get_lg_color_u_from_str
LG_Color_u lg_get_lg_color_u_from_str(const char *str)
Definition: lg_gr_func.c:538
lg_sdl_color_from_lg_color_u
SDL_Color lg_sdl_color_from_lg_color_u(LG_Color_u c)
Definition: lg_gr_func.c:487
Point2Di
Definition: lg_gr_func.h:15
lg_point2d_i
Point2Di lg_point2d_i(int32_t x, int32_t y)
Definition: lg_gr_func.c:352
lg_get_sdl_color_from_str
SDL_Color lg_get_sdl_color_from_str(const char *str)
Definition: lg_gr_func.c:518
Line2Df
Definition: lg_gr_func.h:32
lg_recs_overlap
zboolean lg_recs_overlap(Rec2Df *r1, Rec2Df *r2)
Definition: lg_gr_func.c:219
lg_get_color_str_from_color_index
const char * lg_get_color_str_from_color_index(int i)
Definition: lg_gr_func.c:558
lg_clear_rect
void lg_clear_rect(Rec2Di r, LG_Color_u c)
Definition: lg_gr_func.c:116
lg_draw_rect
void lg_draw_rect(Rec2Di r, LG_Color_u c)
Definition: lg_gr_func.c:46
lg_rec_i_from_rec_f
Rec2Di lg_rec_i_from_rec_f(Rec2Df r)
Definition: lg_gr_func.c:333
lg_set_lg_color_u_from_str
LG_Color_u * lg_set_lg_color_u_from_str(LG_Color_u *c, const char *str)
Definition: lg_gr_func.c:529
lg_rec_i
Rec2Di lg_rec_i(int x, int y, int w, int h)
Definition: lg_gr_func.c:281
lg_color_u_from_sdl_color
LG_Color_u lg_color_u_from_sdl_color(SDL_Color c)
Definition: lg_gr_func.c:476
lg_fill_rect
void lg_fill_rect(Rec2Di r, LG_Color_u c)
Definition: lg_gr_func.c:89
lg_rec_i_center
Point2Di lg_rec_i_center(Rec2Di r)
Definition: lg_gr_func.c:377
lg_draw_line
void lg_draw_line(int32_t x1, int32_t y1, int32_t x2, int32_t y2, LG_Color_u c)
Definition: lg_gr_func.c:30
lg_rec_f
Rec2Df lg_rec_f(float x, float y, float w, float h)
Definition: lg_gr_func.c:302
LG_Color_u
Definition: lg_vertex.h:111
Line2Di
Definition: lg_gr_func.h:25
sdl_to_gl_float_y
float sdl_to_gl_float_y(int32_t y)
Definition: lg_gr_func.c:439
sdl_to_gl_float_x
float sdl_to_gl_float_x(int32_t x)
Definition: lg_gr_func.c:425
v_flip_sdl_surf
void v_flip_sdl_surf(SDL_Surface *surf)
Definition: lg_gr_func.c:581
lg_copy_rect
void lg_copy_rect(Rec2Di src, Rec2Di *dest)
Definition: lg_gr_func.c:236
lg_rec_f_from_rec_i
Rec2Df lg_rec_f_from_rec_i(Rec2Di r)
Definition: lg_gr_func.c:320
lg_clip_rect
zboolean lg_clip_rect(Rec2Di clip, Rec2Di rect, Rec2Di *clipped_rect)
Definition: lg_gr_func.c:163
lg_rec_i_copy
void lg_rec_i_copy(Rec2Di *dest, Rec2Di src)
Definition: lg_gr_func.c:250
lg_set_sdl_color_from_str
SDL_Color * lg_set_sdl_color_from_str(SDL_Color *c, const char *str)
Definition: lg_gr_func.c:495
Rec2Di
Definition: lg_gr_func.h:49
lg_get_n_color_str
int lg_get_n_color_str()
Definition: lg_gr_func.c:547