Color is three unit8_t's instead of three floats
This commit is contained in:
parent
1f2e7c97d6
commit
4e27e4e960
2 changed files with 10 additions and 7 deletions
|
@ -9,6 +9,8 @@
|
||||||
#ifndef __BASICS_H
|
#ifndef __BASICS_H
|
||||||
#define __BASICS_H
|
#define __BASICS_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float x, y, z;
|
float x, y, z;
|
||||||
|
@ -43,7 +45,7 @@ Ray ray_init(Vector3 location, Vector3 direction);
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
float red, green, blue;
|
uint8_t red, green, blue, alpha;
|
||||||
} Color;
|
} Color;
|
||||||
|
|
||||||
|
|
||||||
|
|
13
src/scene.c
13
src/scene.c
|
@ -71,8 +71,8 @@ scene_load(Scene *scene, FILE *scene_file)
|
||||||
void
|
void
|
||||||
scene_render(Scene *scene)
|
scene_render(Scene *scene)
|
||||||
{
|
{
|
||||||
Color *pixels = malloc(sizeof(Color) * scene->height * scene->width);
|
scene->pixels = malloc(sizeof(Color) * scene->height * scene->width);
|
||||||
if (pixels == NULL) {
|
if (scene->pixels == NULL) {
|
||||||
// TODO: Print an error.
|
// TODO: Print an error.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -93,7 +93,7 @@ scene_render(Scene *scene)
|
||||||
// Assemble a ray and trace it.
|
// Assemble a ray and trace it.
|
||||||
direction = vector_init(xx, yy, 1);
|
direction = vector_init(xx, yy, 1);
|
||||||
primary_ray = ray_init(ZeroVector3, direction);
|
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)
|
_scene_trace(Scene *scene, const Ray ray, const int depth)
|
||||||
{
|
{
|
||||||
Color out_color;
|
Color out_color;
|
||||||
out_color.red = 0.0;
|
out_color.red = 0;
|
||||||
out_color.blue = 0.0;
|
out_color.blue = 0;
|
||||||
out_color.green = 0.0;
|
out_color.green = 0;
|
||||||
|
out_color.alpha = 255;
|
||||||
|
|
||||||
return out_color;
|
return out_color;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue