summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-12-16 19:25:11 -0500
committerTavian Barnes <tavianator@gmail.com>2009-12-16 19:25:11 -0500
commitfb8fb378dcce0564085eb6222053a0db57eb480c (patch)
tree7f2521cb72df33d39c7cdf28b0c4187bb1088d71
parent728d06945f7cdee8e459d71f5dabbeeb9f1e1207 (diff)
downloaddimension-fb8fb378dcce0564085eb6222053a0db57eb480c.tar.xz
Accept width and height command-line arguments.
-rw-r--r--dimension/main.c34
-rw-r--r--dimension/realize.c7
-rwxr-xr-xtests/dimension/demo.sh2
3 files changed, 34 insertions, 9 deletions
diff --git a/dimension/main.c b/dimension/main.c
index a0fa35c..e8b0d22 100644
--- a/dimension/main.c
+++ b/dimension/main.c
@@ -27,6 +27,7 @@
#include <getopt.h>
static const char *output = NULL, *input = NULL;
+static unsigned int width = 640, height = 480;
static int tokenize = 0, parse = 0;
int
@@ -38,6 +39,8 @@ main(int argc, char **argv) {
static struct option long_options[] = {
{ "output", required_argument, NULL, 'o' },
{ "input", required_argument, NULL, 'i' },
+ { "width", required_argument, NULL, 'w' },
+ { "height", required_argument, NULL, 'h' },
{ "tokenize", no_argument, &tokenize, 1 },
{ "parse", no_argument, &parse, 1 },
{ 0, 0, 0, 0 }
@@ -45,7 +48,7 @@ main(int argc, char **argv) {
int opt, opt_index;
while (1) {
- opt = getopt_long(argc, argv, "o:i:", long_options, &opt_index);
+ opt = getopt_long(argc, argv, "o:i:w:h:", long_options, &opt_index);
if (opt == -1)
break;
@@ -73,6 +76,27 @@ main(int argc, char **argv) {
}
break;
+ case 'w':
+ {
+ char *endptr;
+ width = strtoul(optarg, &endptr, 10);
+ if (*endptr != '\0' || endptr == optarg) {
+ fprintf(stderr, "Invalid argument to --width!\n");
+ return EXIT_FAILURE;
+ }
+ break;
+ }
+ case 'h':
+ {
+ char *endptr;
+ height = strtoul(optarg, &endptr, 10);
+ if (*endptr != '\0' || endptr == optarg) {
+ fprintf(stderr, "Invalid argument to --height!\n");
+ return EXIT_FAILURE;
+ }
+ break;
+ }
+
default:
fprintf(stderr, "Invalid command line option!\n");
return EXIT_FAILURE;
@@ -166,6 +190,14 @@ main(int argc, char **argv) {
}
dmnsn_delete_astree(astree);
+ /* Allocate a canvas */
+ scene->canvas = dmnsn_new_canvas(width, height);
+ if (!scene->canvas) {
+ dmnsn_delete_scene(scene);
+ fprintf(stderr, "Couldn't allocate canvas!\n");
+ return EXIT_FAILURE;
+ }
+
/*
* Now we render the scene
*/
diff --git a/dimension/realize.c b/dimension/realize.c
index d030a76..1a42be9 100644
--- a/dimension/realize.c
+++ b/dimension/realize.c
@@ -555,13 +555,6 @@ dmnsn_realize(const dmnsn_array *astree)
/* Background color */
scene->background = dmnsn_black;
- /* Allocate a canvas */
- scene->canvas = dmnsn_new_canvas(768, 480);
- if (!scene->canvas) {
- dmnsn_delete_scene(scene);
- return NULL;
- }
-
/* Create the default perspective camera */
scene->camera = dmnsn_new_perspective_camera();
if (!scene->camera) {
diff --git a/tests/dimension/demo.sh b/tests/dimension/demo.sh
index 26b5637..8a210d4 100755
--- a/tests/dimension/demo.sh
+++ b/tests/dimension/demo.sh
@@ -59,4 +59,4 @@ if [ "$demo" != "$demo_exp" ]; then
exit 1
fi
-${top_builddir}/dimension/dimension -o demo.png ${srcdir}/demo.pov
+${top_builddir}/dimension/dimension -w768 -h480 -o demo.png ${srcdir}/demo.pov