aboutsummaryrefslogtreecommitdiff
path: root/pgm.c
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2020-02-21 06:55:27 +0100
committerJulian T <julian@jtle.dk>2020-02-21 06:55:27 +0100
commit623fee395425ab33f14fb9cd8ffa790e362f59d7 (patch)
treec70b64e13fd5e00c2317fa40ee4b8cd786e635d5 /pgm.c
parent63a84080f9f0e3d719d5470e370584a5eff18a47 (diff)
Added pgm drawing and got light ray tracing working
Still needs correct light simulation and reflections
Diffstat (limited to 'pgm.c')
-rw-r--r--pgm.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/pgm.c b/pgm.c
new file mode 100644
index 0000000..058b445
--- /dev/null
+++ b/pgm.c
@@ -0,0 +1,27 @@
+#include "pgm.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int pgm_write_header(FILE *fp, unsigned int w, unsigned int h)
+{
+ return fprintf(fp, "P3\n%d %d\n255\n", w, h);
+}
+
+int pgm_write_pixel(FILE *fp, color_t *c)
+{
+ return fprintf(fp, "%d %d %d\n", c->r, c->g, c->b);
+}
+
+color_t *color_set(color_t *c, uint8_t r, uint8_t g, uint8_t b)
+{
+ if (!c) {
+ c = (color_t *) malloc(sizeof(c));
+ }
+
+ c->r = r;
+ c->g = g;
+ c->b = b;
+
+ return c;
+}