diff options
Diffstat (limited to 'mtl.c')
-rw-r--r-- | mtl.c | 33 |
1 files changed, 23 insertions, 10 deletions
@@ -13,19 +13,34 @@ struct mtl { char name[50]; - GLuint diffuse; + GLuint diff; + GLuint spec; }; static struct mtl *mtls; static int lmtls; static size_t nmtls; -int mtl_load(char *name) +GLuint tex_file(const char *name, const char *type) { - struct mtl *m; char loc[100]; + GLuint ret; FILE *f; + snprintf(loc, sizeof loc, "assets/%s.%s.png", name, type); + f = fopen(loc, "rb"); + if (f == NULL) + eprintf("Could not open '%s':", loc); + ret = png2tex(f); + fclose(f); + + return ret; +} + +int mtl_load(char *name) +{ + struct mtl *m; + for (int i = 0; i < lmtls; i++) if (strcmp(mtls[i].name, name) == 0) return i; @@ -35,12 +50,8 @@ int mtl_load(char *name) snprintf(m->name, sizeof m->name, "%s", name); - snprintf(loc, sizeof loc, "assets/%s.diff.png", name); - f = fopen(loc, "rb"); - if (f == NULL) - eprintf("Could not open '%s':", loc); - m->diffuse = png2tex(f); - fclose(f); + m->diff = tex_file(name, "diff"); + m->spec = tex_file(name, "spec"); return lmtls++; } @@ -54,5 +65,7 @@ void mtl_use(int mtl) return; gl_tex_active(GL_TEXTURE0); - gl_tex_bind(GL_TEXTURE_2D, mtls[mtl].diffuse); + gl_tex_bind(GL_TEXTURE_2D, mtls[mtl].diff); + gl_tex_active(GL_TEXTURE1); + gl_tex_bind(GL_TEXTURE_2D, mtls[mtl].spec); } |