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