LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
libgame.h
1 /*
2  * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2025
3  * All rights reserved
4  *
5  * LibGame is a SDL2/OpenGL ES 3.1 2D/3D minimalist game engine, which doesn't
6  * attempt to do *everything* but does only certain things and does them *well*,
7  * while not preventing you from doing other things (huh ?)
8  *
9  * This version supports both Linux Desktop and Android (with NDK).
10  */
11 
12 #ifndef LIBGAME_H
13 #define LIBGAME_H
14 
15 #ifndef _GNU_SOURCE
16  #define _GNU_SOURCE
17 #endif
18 #ifndef _ISOC11_SOURCE
19  #define _ISOC11_SOURCE
20 #endif
21 
22 #define LIBGAME_NAME "LibGame"
23 #define LIBGAME_V_NUM "0.4.0~beta-20250619"
24 #define LIBGAME_COPYRIGHT_STR "Copyright (C) Emmanuel Thomas-Maurin 2012-2025 - All rights reserved"
25 
26 #define LIBGAME_WEBSITE "https://www.etmsoftware.com" /*"https://www.aetm-games.com"*/
27 #define LIBGAME_DOWNLOAD_WEBSITE LIBGAME_WEBSITE "/download.php"
28 #define LIBGAME_SUPPORT_WEBSITE LIBGAME_WEBSITE "/help.php"
29 #define LIBGAME_SUPPORT_EMAIL "[email protected]" /*"[email protected]"*/
30 
31 #if !defined(ANDROID_V) && !defined(WIN32_V)
32  #define LINUX_V
33 #endif
34 
35 #include <stdlib.h>
36 #include <string.h>
37 #include <stdio.h>
38 #include <stdint.h>
39 #include <math.h>
40 #include <errno.h>
41 #include <time.h>
42 #include <unistd.h>
43 #include <sys/stat.h>
44 #include <sys/time.h>
45 #include <byteswap.h>
46 #include <stdalign.h>
47 #ifndef WIN32_V /* Linux and Android versions */
48  #include <grp.h>
49  #include <pwd.h>
50  #include <signal.h>
51 #else
52  #include <direct.h>
53 #endif
54 
55 #ifdef ANDROID_V
56  #include <jni.h>
57  #include <android/log.h>
58 #endif
59 
60 #ifndef WIN32_V /* Linux and Android versions */
61  #include <SDL.h>
62  #include <SDL_image.h>
63  #include <SDL_mixer.h>
64  #include <SDL_ttf.h>
65  #include <SDL_syswm.h>
66  #ifdef LINUX_V
67  #include <SDL_mouse.h>
68  #endif
69 #else /* Not tested */
70  #include <SDL.h>
71  #include <SDL2/SDL_image.h>
72  #include <SDL2/SDL_mixer.h>
73  #include <SDL2/SDL_ttf.h>
74  #include <SDL_mouse.h>
75  #include <SDL_syswm.h>
76 #endif
77 
78 #include <GLES2/gl2.h>
79 #include <GLES2/gl2ext.h>
80 #include <GLES3/gl3.h>
81 #include <GLES3/gl3ext.h>
82 
83 /* === For LibGame, use VERBOSE_OUTPUT and DEBUG_OUTPUT, *not* these token below === */
84 
85 /* Logging stuff for libetm - must appear before #include libetm.h */
86 #define LIBETM_VERBOSE_OUTPUT
87 /*#define LIBETM_DEBUG_OUTPUT*/
88 
89 /* LIBETM_DEBUG_OUTPUT implies LIBETM_VERBOSE_OUTPUT */
90 #ifdef LIBETM_DEBUG_OUTPUT
91  #ifndef LIBETM_VERBOSE_OUTPUT
92  #define LIBETM_VERBOSE_OUTPUT
93  #endif
94 #endif
95 
96 #ifdef ANDROID_V
97  #include "../extra_libs/libetm-0.5.1/libetm.h"
98 #else
99  #ifndef WIN32_V /* Linux version */
100  #include <libetm/libetm.h>
101  #else
102  #include "../extra_libs/libetm-0.5.1/libetm.h"
103  #endif
104 #endif
105 
106 #ifndef ANDROID_V
107  #undef INFO_ERR
108  #define INFO_ERR INFO_ERR2
109 #endif
110 
111 /* === Now, the LibGame verbose and debug tokens are just below === */
112 
113 #define VERBOSE_OUTPUT
114 //#define DEBUG_OUTPUT
115 
116 #ifdef DEBUG_OUTPUT
117  #ifndef VERBOSE_OUTPUT
118  #define VERBOSE_OUTPUT
119  #endif
120 #endif
121 
122 #define TMPSTR_SIZE ((4 * 1024) - 1) /* = 4 KiB - 1 */
123 #define FILE_NAME_MAXLEN ((2 * 1024) - 1) /* = 2 KiB - 1 */
124 
125 #ifdef LIBGAME_COMPILE_TIME
126  #include "../extra_libs/math_3d.h"
127  #include "../extra_libs/stb_image.h"
128  #include "../extra_libs/ufbx.h"
129 #else
130  #include <libgame/extra_libs/math_3d.h>
131  #include <libgame/extra_libs/stb_image.h>
132  #include <libgame/extra_libs/ufbx.h>
133 #endif
134 
135 /* Which order for header files ? */
136 
137 #include "lg_vbo.h"
138 #include "lg_shader_progs.h"
139 #include "lg_vertex.h"
140 #include "lg_gr_func.h"
141 #include "lg_textures.h"
142 #include "lg_dds_loader.h"
143 #include "lg_astc_loader.h"
144 #include "lg_string.h"
145 #include "lg_sprites.h"
146 #include "lg_background.h"
147 #include "lg_wins.h"
148 #include "lg_keyboard.h"
149 #include "lg_mouse.h"
150 #include "lg_touchscreen.h"
151 #include "lg_audio.h"
152 #include "lg_dirs_stuff.h"
153 #include "lg_quaternions.h"
154 #include "lg_misc.h"
155 #include "lg_ui.h"
156 #include "lg_3d_primitives.h"
157 #include "lg_opengl_2d.h"
158 #include "lg_mesh.h"
159 #include "lg_camera.h"
160 #include "lg_obj_parser.h"
161 #include "lg_light.h"
162 #include "lg_scene_graph.h"
163 #include "lg_scene.h"
164 #include "lg_collision_detect.h"
165 #include "lg_admob.h"
166 #include "lg_vao_gl_ext.h"
167 #include "lg_cubemap.h"
168 #include "lg_error.h"
169 #include "lg_file_ops.h"
170 #include "lg_android_assets.h"
171 #include "lg_render.h"
172 #include "lg_terrain.h"
173 #include "lg_perlin_noise.h"
174 #include "lg_landscape.h"
175 #include "lg_fbx_parser.h"
176 #include "lg_cam_controls.h"
177 #include "lg_part_sys.h"
178 /* OK ? */
179 #include "lg_env.h"
180 #include "lg_env_instance.h"
181 #include "lg_math_extra.h"
182 
183 typedef enum {
184  LG_OK = LIBETM_LASTERRORCODE + 1,
185  LG_ERROR,
186  LG_INIT_ERROR,
187  LG_EXTRA_LIB_INIT_ERROR,
188  LG_OPENGL_ERROR,
189  LG_GLSL_ERROR,
190  LG_CREATE_FILE_ERROR,
191  LG_OPEN_FILE_ERROR,
192  LG_SAVE_FILE_ERROR,
193  LG_READ_FROM_FILE_ERROR,
194  LG_WRITE_TO_FILE_ERROR,
195  LG_FILE_ACCESS_ERROR,
196  LG_READ_FROM_FILE_EOF,
197  LG_EOF,
198  LG_OOM,
199  LG_INVALID_PTR,
200  /* Unix signals */
201  LG_BUSERR, /* SIGBUS Bus error (bad memory access) */
202  LG_FPE, /* SIGFPE Floating-point exception */
203  LG_ILL, /* SIGILL Illegal Instruction */
204  LG_SEGFAULT, /* SIGSEGV Invalid memory reference */
205  /* Must really be the last one */
206  LG_LASTERRORCODE
207 } lg_error_code;
208 
209 typedef enum {
210  LG_CONTINUE = LG_LASTERRORCODE + 1,
211  LG_CANCEL,
212  LG_QUIT,
213  LG_WON,
214  LG_LOST,
215  LG_LASTRETURNCODE
216 } lg_return_code;
217 
218 /*
219  * WIN_LOGICAL_W and WIN_LOGICAL_H must be defined in app
220  * 16/9 or (on new mobiles) 18/9 aspect ratio ?
221  * #define WIN_LOGICAL_W 1000
222  * #define WIN_LOGICAL_H 500
223  * On Android, we *always* want/use landscape orientation
224  */
225 #define LG_WIN_WIDTH_MIN 800
226 #define LG_WIN_HEIGHT_MIN 400
227 
228 #define LG_WIN_D_HEIGHT_HACK 2 /* DIRTY HACK: We want the whole win to be visible - actually, what was it about ? */
229 
230 /* Requested bit-depth */
231 #define LG_REQUESTED_RED_SIZE 5
232 #define LG_REQUESTED_GREEN_SIZE 6
233 #define LG_REQUESTED_BLUE_SIZE 5
234 #define LG_REQUESTED_ALPHA_SIZE 0
235 #define LG_REQUESTED_DEPTH_SIZE 16
236 #define LG_REQUESTED_STENCIL_SIZE 8
237 
238 int lg_init(int, int, const char *, const char *, const char *, const char *, const char *, const char *, const char *);
239 
241 
243 
244 void lg_reset_viewport();
245 
246 void lg_enable_mouse();
247 
248 void lg_disable_mouse();
249 
251 
252 zboolean lg_load_engine_fonts();
253 
254 void lg_engine_fonts_info();
255 
256 void lg_quit(int);
257 
258 void lg_swap_fb();
259 
260 void lg_show_lib_info();
261 
262 void lg_show_sys_info();
263 
264 void lg_show_extra_sys_info(SDL_Window *);
265 
266 zboolean sdl2_is_installed();
267 
268 /* Must be freed afterwards with l_str_free() */
269 char *lg_get_sdl_win_flags(SDL_Window *);
270 
271 #endif /* LIBGAME_H */
lg_engine_fonts_info
void lg_engine_fonts_info()
Definition: libgame.c:914
lg_reset_viewport
void lg_reset_viewport()
Definition: libgame.c:803
lg_show_sys_info
void lg_show_sys_info()
Definition: libgame.c:1039
lg_enable_mouse
void lg_enable_mouse()
Definition: libgame.c:812
lg_swap_fb
void lg_swap_fb()
Definition: libgame.c:1007
lg_get_default_viewport
Rec2Di lg_get_default_viewport()
Definition: libgame.c:785
lg_set_new_viewport
void lg_set_new_viewport(Rec2Di viewport)
Definition: libgame.c:795
lg_load_engine_fonts
zboolean lg_load_engine_fonts()
Definition: libgame.c:863
lg_show_extra_sys_info
void lg_show_extra_sys_info(SDL_Window *w)
Definition: libgame.c:1136
lg_get_sdl_win_flags
char * lg_get_sdl_win_flags(SDL_Window *w)
Definition: libgame.c:1217
lg_init
int lg_init(int win_w, int win_h, const char *win_title, const char *app_name, const char *app_cmd, const char *org_name_android, const char *app_name_android, const char *assets_folder, const char *app_wr_folder)
Definition: libgame.c:47
sdl2_is_installed
zboolean sdl2_is_installed()
Definition: libgame.c:1197
lg_quit
void lg_quit(int exit_code)
Definition: libgame.c:924
lg_list_opengl_extensions
void lg_list_opengl_extensions()
Definition: libgame.c:828
lg_disable_mouse
void lg_disable_mouse()
Definition: libgame.c:820
lg_show_lib_info
void lg_show_lib_info()
Definition: libgame.c:1015
Rec2Di
Definition: lg_gr_func.h:49