diff options
author | Tomasz Kramkowski <tk@the-tk.com> | 2018-10-19 23:42:59 +0300 |
---|---|---|
committer | Tomasz Kramkowski <tk@the-tk.com> | 2018-10-19 23:42:59 +0300 |
commit | a5262a9504d0ad264d93e1761f5a4123e524cc87 (patch) | |
tree | 28b147973149f860007f8ef78e5f9af890ea3e33 /mtl.c | |
parent | 63a4ed57bae7a7ff8c497380cd3353badea15806 (diff) | |
download | faqe-a5262a9504d0ad264d93e1761f5a4123e524cc87.tar.gz faqe-a5262a9504d0ad264d93e1761f5a4123e524cc87.tar.xz faqe-a5262a9504d0ad264d93e1761f5a4123e524cc87.zip |
Implement specular mapping
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); } |