target_compile_definitions(posix_BC PUBLIC POSIX_BC=1)
target_compile_definitions(windows_BC PUBLIC WINDOWS_BC=1)
-target_compile_options(posix_BC PUBLIC -Wall)
+target_compile_options(posix_BC PUBLIC -Wall -g)
-target_link_libraries(posix_BC -lm -lpthread)
+target_link_libraries(posix_BC -lm -lpthread -lraylib)
target_link_libraries(windows_BC -lm -lpthread)
set_target_properties(posix_BC PROPERTIES RUNTIME_OUTPUT_DIRECTORY ./bin/)
#include <stdio.h>
#include <stdlib.h>
+
#include "structs.h"
+#include "render.h"
-int main(int argc, char** argv)
+void print_rlog(int logLevel, const char* text, va_list args)
{
+ printf("TRACE %d: ", logLevel);
+ printf(text, args);
+ printf("\n");
+}
- IVec2 grid_size = {.x = GRID_X * 1.5, .y = GRID_Y * 1.5};
+int main(int argc, char** argv)
+{
+ IVec2 grid_size = {.x = GRID_X * 1.0, .y = GRID_Y * 1.0};
FVec2 **grid = NULL;
grid = (FVec2**)malloc(grid_size.x * sizeof(FVec2*));
for (int n = 0; n < grid_size.x; n++)
}
generate_rd(8, barrow, grid, grid_size);
+ start_render_loop();
return 0;
}
--- /dev/null
+#ifndef RENDER_INTERFACE
+#define RENDER_INTERFACE
+
+void initialize_renderer();
+void start_render_loop();
+
+#endif /* RENDER_INTERFACE */
+
--- /dev/null
+#include <raylib.h>
+#include "structs.h"
+
+Camera3D cam;
+
+Image barrow_image;
+Texture barrow_texture;
+Texture diffuse_texture;
+Model barrow_model;
+Mesh barrow_meshes[1U];
+Material barrow_material;
+Matrix barrow_transform;
+Vector3 barrow_position;
+
+void initialize_renderer()
+{
+ barrow_position = (Vector3){-8.0f, 0.0f, -8.0f};
+ barrow_image = LoadImage("./barrow.png");
+ diffuse_texture = LoadTexture("./barrow_diffuse.png");
+
+ while(!IsImageReady(barrow_image)){}
+ barrow_texture = LoadTextureFromImage(barrow_image);
+
+ while(!IsTextureReady(barrow_texture)){}
+ while(!IsTextureReady(diffuse_texture)){}
+
+ barrow_meshes[0U] = GenMeshHeightmap(barrow_image, (Vector3){64.0f, 8.0f, 64.0f});
+ barrow_model = LoadModelFromMesh(barrow_meshes[0]);
+ barrow_model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = diffuse_texture;
+
+ cam = (Camera3D){0};
+ cam.position = barrow_position; //(Vector3){18.0f, 21.0f, 18.0f};
+ cam.position.y += 1.0f;
+ cam.target = (Vector3){0.0f, 0.0f, 0.0f};
+ cam.up = (Vector3){0.0f, 1.0f, 0.0f};
+ cam.fovy = 45.0f;
+ cam.projection= CAMERA_PERSPECTIVE;
+}
+
+void start_render_loop()
+{
+ InitWindow(screen_dims.x, screen_dims.y, screen_title);
+ initialize_renderer();
+
+ SetTargetFPS(target_fps);
+ while (!WindowShouldClose())
+ {
+ UpdateCamera(&cam, CAMERA_CUSTOM);
+ BeginDrawing();
+ ClearBackground(LIGHTGRAY);
+
+ BeginMode3D(cam);
+ DrawModel(barrow_model, barrow_position, 1.0f, DARKGRAY);
+ EndMode3D();
+
+ DrawTexture(barrow_texture, 64, 64, RAYWHITE);
+ DrawFPS(10, 10);
+ EndDrawing();
+ }
+
+ UnloadImage(barrow_image);
+ UnloadTexture(barrow_texture);
+ CloseWindow();
+}
+
const char chars[6] = {' ', ' ', ' ', '+', '#', '@'};
const int max_chars = sizeof(chars) / sizeof(chars[0]) - 1;
+const IVec2 screen_dims = {.x = 1600, .y = 900};
+const char* screen_title = "Barrow Crawler";
+const int target_fps = 60;
+
extern RD_Opts meiosis;
extern const Mat3 laplacian_kernel;
+extern const IVec2 screen_dims;
+extern const char* screen_title;
+extern const int target_fps;
+
int generate_rd(int worker_count, RD_Opts active_opt, FVec2 **grid_buffer, IVec2 pgrid_size);
#endif //__RD_STRUCTS__
#include <stdint.h>
#include <math.h>
-#warning TODO: I think this header is only posix, check for alt platform replacements
+#warning "TODO: I think this header is only posix, check for alt platform replacements"
#include <time.h>
#include "structs.h"
printf("Opts: {\nIterations: %d\nTime delta: %f\nDiffA: %f\nDiffB: %f\nFeed: %f\nKill: %f\n\n}\n", active_opt.max_iterations, active_opt.delta_t, active_opt.diff_a, active_opt.diff_b, active_opt.feed, active_opt.kill);
- char buffer[pgrid_size.x][pgrid_size.y];
+ /* png for the heightmap */
+ char mesh_buffer[pgrid_size.x][pgrid_size.y];
+ /* png for diffuse material */
+ char diffuse_buffer[pgrid_size.x][pgrid_size.y];
for (int x = 0; x < pgrid_size.x; x++)
{
for (int y = 0; y < pgrid_size.y; y++)
{
- buffer[x][y] = (uint8_t)(255.0f * round(-0.05f + grid_buffer[x][y].a));
+ float a = round(-0.05f + grid_buffer[x][y].a);
+ mesh_buffer[x][y] = (uint8_t)(255.0f * a);
+
+ /* Generate the diffuse texture.
+ This is a good chance to do cool stuff.
+ */
+ a = grid_buffer[x][y].a;
+ diffuse_buffer[x][y] = (uint8_t)(255.0f * a);
}
}
- char name[64] = {0};
- sprintf(name, "./%s.png", active_opt.name);
- stbi_write_png(name, pgrid_size.x, pgrid_size.y, 1, buffer, pgrid_size.x * sizeof(uint8_t));
+
+ char mesh_name[64] = {0};
+ char diffuse_name[64] = {0};
+ sprintf(mesh_name, "./%s.png", active_opt.name);
+ sprintf(diffuse_name, "./%s_diffuse.png", active_opt.name);
+ stbi_write_png(mesh_name, pgrid_size.x, pgrid_size.y, 1, mesh_buffer, pgrid_size.x * sizeof(uint8_t));
+ stbi_write_png(diffuse_name, pgrid_size.x, pgrid_size.y, 1, diffuse_buffer, pgrid_size.x * sizeof(uint8_t));
cleanup();
return 0;