diff options
author | Kyle K <kylek389@gmail.com> | 2010-10-16 15:17:08 -0500 |
---|---|---|
committer | Kamil Kaminski <kamilkss@gmail.com> | 2010-10-16 15:17:08 -0500 |
commit | 663a667df86e36acaade5070305692f3c9199879 (patch) | |
tree | cab2230d0bf4b142969a409128e610163ca4b486 /objloader.c | |
parent | 9e4401021950b72bbdf2e1db67ad393966bbd3df (diff) | |
download | OBJLoader-663a667df86e36acaade5070305692f3c9199879.tar.gz OBJLoader-663a667df86e36acaade5070305692f3c9199879.tar.bz2 OBJLoader-663a667df86e36acaade5070305692f3c9199879.zip |
Add more error checking
Diffstat (limited to 'objloader.c')
-rw-r--r-- | objloader.c | 43 |
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); |