labyrinth
diff src/mesh.c @ 5:c8826e5ebec1
- changed every data loading function to return dummy objects instead of failing
- fixed mistake in AndroidManifest.xml
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 01 May 2015 05:58:41 +0300 |
parents | 45b91185b298 |
children |
line diff
1.1 --- a/src/mesh.c Fri May 01 04:38:43 2015 +0300 1.2 +++ b/src/mesh.c Fri May 01 05:58:41 2015 +0300 1.3 @@ -1,8 +1,34 @@ 1.4 #include <stdlib.h> 1.5 +#include <assert.h> 1.6 #include "opengl.h" 1.7 #include "mesh.h" 1.8 #include "objfile.h" 1.9 1.10 +static struct vec3 def_verts[] = { 1.11 + {-1, -1, 1}, {1, -1, 1}, {1, 1, 1}, {-1, -1, 1}, {1, 1, 1}, {-1, 1, 1}, 1.12 + {1, -1, 1}, {1, -1, -1}, {1, 1, -1}, {1, -1, 1}, {1, 1, -1}, {1, 1, 1}, 1.13 + {1, -1, -1}, {-1, -1, -1}, {-1, 1, -1}, {1, -1, -1}, {-1, 1, -1}, {1, 1, -1}, 1.14 + {-1, -1, -1}, {-1, -1, 1}, {-1, 1, 1}, {-1, -1, -1}, {-1, 1, 1}, {-1, 1, -1} 1.15 +}; 1.16 +#define FACEATTR(x, y, z) {x, y, z}, {x, y, z}, {x, y, z}, {x, y, z}, {x, y, z}, {x, y, z} 1.17 +static struct vec3 def_norm[] = { 1.18 + FACEATTR(0, 0, 1), 1.19 + FACEATTR(1, 0, 0), 1.20 + FACEATTR(0, 0, -1), 1.21 + FACEATTR(-1, 0, 0) 1.22 +}; 1.23 +static struct vec3 def_tc[] = { 1.24 + {0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 0, 0}, {1, 1, 0}, {0, 1, 0}, 1.25 + {0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 0, 0}, {1, 1, 0}, {0, 1, 0}, 1.26 + {0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 0, 0}, {1, 1, 0}, {0, 1, 0}, 1.27 + {0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 0, 0}, {1, 1, 0}, {0, 1, 0} 1.28 +}; 1.29 + 1.30 +static struct mesh def_mesh = { 1.31 + def_verts, def_norm, def_tc, 1.32 + sizeof def_verts / sizeof *def_verts 1.33 +}; 1.34 + 1.35 /* use objfile to load mesh data (vertices, normals, and texcoords) 1.36 * from a wavefront|OBJ file. 1.37 */ 1.38 @@ -13,7 +39,7 @@ 1.39 struct objfile *obj; 1.40 1.41 if(!(obj = objf_load(fname))) { 1.42 - return 0; 1.43 + return &def_mesh; 1.44 } 1.45 m = malloc(sizeof *m); 1.46 m->num_verts = objf_vertex_count(obj); 1.47 @@ -44,7 +70,7 @@ 1.48 1.49 void free_mesh(struct mesh *m) 1.50 { 1.51 - if(m) { 1.52 + if(m && m != &def_mesh) { 1.53 free(m->vert); 1.54 free(m->norm); 1.55 free(m->tc);