X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=scene.c;h=1493e3163c9a781b7def812d573c392736bbdda5;hb=bc662e293c854e1bdc9d46e9a410fe220247e6d4;hp=d079e17ac7c4788617beb42d6c1ff4665ddb428a;hpb=95850b98f73ad7033af60a30e324e9c3cda55389;p=chaz%2Frasterize diff --git a/scene.c b/scene.c index d079e17..1493e31 100644 --- a/scene.c +++ b/scene.c @@ -18,6 +18,7 @@ static int _model_add_translate(model_t* m, FILE* file); static int _model_add_rotate(model_t* m, FILE* file); static int _model_add_scale(model_t* m, FILE* file); static int _model_set_material(model_t* m, FILE* file); +static int _model_set_texture(model_t* m, FILE* file); static int _scene_set_ambient(scene_t* s, FILE* file); static int _scene_add_light(scene_t* s, FILE* file); @@ -124,6 +125,13 @@ if (m == NULL) { \ } break; + case 'm': + _ASSERT_G; + if (_model_set_texture(m, file) != 0) { + goto fail; + } + break; + case 'X': goto done; @@ -161,11 +169,13 @@ static int _model_set_colors(model_t* m, FILE* file) return -1; } - for (const list_t* i = model_geometry(m); i; i = i->link) { - tri_t* t = (tri_t*)i->val; - t->a.c = color_new((colorchan_t)r, (colorchan_t)g, (colorchan_t)b, (colorchan_t)a); - t->b.c = color_new((colorchan_t)r, (colorchan_t)g, (colorchan_t)b, (colorchan_t)a); - t->c.c = color_new((colorchan_t)r, (colorchan_t)g, (colorchan_t)b, (colorchan_t)a); + color_t color = color_new((colorchan_t)r, (colorchan_t)g, (colorchan_t)b, (colorchan_t)a); + + array_it_t it = array_begin(model_geometry(m)); + for (tri_t* t; t = array_it_tri_next(&it);) { + t->a.c = color; + t->b.c = color; + t->c.c = color; } return 0; } @@ -229,6 +239,22 @@ static int _model_set_material(model_t* m, FILE* file) return 0; } +/* + * Set the texture to be used while drawing the current model. + */ +static int _model_set_texture(model_t* m, FILE* file) +{ + char filename[4096]; + if (fgets(filename, 4096, file) == NULL) { + fprintf(stderr, "Cannot read texture filename from scene.\n"); + return -1; + } +#if TEXTURING + model_texture(m, (const void*)raster_import(trim(filename))); +#endif + return 0; +} + /* * Add a light to the scene. */ @@ -283,3 +309,6 @@ raster_t* scene_render(scene_t* s) return p; } + +#include "opengl.c" +