下面是main.c
#include <stdio.h>
#include <math.h>
#include <il/il.h>
#pragma comment(lib,"DevIL.lib")
#pragma comment(lib,"ILU.lib")
#pragma comment(lib,"ILUT.lib")
#include "vec3.h"
#include "sample.h"
#include "shapes.h"
#define IMAGE_WIDTH 512
#define IMAGE_HEIGHT 384
#define NUM_SAMPLES 16
shape_t shapes[4];
light_t lights[1];
unsigned char floattochar(float c)
{
int i = (int)c;
if (i <= 0)
return 0;
if (i >= 255)
return 255;
else
return (unsigned char)(c);
}
int main(int argc, int argv)
{
int r, c, s;
float x_samples[NUM_SAMPLES];
float y_samples[NUM_SAMPLES];
float t_samples[NUM_SAMPLES];
unsigned char image[IMAGE_WIDTH * IMAGE_HEIGHT * 3];
float aspect;
vec3 total, color, hitpos;
vec3 start, dir;
hit_t hit;
ILuint iname;
ilInit();
ilEnable(IL_FILE_OVERWRITE);
aspect = (float) IMAGE_HEIGHT / (float)IMAGE_WIDTH;
VectorSet(dir, 0, 0, -1);
shapes[0].type = SHAPE_SPHERE;
VectorSet(shapes[0].sphere.center, -0.3f, 0.3f, -2);
shapes[0].sphere.radius = 0.25f;
VectorSet(shapes[0].move_velocity, 0, -0.05f, 0);
VectorSet(shapes[0].color, 1, 0, 0);
shapes[1].type = SHAPE_SPHERE;
VectorSet(shapes[1].sphere.center, 0.3f, 0.3f, -4);
shapes[1].sphere.radius = 0.25f;
VectorSet(shapes[1].move_velocity, 0.1f, 0, 0);
VectorSet(shapes[1].color, 0, 1, 0);
shapes[2].type = SHAPE_TRI;
VectorSet(shapes[2].tri.verts[0], -0.9f, -0.5f,0);
VectorSet(shapes[2].tri.verts[1], 0, 0, -6