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-20260204"
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#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#include "lg_goodies.h"
183
187typedef enum {
188 LG_OK = LIBETM_LASTERRORCODE + 1,
189 LG_ERROR,
190 LG_INIT_ERROR,
191 LG_EXTRA_LIB_INIT_ERROR,
192 LG_OPENGL_ERROR,
193 LG_GLSL_ERROR,
194 LG_CREATE_FILE_ERROR,
195 LG_OPEN_FILE_ERROR,
196 LG_SAVE_FILE_ERROR,
197 LG_READ_FROM_FILE_ERROR,
198 LG_WRITE_TO_FILE_ERROR,
199 LG_FILE_ACCESS_ERROR,
200 LG_READ_FROM_FILE_EOF,
201 LG_EOF,
202 LG_SIZE_IS_ZERO,
203 LG_FREE_NULL,
204 LG_OOM,
205 LG_SIG_START, /* For Unix signals, error code = LG_SIG_START + signal value */
206 LG_SIG_END = LG_SIG_START + 100, /* Must really be the last one */
207 LG_LASTERRORCODE
208} lg_error_code;
209
210typedef enum {
211 LG_CONTINUE = LG_LASTERRORCODE + 1,
212 LG_CANCEL,
213 LG_QUIT,
214 LG_WON,
215 LG_LOST,
216 LG_LASTRETURNCODE
217} lg_return_code;
218
219/* SDL2 vsync stuff */
220#define NEVER_VSYNC 0
221#define ALWAYS_VSYNC 1
222#define ADAPTIVE_VSYNC -1
223
224typedef struct {
225 int i;
226 const char *str;
227} Vsync;
228
229/*
230 * WIN_LOGICAL_W and WIN_LOGICAL_H must be defined in app
231 * 16/9 or (on new mobiles) 18/9 aspect ratio ?
232 * #define WIN_LOGICAL_W 1000
233 * #define WIN_LOGICAL_H 500
234 * On Android, we *always* want/use landscape orientation
235 */
236#define LG_WIN_WIDTH_MIN 800
237#define LG_WIN_HEIGHT_MIN 400
238
239#define LG_WIN_D_HEIGHT_HACK 2 /* DIRTY HACK: We want the whole win to be visible - actually, what was it about ? */
240
241/* Requested bit-depth */
242#define LG_REQUESTED_RED_SIZE 5
243#define LG_REQUESTED_GREEN_SIZE 6
244#define LG_REQUESTED_BLUE_SIZE 5
245#define LG_REQUESTED_ALPHA_SIZE 0
246#define LG_REQUESTED_DEPTH_SIZE 16
247#define LG_REQUESTED_STENCIL_SIZE 8
248
249int lg_init(int, int, const char *, const char *, const char *, const char *, const char *, const char *, const char *);
250
252
254
255void lg_reset_viewport();
256
257void lg_enable_mouse();
258
259void lg_disable_mouse();
260
262
263zboolean lg_load_engine_fonts();
264
266
267void lg_quit(int, zboolean);
268
269void lg_swap_fb();
270
271void lg_show_lib_info();
272
273void lg_show_sys_info();
274
275void lg_show_extra_sys_info(SDL_Window *);
276
277zboolean sdl2_is_installed();
278
279/* Must be freed afterwards with l_str_free() */
280char *lg_get_sdl_win_flags(SDL_Window *);
281
282#endif /* LIBGAME_H */
void lg_show_extra_sys_info(SDL_Window *w)
Definition libgame.c:1230
void lg_set_new_viewport(Rec2Di viewport)
Definition libgame.c:868
void lg_show_sys_info()
Definition libgame.c:1114
void lg_disable_mouse()
Definition libgame.c:893
void lg_show_lib_info()
Definition libgame.c:1090
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:901
zboolean sdl2_is_installed()
Definition libgame.c:1291
void lg_enable_mouse()
Definition libgame.c:885
zboolean lg_load_engine_fonts()
Definition libgame.c:936
void lg_reset_viewport()
Definition libgame.c:876
void lg_swap_fb()
Definition libgame.c:1082
void lg_quit(int exit_code, zboolean call_exit)
Definition libgame.c:998
Rec2Di lg_get_default_viewport()
Definition libgame.c:858
void lg_engine_fonts_info()
Definition libgame.c:987
char * lg_get_sdl_win_flags(SDL_Window *w)
Definition libgame.c:1311
Definition lg_gr_func.h:49
Definition libgame.h:224