aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2018-05-04 20:00:07 +0100
committerTomasz Kramkowski <tk@the-tk.com>2018-05-04 20:05:59 +0100
commitb97f4f6e1083a939283505f3c324f70b6bf5341f (patch)
treefbd62c25ef2308616dd0503134ca84a444244307
parentd1d4c8678b313708b91ba0342db84d33c0bb0677 (diff)
downloadfaqe-b97f4f6e1083a939283505f3c324f70b6bf5341f.tar.gz
faqe-b97f4f6e1083a939283505f3c324f70b6bf5341f.tar.xz
faqe-b97f4f6e1083a939283505f3c324f70b6bf5341f.zip
Move assets to an assets subdirectory and simplify model loading
-rw-r--r--faqe.c28
-rw-r--r--mtl.c2
2 files changed, 18 insertions, 12 deletions
diff --git a/faqe.c b/faqe.c
index e51aaf0..d1f6402 100644
--- a/faqe.c
+++ b/faqe.c
@@ -30,6 +30,20 @@ void viewport(GLuint proj, int width, int height)
gl_uni_setm4fv(proj, 1, GL_FALSE, pers[0]);
}
+void loadmodel(struct model *mdl, char *name)
+{
+ FILE *f;
+ struct fmd fmd;
+
+ f = fopen(name, "rb");
+ if (f == NULL)
+ eprintf("Could not open '%s':", name);
+ fmd_load(&fmd, f);
+ fclose(f);
+ model_load(mdl, &fmd);
+ fmd_free(&fmd);
+}
+
int main(int argc, char **argv)
{
bool running = true;
@@ -39,9 +53,7 @@ int main(int argc, char **argv)
struct {
GLint model, view, proj, tex, light;
} uni;
- FILE *cube_file;
- struct fmd cube_fmd;
- struct model cube_model;
+ struct model mdl;
struct camera cam = { .pos = { 0.0, 0.0, 3.0 }, .yaw = -PI/2 };
struct {
bool w, a, s, d, spc, lct;
@@ -74,13 +86,7 @@ int main(int argc, char **argv)
gl_load((gl_loadfunc *)SDL_GL_GetProcAddress);
- cube_file = fopen("cube.fmd", "rb");
- if (cube_file == NULL)
- eprintf("Could not open 'cube.fmd':");
- fmd_load(&cube_fmd, cube_file);
- model_load(&cube_model, &cube_fmd);
- fmd_free(&cube_fmd);
- fclose(cube_file);
+ loadmodel(&mdl, "assets/utah.fmd");
prog = glprog_load((struct shdrdat []){
{ GL_VERTEX_SHADER, vert_glsl.data, vert_glsl.size },
@@ -178,7 +184,7 @@ int main(int argc, char **argv)
gl_uni_setm4fv(uni.view, 1, GL_FALSE, view[0]);
gl_uni_setm4fv(uni.model, 1, GL_FALSE, model[0]);
gl_uni_set3fv(uni.light, 1, lipos);
- model_render(&cube_model);
+ model_render(&mdl);
gl_va_bind(0);
SDL_GL_SwapWindow(win);
diff --git a/mtl.c b/mtl.c
index 42e5de2..3b46ce7 100644
--- a/mtl.c
+++ b/mtl.c
@@ -35,7 +35,7 @@ int mtl_load(char *name)
snprintf(m->name, sizeof m->name, "%s", name);
- snprintf(loc, sizeof loc, "./tex/%s.png", name);
+ snprintf(loc, sizeof loc, "assets/%s.diff.png", name);
f = fopen(loc, "rb");
if (f == NULL)
eprintf("Could not open '%s':", loc);