X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=scene.cc;h=dadc5799adeab92e3a369e5a87d5fe39973584e0;hb=9f13ae5fe777dd4f7a9302f6dcf3e0d99a1ce65d;hp=a415ab084d0354342a420c3cd0a3876ca5d804f5;hpb=a737ad45e690daa3b39b8885e2b6574d2ea48833;p=chaz%2Frasterize diff --git a/scene.cc b/scene.cc index a415ab0..dadc579 100644 --- a/scene.cc +++ b/scene.cc @@ -155,9 +155,9 @@ static int _scene_add_sphere(scene_t* s, FILE* file) } rt::element* sphere = new rt::sphere( vec_new((scal_t)x, (scal_t)y, (scal_t)z), - (scal_t)radius, - color_new((scal_t)r, (scal_t)g, (scal_t)b, S(1.0)) + (scal_t)radius ); + sphere->material(color_new((scal_t)r, (scal_t)g, (scal_t)b, S(1.0))); list_push2(&s->objects, sphere, DTOR(rt::sphere_destroy)); return 0; } @@ -172,9 +172,9 @@ static int _scene_add_plane(scene_t* s, FILE* file) } rt::element* plane = new rt::plane( vec_new((scal_t)x, (scal_t)y, (scal_t)z), - vec_new((scal_t)nx, (scal_t)ny, (scal_t)nz), - color_new((scal_t)r, (scal_t)g, (scal_t)b, S(1.0)) + vec_new((scal_t)nx, (scal_t)ny, (scal_t)nz) ); + plane->material(color_new((scal_t)r, (scal_t)g, (scal_t)b, S(1.0))); list_push2(&s->objects, plane, DTOR(rt::plane_destroy)); return 0; } @@ -190,9 +190,9 @@ static int _scene_add_triangle(scene_t* s, FILE* file) rt::element* triangle = new rt::triangle( vec_new((scal_t)x1, (scal_t)y1, (scal_t)z1), vec_new((scal_t)x2, (scal_t)y2, (scal_t)z2), - vec_new((scal_t)x3, (scal_t)y3, (scal_t)z3), - color_new((scal_t)r, (scal_t)g, (scal_t)b, S(1.0)) + vec_new((scal_t)x3, (scal_t)y3, (scal_t)z3) ); + triangle->material(color_new((scal_t)r, (scal_t)g, (scal_t)b, S(1.0))); list_push2(&s->objects, triangle, DTOR(rt::triangle_destroy)); return 0; } @@ -226,6 +226,19 @@ raster_t* scene_render(const scene_t* s) /*raster_light(p, *(light_t*)i->val);*/ /*}*/ + raster_t* texture = raster_import("texture.bmp"); + if (texture == NULL) { + texture = raster_import("texture.ppm"); + } + + if (s->objects && texture != NULL) { + rt::element* obj = (rt::element*)s->objects->val; + obj->texture(texture); +#if VERBOSITY >= 3 + printf("Loaded texture file; will texture first scene object.\n"); +#endif + } + #if VERBOSITY >= 3 printf("rendering scene...\n"); #endif @@ -267,6 +280,10 @@ raster_t* scene_render(const scene_t* s) printf("render complete!\ntime\t%.3fms\n", (float)dt / 1000.0f); #endif + if (texture) { + raster_destroy(texture); + } + return p; }