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);
}
break;
+ case 'm':
+ _ASSERT_G;
+ if (_model_set_texture(m, file) != 0) {
+ goto fail;
+ }
+ break;
+
case 'X':
goto done;
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;
}
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.
*/
return p;
}
+
+#include "opengl.c"
+