]>
Dogcows Code - chaz/rasterize/blob - main.cc
3 * CS5600 University of Utah
5 * mcgarvey@eng.utah.edu
8 #define _POSIX_C_SOURCE 2
17 * Load a scene from a file.
19 static int load(scene_t
** scene
, const char* filename
)
21 FILE* file
= fopen(filename
, "r");
23 fprintf(stderr
, "Cannot read %s: %s\n", filename
, strerror(errno
));
27 *scene
= scene_alloc(file
);
38 * Load a scene from standard input.
40 static int load_from_stdin(scene_t
** scene
)
42 *scene
= scene_alloc(stdin
);
50 * Load a scene file, render it, and export it.
52 static void draw(const char* filename
)
55 TRY_DO("Loading %s", load(&scene
, filename
), filename
);
57 raster_t
* raster
= scene_render(scene
);
60 char* urt
= mem_strdup(filename
);
63 char* ppm
= mem_strcat(urt
, ".ppm");
64 TRY_DO("Exporting to %s", raster_export_ppm(raster
, ppm
), ppm
);
68 char* bmp
= mem_strcat(urt
, ".bmp");
69 TRY_DO("Exporting to %s", raster_export_bmp(raster
, bmp
), bmp
);
74 raster_destroy(raster
);
78 * Render a scene that is read from standard input, and export to BMP.
80 static void draw_from_stdin(const char* filename
)
83 TRY_DO("Loading from stdin", load_from_stdin(&scene
));
85 raster_t
* raster
= scene_render(scene
);
88 TRY_DO("Exporting to %s", raster_export_bmp(raster
, filename
), filename
);
90 raster_destroy(raster
);
94 * Render one or more scenes from 3D scene files.
96 int main(int argc
, char* argv
[])
100 while ((c
= getopt(argc
, argv
, "o:")) != -1) {
104 draw_from_stdin(optarg
);
108 if (out
== 0 && argc
<= 1) {
112 for (int i
= optind
; i
< argc
; ++i
) {
118 int _blocks
= mem_blocks();
120 fprintf(stderr
, " *** Leaked %d blocks of memory! ***\n", _blocks
);
This page took 0.042275 seconds and 4 git commands to generate.