raytracer

raytracer.git
git clone git://git.lenczewski.org/raytracer.git
Log | Files | Refs | README | LICENSE

main.c (1139B)


      1 #include "rt.h"
      2 
      3 int
      4 main(int argc, char **argv)
      5 {
      6 	char *filepath = "/tmp/test.bmp";
      7 
      8 	int fd = open(filepath, O_WRONLY | O_CREAT, 0644);
      9 	if (fd < 0) {
     10 		fprintf(stderr, "Failed to open file: %s: ", filepath);
     11 		perror("open");
     12 		exit(EXIT_FAILURE);
     13 	}
     14 
     15 	// ===================================================================
     16 
     17 	// image
     18 	size_t width = 1024, height = 1024;
     19 	pixel_t *buf = malloc(sizeof *buf * width * height);
     20 	assert(buf);
     21 
     22 	// world
     23 	struct world world;
     24 
     25 	world_init(&world);
     26 
     27 	struct sphere sphere = {
     28 		.centre = VEC3(point_t, 0, 0, -1),
     29 		.radius = 0.5,
     30 
     31 		.hittable.impl = sphere_hittable_impl,
     32 	};
     33 
     34 	world_push(&world, &sphere.hittable);
     35 
     36 	struct sphere ground = {
     37 		.centre = VEC3(point_t, 0, -100.5, -1),
     38 		.radius = 100,
     39 
     40 		.hittable.impl = sphere_hittable_impl,
     41 	};
     42 
     43 	world_push(&world, &ground.hittable);
     44 
     45 	// rendering
     46 	render(buf, width, height, &world);
     47 
     48 	// ===================================================================
     49 
     50 	bitmap_write(fd, buf, width, height, PIXEL_FORMAT_ARGB32);
     51 
     52 	close(fd);
     53 
     54 	exit(EXIT_SUCCESS);
     55 }
     56 
     57 #include "math.c"
     58 #include "raytracing.c"
     59 #include "bitmap.c"
     60 #include "rt.c"