From 7e27b949516ea9cf94336252581fb0a90727e400 Mon Sep 17 00:00:00 2001 From: Randy McShandy Date: Sat, 18 May 2024 17:59:18 -0500 Subject: [PATCH] Clean up organization of some resource setup in renderer, and whatever else snuck in --- src/main.c | 2 +- src/platforms/platform_posix.c | 2 + src/render_raylib.c | 130 +++++++++++++++++++-------------- src/shaders/lighting.fs | 2 +- 4 files changed, 80 insertions(+), 56 deletions(-) diff --git a/src/main.c b/src/main.c index eb6dbc7..456c15e 100755 --- a/src/main.c +++ b/src/main.c @@ -22,7 +22,7 @@ int main(int argc, char** argv) } barrow.max_iterations *= 1; -#define ENABLE_BARROWGEN 1 +#define ENABLE_BARROWGEN 0 #if ENABLE_BARROWGEN generate_rd(8, barrow, grid, grid_size); #endif diff --git a/src/platforms/platform_posix.c b/src/platforms/platform_posix.c index 3550db5..72aa4e8 100644 --- a/src/platforms/platform_posix.c +++ b/src/platforms/platform_posix.c @@ -16,6 +16,7 @@ pthread_t* threads; pthread_mutex_t mutex; pthread_barrier_t barrier; +/* TODO: This should go in a header, platforms don't care. */ float rd_a_prime(FVec2 **source_grid, RD_Opts opts, int x, int y, Mat3 kernel, float A, float B); float rd_b_prime(FVec2** source_grid, RD_Opts opts, int x, int y, Mat3 kernel, float A, float B); @@ -90,6 +91,7 @@ void start(int worker_count, RD_Opts active_opt) } } +/* TODO: Revisit this for any new additions. */ int cleanup() { for (int t = 0; t < warg.worker_count; t++) diff --git a/src/render_raylib.c b/src/render_raylib.c index 72f52e5..d15803e 100644 --- a/src/render_raylib.c +++ b/src/render_raylib.c @@ -128,73 +128,91 @@ void process_inputs() while((key = GetKeyPressed())); } -void initialize_prerenderer() +void wait_initialize_shaders() { - fscreen_dims = (Vector2){.x=screen_dims.x, .y=screen_dims.y}; -} - -void initialize_renderer() -{ - shader = LoadShader("./src/shaders/lighting.vs", "./src/shaders/lighting.fs"); + while(!IsShaderReady(shader)){} + shader.locs[SHADER_LOC_VECTOR_VIEW] = GetShaderLocation(shader, "viewPos"); shader.locs[SHADER_LOC_MATRIX_MVP] = GetShaderLocation(shader, "mvp"); cam_position_shader_loc = GetShaderLocation(shader, "cam_position"); screen_dims_shader_loc = GetShaderLocation(shader, "screen_dims"); map_center_shader_loc = GetShaderLocation(shader, "map_center"); - while(!IsShaderReady(shader)){} +} + +void wait_initialize_resources() +{ + /* Barrow resource setup. */ + { + barrow_position = (Vector3){0.0f, 0.0f, 0.0f}; + barrow_image = LoadImage("./barrow.png"); + barrow_albedo = LoadTexture("./barrow_albedo.png"); + barrow_scale = (Vector3){barrow_image.width/6.0f, 8.0f, barrow_image.height/6.0f}; + barrow_rotation_axis = (Vector3){1.0f, 0.0f, 0.0f}; + barrow_rotation = 180.0f; + + while(!IsImageReady(barrow_image)){} + while(!IsTextureReady(barrow_albedo)){} + barrow_texture = LoadTextureFromImage(barrow_image); + while(!IsTextureReady(barrow_texture)){} + + barrow_meshes[0U] = GenMeshHeightmap(barrow_image, vec3_unit); + barrow_model = LoadModelFromMesh(barrow_meshes[0]); + barrow_model.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = barrow_albedo; + barrow_model.materials[0].maps[MATERIAL_MAP_ROUGHNESS].texture = barrow_albedo; + barrow_model.materials[0].shader = shader; + + while(!IsModelReady(barrow_model)){} + } - barrow_position = (Vector3){0.0f, 0.0f, 0.0f}; - barrow_image = LoadImage("./barrow.png"); - barrow_albedo = LoadTexture("./barrow_albedo.png"); - barrow_scale = (Vector3){barrow_image.width/6.0f, 8.0f, barrow_image.height/6.0f}; - barrow_rotation_axis = (Vector3){1.0f, 0.0f, 0.0f}; - barrow_rotation = 180.0f; + /* Floor resource setup. */ + { + floor_image = LoadImage("./floor.png"); + floor_albedo = LoadTexture("./floor_albedo.png"); + floor_scale = (Vector3){floor_image.width/6.0f, 3.0f, floor_image.height/6.0f}; + floor_position = (Vector3){0.0f, -3.0f, -floor_scale.z}; + floor_rotation_axis = (Vector3){0.0f, 0.0f, floor_image.width}; + floor_rotation = 0.0f; + while(!IsImageReady(floor_image)){} + while(!IsTextureReady(floor_albedo)){} + + floor_texture = LoadTextureFromImage(floor_image); + while(!IsTextureReady(floor_texture)){} + + floor_meshes[0U] = GenMeshHeightmap(floor_image, vec3_unit); + floor_model = LoadModelFromMesh(floor_meshes[0]); + floor_model.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = floor_albedo; + floor_model.materials[0].maps[MATERIAL_MAP_ROUGHNESS].texture = floor_albedo; + floor_model.materials[0].shader = shader; + while(!IsModelReady(floor_model)){} + } + + /* Other resource setup. */ + { + coffin_scale = (Vector3){1.5f, 1.5f, 1.5f}; + coffin_position = (Vector3){barrow_scale.x/2.0f, floor_position.y, -barrow_scale.z/2.0f}; + coffin_rotation_axis = (Vector3){0.0f, 0.0f, 0.0f}; + coffin_rotation = 0.0f; + coffin_model = LoadModel("./assets/coffin_1.glb"); + while(!IsModelReady(coffin_model)){} + coffin_model.materials[0].shader = shader; + } +} + +/* Values that are required to initialize Raylib. */ +void initialize_prerenderer() +{ + fscreen_dims = (Vector2){.x=screen_dims.x, .y=screen_dims.y}; map_center = barrow_scale; map_center.x /= 2.0f; map_center.z /= -2.0f; map_center.y = -3.0f; +} - while(!IsImageReady(barrow_image)){} - barrow_texture = LoadTextureFromImage(barrow_image); - - while(!IsTextureReady(barrow_texture)){} - while(!IsTextureReady(barrow_albedo)){} - - floor_image = LoadImage("./floor.png"); - floor_albedo = LoadTexture("./floor_albedo.png"); - floor_scale = (Vector3){floor_image.width/6.0f, 3.0f, floor_image.height/6.0f}; - floor_position = (Vector3){0.0f, -3.0f, -floor_scale.z}; - floor_rotation_axis = (Vector3){0.0f, 0.0f, floor_image.width}; - floor_rotation = 0.0f; - - while(!IsImageReady(floor_image)){} - floor_texture = LoadTextureFromImage(floor_image); - while(!IsTextureReady(floor_texture)){} - while(!IsTextureReady(floor_albedo)){} - - /* Might want to replace barrow_scale with just img dimensions. */ - barrow_meshes[0U] = GenMeshHeightmap(barrow_image, vec3_unit); - barrow_model = LoadModelFromMesh(barrow_meshes[0]); - barrow_model.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = barrow_albedo; - barrow_model.materials[0].maps[MATERIAL_MAP_ROUGHNESS].texture = barrow_albedo; - barrow_model.materials[0].shader = shader; - - floor_meshes[0U] = GenMeshHeightmap(floor_image, vec3_unit); - floor_model = LoadModelFromMesh(floor_meshes[0]); - floor_model.materials[0].maps[MATERIAL_MAP_ALBEDO].texture = floor_albedo; - floor_model.materials[0].maps[MATERIAL_MAP_ROUGHNESS].texture = floor_albedo; - floor_model.materials[0].shader = shader; - - coffin_scale = (Vector3){1.5f, 1.5f, 1.5f}; - coffin_position = (Vector3){barrow_scale.x/2.0f, floor_position.y, -barrow_scale.z/2.0f}; - coffin_rotation_axis = (Vector3){0.0f, 0.0f, 0.0f}; - coffin_rotation = 0.0f; - coffin_model = LoadModel("./assets/coffin_1.glb"); - while(!IsModelReady(coffin_model)){} - coffin_model.materials[0].shader = shader; - +/* Values and things to do that have to have to be done after Raylib is initialized. */ +void initialize_renderer() +{ cam = (Camera3D){0}; cam.position = barrow_position; cam.position.y -= 0.5f; @@ -206,13 +224,16 @@ void initialize_renderer() cam.projection = CAMERA_PERSPECTIVE; DisableCursor(); + SetWindowState(FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE); } void start_render_loop() { initialize_prerenderer(); InitWindow(fscreen_dims.x, fscreen_dims.y, screen_title); - SetWindowState(FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE); + + wait_initialize_shaders(); + wait_initialize_resources(); initialize_renderer(); Rectangle minimap_dest = {.width = 64.0f*img_export_scale.x, .height = 64.0f*img_export_scale.y, .x = 0.0f, .y = 0.0f}; @@ -221,6 +242,7 @@ void start_render_loop() SetTargetFPS(target_fps); while (!WindowShouldClose()) { + player_collide_point = cam.position; player_collide_point.y -= 1.0f; process_inputs(); diff --git a/src/shaders/lighting.fs b/src/shaders/lighting.fs index 7da0f8a..f856910 100644 --- a/src/shaders/lighting.fs +++ b/src/shaders/lighting.fs @@ -16,7 +16,7 @@ uniform vec3 map_center; out vec4 finalColor; const vec3 v3_unit = vec3(1.0f, 1.0f, 1.0f); -const float max_lum = 0.8f; +const float max_lum = 1.0f; const float max_lit_distance = 7.5f; const float max_center_distance = 8.0f; const vec4 candle_color = vec4(228.0f/255.0f, 103.0f/255.0f, 1.0f/255.0f, 255.0f/255.0f); -- 2.49.0