summaryrefslogtreecommitdiffstats
path: root/objloader.c
diff options
context:
space:
mode:
Diffstat (limited to 'objloader.c')
-rw-r--r--objloader.c43
1 files changed, 25 insertions, 18 deletions
diff --git a/objloader.c b/objloader.c
index 1f5eddd..1b2ba67 100644
--- a/objloader.c
+++ b/objloader.c
@@ -81,26 +81,28 @@ static void setup_opengl(ObjModel *model)
/* get the texture filename from obj */
char *fname = ObjGetPath(model->mtl->map_Ka); /* ambient texture map */
if (model->mtl != NULL)
+ {
printf("ambient texture map: %s\n", model->mtl->map_Ka);
- /* load texture */
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- pBytes = gltLoadTGA(fname, &iWidth, &iHeight, &iComponents, &eFormat);
- if (!pBytes)
- fprintf(stderr, "gltLoadTGA: failed to load texture!\n");
-
- /* load texture image */
- glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormat,
- GL_UNSIGNED_BYTE, pBytes);
- free(pBytes);
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glEnable(GL_TEXTURE_2D);
+ /* load texture */
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ pBytes = gltLoadTGA(fname, &iWidth, &iHeight, &iComponents, &eFormat);
+ if (!pBytes)
+ fprintf(stderr, "gltLoadTGA: failed to load texture!\n");
+
+ /* load texture image */
+ glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormat,
+ GL_UNSIGNED_BYTE, pBytes);
+ free(pBytes);
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glEnable(GL_TEXTURE_2D);
+ }
}
/* process SDL events */
@@ -223,6 +225,11 @@ int main(void)
char *memory = NULL;
size_t bytes = ObjLoadFile("./cube/cube.obj", &memory);
ObjModel *model = ObjLoadModel(memory, bytes);
+ if (!bytes || model == NULL)
+ {
+ fprintf(stderr, "obj file could not be loaded!\n");
+ exit(-1);
+ }
/* setup few stuff before rendring */
setup_opengl(model);