LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024-2025 ETMSoftware
lg_terrain.h
1 /*
2  * LibGame - Copyright (C) Emmanuel Thomas-Maurin 2011-2025
3  * All rights reserved
4  */
5 
6 #ifndef LG_TERRAIN_H
7 #define LG_TERRAIN_H
8 
9 #define HEIGHTMAP_MAX_W 1024
10 #define HEIGHTMAP_MAX_H 1024
11 
12 #define HEIGHTMAP_MIN_W 8
13 #define HEIGHTMAP_MIN_H 8
14 
15 #define TERRAIN_BBOX_COLOR "cyan"
16 
17 typedef enum {
18  RANDOM_NOISE,
19  PERLIN_NOISE,
20  OPENSIMPLEX2_NOISE,
21  CELLULAR_NOISE /* = VORONOI_NOISE */
22  /*
23  OPENSIMPLEX2S_NOISE
24  VALUE_CUBIC_NOISE
25  VALUE_NOISE
26  */
27 } lg_noise_type;
28 
29 #define NORTH_BORDER 1
30 #define SOUTH_BORDER 2
31 #define WEST_BORDER 4
32 #define EAST_BORDER 8
33 
34 /* Horizontally-centered and normalized */
35 typedef struct {
36  Vertex_uv_n *vbo_data; /* VBO (with interleaved vertex data) - sizeof(Vertex_uv_n) = 24 */
37  uint32_t *ibo_data; /* IBO (indices start at 0) - sizeof(uint32_t) = 4 */
38  uint32_t vbo_size;
39  uint32_t ibo_size;
40  uint32_t n_vertices;
41  uint32_t n_faces;
42  uint32_t n_indices; /* Needed ? Always = n_faces * 3 */
43  LG_Texture *tex;
44  uint16_t grid_w; /* Useful ? */
45  uint16_t grid_h; /* Useful ? */
46 } LG_Terrain;
47 
48 LG_Terrain *lg_terrain_new(uint16_t, uint16_t, float, int, int, float, LG_Texture *);
49 
50 LG_Terrain *lg_terrain_new_from_heightmap(float *, uint16_t, uint16_t, float, LG_Texture *);
51 
53 
54 float *lg_heightmap_generate(uint16_t, uint16_t, int, int, float);
55 
56 void lg_heightmaps_add(float *, float *, uint16_t, uint16_t, float);
57 
58 void lg_heightmap_flatten_border(float *, uint16_t, uint16_t, uint16_t, int);
59 
61 
62 Vertex_rgba *lg_horiz_grid(int, int *, float, LG_Color_u);
63 
64 // DEPRECATED
65 const Vertex *lg_horiz_grid0();
66 
67 const unsigned short *lg_horiz_grid0_indices();
68 
69 size_t lg_sizeof_horiz_grid0();
70 
72 
73 #endif /* LG_TERRAIN_H */
LG_Mesh
Definition: lg_mesh.h:68
lg_terrain_to_mesh
LG_Mesh * lg_terrain_to_mesh(LG_Terrain *terrain)
Definition: lg_terrain.c:449
lg_sizeof_horiz_grid0
size_t lg_sizeof_horiz_grid0()
Definition: lg_terrain.c:736
lg_sizeof_horiz_grid0_indices
size_t lg_sizeof_horiz_grid0_indices()
Definition: lg_terrain.c:744
Vertex_uv_n
Definition: lg_vertex.h:44
lg_terrain_free
void lg_terrain_free(LG_Terrain *terrain)
Definition: lg_terrain.c:300
lg_terrain_new_from_heightmap
LG_Terrain * lg_terrain_new_from_heightmap(float *heightmap, uint16_t width, uint16_t height, float vert_scaling_k, LG_Texture *tex)
Definition: lg_terrain.c:120
lg_heightmap_generate
float * lg_heightmap_generate(uint16_t width, uint16_t height, int noise_type, int seed, float frequency)
Definition: lg_terrain.c:335
Vertex
Definition: lg_vertex.h:14
lg_heightmaps_add
void lg_heightmaps_add(float *heightmap1, float *heightmap2, uint16_t w, uint16_t h, float k)
Definition: lg_terrain.c:380
lg_horiz_grid0
const Vertex * lg_horiz_grid0()
Definition: lg_terrain.c:711
lg_heightmap_flatten_border
void lg_heightmap_flatten_border(float *heightmap, uint16_t w, uint16_t h, uint16_t k, int border)
Definition: lg_terrain.c:405
LG_Color_u
Definition: lg_vertex.h:91
LG_Texture
Definition: lg_textures.h:42
lg_horiz_grid
Vertex_rgba * lg_horiz_grid(int grid_width, int *n_vertices, float scaling, LG_Color_u c)
Definition: lg_terrain.c:605
lg_horiz_grid0_indices
const unsigned short * lg_horiz_grid0_indices()
Definition: lg_terrain.c:728
LG_Terrain
Definition: lg_terrain.h:35
lg_terrain_new
LG_Terrain * lg_terrain_new(uint16_t width, uint16_t height, float vert_scaling_k, int noise_type, int seed, float frequency, LG_Texture *tex)
Definition: lg_terrain.c:91
Vertex_rgba
Definition: lg_vertex.h:60