From 4e27e4e960c3f97453f2700b5556df5d27d62af7 Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Fri, 6 Sep 2013 23:03:08 -0700 Subject: [PATCH] Color is three unit8_t's instead of three floats --- src/basics.h | 4 +++- src/scene.c | 13 +++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/basics.h b/src/basics.h index 41c8617..bdb78f4 100644 --- a/src/basics.h +++ b/src/basics.h @@ -9,6 +9,8 @@ #ifndef __BASICS_H #define __BASICS_H +#include + typedef struct { float x, y, z; @@ -43,7 +45,7 @@ Ray ray_init(Vector3 location, Vector3 direction); typedef struct { - float red, green, blue; + uint8_t red, green, blue, alpha; } Color; diff --git a/src/scene.c b/src/scene.c index 55158e8..59f8fc0 100644 --- a/src/scene.c +++ b/src/scene.c @@ -71,8 +71,8 @@ scene_load(Scene *scene, FILE *scene_file) void scene_render(Scene *scene) { - Color *pixels = malloc(sizeof(Color) * scene->height * scene->width); - if (pixels == NULL) { + scene->pixels = malloc(sizeof(Color) * scene->height * scene->width); + if (scene->pixels == NULL) { // TODO: Print an error. return; } @@ -93,7 +93,7 @@ scene_render(Scene *scene) // Assemble a ray and trace it. direction = vector_init(xx, yy, 1); primary_ray = ray_init(ZeroVector3, direction); - pixels[y * x] = _scene_trace(scene, primary_ray, 0); + scene->pixels[y * scene->height + x] = _scene_trace(scene, primary_ray, 0); } } } @@ -103,9 +103,10 @@ Color _scene_trace(Scene *scene, const Ray ray, const int depth) { Color out_color; - out_color.red = 0.0; - out_color.blue = 0.0; - out_color.green = 0.0; + out_color.red = 0; + out_color.blue = 0; + out_color.green = 0; + out_color.alpha = 255; return out_color; }