]>
Dogcows Code - chaz/rasterize/blob - main.c
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
);
59 raster_printstats(raster
);
61 char* u3d
= mem_strdup(filename
);
64 char* ppm
= mem_strcat(u3d
, ".ppm");
65 TRY_DO("Exporting to %s", raster_export_ppm(raster
, ppm
), ppm
);
69 char* bmp
= mem_strcat(u3d
, ".bmp");
70 TRY_DO("Exporting to %s", raster_export_bmp(raster
, bmp
), bmp
);
75 raster_destroy(raster
);
79 * Render a scene that is read from standard input, and export to BMP.
81 static void draw_from_stdin(const char* filename
)
84 TRY_DO("Loading from stdin", load_from_stdin(&scene
));
86 raster_t
* raster
= scene_render(scene
);
88 raster_printstats(raster
);
90 TRY_DO("Exporting to %s", raster_export_bmp(raster
, filename
), filename
);
92 raster_destroy(raster
);
96 * Render one or more scenes from 3D scene files.
98 int main(int argc
, char* argv
[])
102 while ((c
= getopt(argc
, argv
, "o:")) != -1) {
106 draw_from_stdin(optarg
);
110 if (out
== 0 && argc
<= 1) {
114 for (int i
= optind
; i
< argc
; ++i
) {
120 int _blocks
= mem_blocks();
122 fprintf(stderr
, " *** Leaked %d blocks of memory! ***\n", _blocks
);
This page took 0.040508 seconds and 4 git commands to generate.