LibGame v0.4.0
The LG Game Engine - Copyright (C) 2024-2026 ETMSoftware
Loading...
Searching...
No Matches
libgame.h
1/*
2 * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2026
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-20260815"
24#define LIBGAME_COPYRIGHT_STR "Copyright (C) Emmanuel Thomas-Maurin 2012-2026 - 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#include <limits.h>
48#ifndef WIN32_V /* Linux and Android versions */
49 #include <grp.h>
50 #include <pwd.h>
51 #include <signal.h>
52 #include <sys/mman.h>
53#else
54 #include <direct.h>
55#endif
56
57#ifdef ANDROID_V
58 #include <jni.h>
59 #include <android/log.h>
60#endif
61
62#ifndef WIN32_V /* Linux and Android versions */
63 #include <SDL.h>
64 #include <SDL_image.h>
65 #include <SDL_mixer.h>
66 #include <SDL_ttf.h>
67 #include <SDL_syswm.h>
68 #ifdef LINUX_V
69 #include <SDL_mouse.h>
70 #endif
71#else /* Not tested */
72 #include <SDL.h>
73 #include <SDL2/SDL_image.h>
74 #include <SDL2/SDL_mixer.h>
75 #include <SDL2/SDL_ttf.h>
76 #include <SDL_mouse.h>
77 #include <SDL_syswm.h>
78#endif
79
80#include <GLES2/gl2.h>
81#include <GLES2/gl2ext.h>
82#include <GLES3/gl3.h>
83#include <GLES3/gl3ext.h>
84
85/* === For LibGame, use VERBOSE_OUTPUT and DEBUG_OUTPUT, *not* these token below === */
86
87/* Logging stuff for libetm - must appear before #include libetm.h */
88#define LIBETM_VERBOSE_OUTPUT
89/*#define LIBETM_DEBUG_OUTPUT*/
90
91/* LIBETM_DEBUG_OUTPUT implies LIBETM_VERBOSE_OUTPUT */
92#ifdef LIBETM_DEBUG_OUTPUT
93 #ifndef LIBETM_VERBOSE_OUTPUT
94 #define LIBETM_VERBOSE_OUTPUT
95 #endif
96#endif
97
98#ifdef ANDROID_V
99 #include "../extra_libs/libetm-0.6.0/libetm.h"
100#else
101 #ifndef WIN32_V /* Linux version */
102 #include <libetm/libetm.h>
103 #else
104 #include "../extra_libs/libetm-0.6.0/libetm.h"
105 #endif
106#endif
107
108#ifndef ANDROID_V
109 #undef INFO_ERR
110 #define INFO_ERR INFO_ERR2
111#endif
112
113/* === Now, the LibGame verbose and debug tokens are just below === */
114
115#define VERBOSE_OUTPUT
116//#define DEBUG_OUTPUT /* This is actually the real verbose output */
117
118#ifdef DEBUG_OUTPUT
119 #ifndef VERBOSE_OUTPUT
120 #define VERBOSE_OUTPUT
121 #endif
122#endif
123
124#ifdef DEBUG_OUTPUT
125 #define DEBUG_INFO_OUT(...) \
126 {\
127 fprintf(STD_OUT, FILE_LINE_FUNC_STR);\
128 INFO_OUT(__VA_ARGS__)\
129 }
130#else
131 #define DEBUG_INFO_OUT(...) \
132 {}
133#endif
134
135typedef enum {LG_NONE, LG_INFO, LG_VERBOSE, LG_DEBUG} env_logging_level;
136
137#define TMPSTR_SIZE ((4 * 1024) - 1) /* = 4 KiB - 1 */
138#define FILE_NAME_MAXLEN ((2 * 1024) - 1) /* = 2 KiB - 1 */
139
140/* Adding some space */
141#define EXTRA_NEWLINES
142#ifdef EXTRA_NEWLINES
143 #define __extra_newline__ INFO_OUT("\n")
144#else
145 #define __extra_newline__
146#endif
147
148#ifdef LIBGAME_COMPILE_TIME
149 #include "../extra_libs/math_3d.h"
150 #include "../extra_libs/stb_image.h"
151 #include "../extra_libs/ufbx.h"
152#else
153 #include <libgame/extra_libs/math_3d.h>
154 #include <libgame/extra_libs/stb_image.h>
155 #include <libgame/extra_libs/ufbx.h>
156#endif
157
158/* Which order for header files ? */
159
160#include "lg_vbo.h"
161#include "lg_shader_progs.h"
162#include "lg_vertex.h"
163#include "lg_vertex_info.h"
164#include "lg_gr_func.h"
165#include "lg_textures.h"
166#include "lg_dds_loader.h"
167#include "lg_astc_loader.h"
168#include "lg_string.h"
169#include "lg_sprites.h"
170#include "lg_background.h"
171#include "lg_fonts.h"
172#include "lg_wins.h"
173#include "lg_keyboard.h"
174#include "lg_mouse.h"
175#include "lg_touchscreen.h"
176#include "lg_audio.h"
177#include "lg_dirs_stuff.h"
178#include "lg_quaternions.h"
179#include "lg_misc.h"
180#include "lg_ui.h"
181#include "lg_3d_primitives.h"
182#include "lg_opengl_2d.h"
183#include "lg_mesh.h"
184#include "lg_camera.h"
185#include "lg_obj_parser.h"
186#include "lg_light.h"
187#include "lg_scene_graph.h"
188#include "lg_scene.h"
189#include "lg_collision_detect.h"
190#include "lg_admob.h"
191#include "lg_vao_gl_ext.h"
192#include "lg_cubemap.h"
193#include "lg_error.h"
194#include "lg_file_ops.h"
195#include "lg_android_assets.h"
196#include "lg_render.h"
197#include "lg_terrain.h"
198#include "lg_perlin_noise.h"
199#include "lg_landscape.h"
200#include "lg_fbx_parser.h"
201#include "lg_cam_controls.h"
202#include "lg_part_sys.h"
203#include "lg_goodies.h"
204#include "lg_arena.h"
205#include "lg_mesh_lines.h"
206#include "lg_mem.h"
207#include "lg_grid_geom_shader.h"
208
209/* OK ? */
210#include "lg_env.h"
211#include "lg_env_instance.h"
212#include "lg_math_extra.h"
213
217typedef enum {
218 LG_OK = LIBETM_LASTERRORCODE + 1,
219 LG_ERROR,
220 LG_INIT_ERROR,
221 LG_EXTRA_LIB_INIT_ERROR,
222 LG_OPENGL_ERROR,
223 LG_GLSL_ERROR,
224 LG_CREATE_FILE_ERROR,
225 LG_OPEN_FILE_ERROR,
226 LG_SAVE_FILE_ERROR,
227 LG_READ_FROM_FILE_ERROR,
228 LG_WRITE_TO_FILE_ERROR,
229 LG_FILE_ACCESS_ERROR,
230 LG_READ_FROM_FILE_EOF,
231 LG_EOF,
232 LG_SIZE_IS_ZERO,
233 LG_FREE_NULL,
234 LG_OOM,
235 LG_AOOM, /* LG_Arena out of reserved memory */
236 LG_SIG_START, /* For Unix signals, error code = LG_SIG_START + signal value */
237 LG_SIG_END = LG_SIG_START + 100, /* Must really be the last one */
238 LG_NODE_IS_NOT_A_LEAF,
239 LG_LASTERRORCODE
240} lg_error_code;
241
242typedef enum {
243 LG_CONTINUE = LG_LASTERRORCODE + 1,
244 LG_CANCEL,
245 LG_QUIT,
246 LG_WON,
247 LG_LOST,
248 LG_LASTRETURNCODE
249} lg_return_code;
250
251/* SDL2 vsync stuff */
252#define NEVER_VSYNC 0
253#define ALWAYS_VSYNC 1
254#define ADAPTIVE_VSYNC -1
255
256typedef struct {
257 int i;
258 const char *str;
259} Vsync;
260
261/*
262 * WIN_LOGICAL_W and WIN_LOGICAL_H must be defined in app
263 * 16/9 or (on new mobiles) 18/9 aspect ratio ?
264 * #define WIN_LOGICAL_W 1000
265 * #define WIN_LOGICAL_H 500
266 * On Android, we *always* want/use landscape orientation
267 */
268#define LG_WIN_WIDTH_MIN 800
269#define LG_WIN_HEIGHT_MIN 400
270
271#define LG_WIN_D_HEIGHT_HACK 2 /* DIRTY HACK: We want the whole win to be visible - actually, what was it about ? */
272
273/* Requested bit-depth */
274#define LG_REQUESTED_RED_SIZE 5
275#define LG_REQUESTED_GREEN_SIZE 6
276#define LG_REQUESTED_BLUE_SIZE 5
277#define LG_REQUESTED_ALPHA_SIZE 0
278#define LG_REQUESTED_DEPTH_SIZE 16
279#define LG_REQUESTED_STENCIL_SIZE 8
280
281int lg_init(int, int, const char *, const char *, const char *, const char *, const char *, const char *, const char *);
282
284
286
287void lg_reset_viewport();
288
289void lg_enable_mouse();
290
291void lg_disable_mouse();
292
294
295zboolean lg_load_engine_fonts();
296
298
299void lg_quit(int, zboolean);
300
301void lg_swap_fb();
302
303void lg_update_gl_win_title(const char *);
304
305void lg_show_lib_info();
306
307void lg_show_sys_info();
308
309void lg_show_extra_sys_info(SDL_Window *);
310
311zboolean sdl2_is_installed();
312
313/* Must be freed afterwards with l_str_free() */
314char *lg_get_sdl_win_flags(SDL_Window *);
315
316#endif /* LIBGAME_H */
void lg_show_extra_sys_info(SDL_Window *w)
Definition libgame.c:1309
void lg_set_new_viewport(Rec2Di viewport)
Definition libgame.c:916
void lg_show_sys_info()
Definition libgame.c:1181
void lg_disable_mouse()
Definition libgame.c:941
void lg_update_gl_win_title(const char *win_title)
Definition libgame.c:1147
void lg_show_lib_info()
Definition libgame.c:1157
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
void lg_list_opengl_extensions()
Definition libgame.c:949
zboolean sdl2_is_installed()
Definition libgame.c:1362
void lg_enable_mouse()
Definition libgame.c:933
zboolean lg_load_engine_fonts()
Definition libgame.c:984
void lg_reset_viewport()
Definition libgame.c:924
void lg_swap_fb()
Definition libgame.c:1137
void lg_quit(int exit_code, zboolean call_exit)
Definition libgame.c:1053
Rec2Di lg_get_default_viewport()
Definition libgame.c:906
void lg_engine_fonts_info()
Definition libgame.c:1042
char * lg_get_sdl_win_flags(SDL_Window *w)
Definition libgame.c:1382
Definition lg_gr_func.h:49
Definition libgame.h:256