add support for 3d scenes, depth testing, lighting
[chaz/rasterize] / main.c
1
2 /*
3 * CS5600 University of Utah
4 * Charles McGarvey
5 * mcgarvey@eng.utah.edu
6 */
7
8 #include <stdio.h>
9
10 #include "raster.h"
11 #include "scene.h"
12
13
14 /*
15 * Load a scene from a file.
16 */
17 static int load(scene_t** scene, const char* filename)
18 {
19 *scene = scene_alloc(filename);
20 if (*scene == NULL) {
21 return 1;
22 }
23 return 0;
24 }
25
26 /*
27 * Load a scene file, render it, and export it to PPM and BMP formats.
28 */
29 static void draw(const char* filename)
30 {
31 scene_t* scene;
32 TRY_DO("Loading %s", load(&scene, filename), filename);
33
34 raster_t* raster = scene_render(scene);
35 scene_destroy(scene);
36 raster_printstats(raster);
37
38 char* u3d = mem_strdup(filename);
39 strcut(u3d, '.');
40 char* ppm = mem_strcat(u3d, ".ppm");
41 char* bmp = mem_strcat(u3d, ".bmp");
42
43 TRY_DO("Exporting to %s", raster_export_ppm(raster, ppm), ppm);
44 TRY_DO("Exporting to %s", raster_export_bmp(raster, bmp), bmp);
45
46 mem_free(u3d);
47 mem_free(ppm);
48 mem_free(bmp);
49 raster_destroy(raster);
50 }
51
52 /*
53 * Render one or more scenes from 3D scene files.
54 */
55 int main(int argc, char* argv[])
56 {
57 if (argc <= 1) {
58 draw("scene.u3d");
59 }
60 else {
61 for (int i = 1; i < argc; ++i) {
62 draw(argv[i]);
63 }
64 }
65
66 #if !NDEBUG
67 int _blocks = mem_blocks();
68 if (_blocks != 0) {
69 fprintf(stderr, " *** Leaked %d blocks of memory! ***\n", _blocks);
70 return EXIT_FAILURE;
71 }
72 #endif
73 return EXIT_SUCCESS;
74 }
75
This page took 0.040224 seconds and 4 git commands to generate.