Move to CMake
This commit is contained in:
parent
007bb10b7b
commit
baa67b51db
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,12 +1,15 @@
|
|||||||
build/
|
build/
|
||||||
|
cmake-build-*/
|
||||||
|
|
||||||
output.ppm
|
output.ppm
|
||||||
|
|
||||||
.clangd/
|
|
||||||
.cache/
|
.cache/
|
||||||
|
.clangd/
|
||||||
|
.idea/
|
||||||
.vs/
|
.vs/
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
|
compile_commands.json
|
||||||
compile_flags.txt
|
compile_flags.txt
|
||||||
|
|
||||||
vgcore.*
|
vgcore.*
|
||||||
|
|||||||
20
CMakeLists.txt
Normal file
20
CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
|
project(raytracing-in-one-weekend C)
|
||||||
|
|
||||||
|
add_executable(raytracer main.c
|
||||||
|
aabb.c
|
||||||
|
arena.c
|
||||||
|
camera.c
|
||||||
|
color.c
|
||||||
|
hittable.c
|
||||||
|
material.c
|
||||||
|
perlin.c
|
||||||
|
point3.c
|
||||||
|
ray.c
|
||||||
|
texture.c
|
||||||
|
utils.c
|
||||||
|
vec3.c
|
||||||
|
|
||||||
|
external/stb_image.c)
|
||||||
|
target_link_libraries(raytracer m)
|
||||||
13
build.sh
13
build.sh
@ -1,13 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
CC=${CC:-"gcc"}
|
|
||||||
CFLAGS=${CFLAGS:-"-Wall -Wextra -Wno-unused-function -std=gnu18 -fno-strict-aliasing -O3"}
|
|
||||||
LDFLAGS=${LDFLAGS:-"-lm"}
|
|
||||||
MAIN_FILE=${MAIN_FILE:-"main.c"}
|
|
||||||
|
|
||||||
# Write out compile_flags.txt for clangd
|
|
||||||
echo "${CFLAGS}" | tr ' ' '\n' > compile_flags.txt
|
|
||||||
|
|
||||||
mkdir -p build
|
|
||||||
|
|
||||||
${CC} ${CFLAGS} ${MAIN_FILE} -o build/raytracer ${LDFLAGS}
|
|
||||||
2
external/stb_image.c
vendored
Normal file
2
external/stb_image.c
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#include "stb_image.h"
|
||||||
42
main.c
42
main.c
@ -1,8 +1,9 @@
|
|||||||
|
#include <errno.h>
|
||||||
#include <float.h>
|
#include <float.h>
|
||||||
#include <math.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "arena.h"
|
#include "arena.h"
|
||||||
#include "camera.h"
|
#include "camera.h"
|
||||||
@ -185,8 +186,20 @@ static Hittable *simple_light(Arena *arena) {
|
|||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void) {
|
int main(int argc, char *argv[]) {
|
||||||
srand(42);
|
srand(time(0));
|
||||||
|
|
||||||
|
if (argc < 2) {
|
||||||
|
fprintf(stderr, "Expected output file name\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
FILE *output_file = fopen(argv[1], "wb");
|
||||||
|
if (!output_file) {
|
||||||
|
fprintf(stderr, "Failed to open output file %s: %s", argv[1],
|
||||||
|
strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* Memory management */
|
/* Memory management */
|
||||||
|
|
||||||
@ -255,7 +268,7 @@ int main(void) {
|
|||||||
camera_init(&camera, look_from, look_at, up, vfov, aspect_ratio, aperture,
|
camera_init(&camera, look_from, look_at, up, vfov, aspect_ratio, aperture,
|
||||||
dist_to_focus, 0.0, 1.0);
|
dist_to_focus, 0.0, 1.0);
|
||||||
|
|
||||||
printf("P3\n%u %u\n255\n", image_width, image_height);
|
fprintf(output_file, "P3\n%u %u\n255\n", image_width, image_height);
|
||||||
|
|
||||||
for (int j = image_height - 1; j >= 0; --j) {
|
for (int j = image_height - 1; j >= 0; --j) {
|
||||||
fprintf(stderr, "\rScanlines remaining: %d ", j);
|
fprintf(stderr, "\rScanlines remaining: %d ", j);
|
||||||
@ -268,29 +281,14 @@ int main(void) {
|
|||||||
pixel_color = color_add(
|
pixel_color = color_add(
|
||||||
pixel_color, ray_color(r, background_color, world, max_depth));
|
pixel_color, ray_color(r, background_color, world, max_depth));
|
||||||
}
|
}
|
||||||
color_write(stdout, pixel_color, samples_per_pixel);
|
color_write(output_file, pixel_color, samples_per_pixel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "\nDone.\n");
|
fprintf(stderr, "\nDone.\n");
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
fclose(output_file);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "aabb.c"
|
|
||||||
#include "arena.c"
|
|
||||||
#include "camera.c"
|
|
||||||
#include "color.c"
|
|
||||||
#include "hittable.c"
|
|
||||||
#include "material.c"
|
|
||||||
#include "perlin.c"
|
|
||||||
#include "point3.c"
|
|
||||||
#include "ray.c"
|
|
||||||
#include "texture.c"
|
|
||||||
#include "utils.c"
|
|
||||||
#include "vec3.c"
|
|
||||||
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
|
||||||
#include "external/stb_image.h"
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user