goat3d
diff generators/goatprim/main.c @ 16:cb6c1a945a11
goat3d is starting to become functional inch by inch
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 26 Sep 2013 14:16:09 +0300 |
parents | |
children | 1d85d7dd0038 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/generators/goatprim/main.c Thu Sep 26 14:16:09 2013 +0300 1.3 @@ -0,0 +1,78 @@ 1.4 +#include <stdio.h> 1.5 +#include "goat3d.h" 1.6 + 1.7 +static struct goat3d_mesh *create_box(void); 1.8 + 1.9 +int main(void) 1.10 +{ 1.11 + struct goat3d *goat; 1.12 + struct goat3d_material *mtl; 1.13 + struct goat3d_mesh *mesh; 1.14 + 1.15 + goat = goat3d_create(); 1.16 + 1.17 + mtl = goat3d_create_mtl(); 1.18 + goat3d_set_mtl_name(mtl, "mat"); 1.19 + goat3d_set_mtl_attrib4f(mtl, GOAT3D_MAT_ATTR_DIFFUSE, 1, 0, 0, 1); 1.20 + goat3d_add_mtl(goat, mtl); 1.21 + 1.22 + mesh = create_box(); 1.23 + goat3d_add_mesh(goat, mesh); 1.24 + 1.25 + goat3d_setopt(goat, GOAT3D_OPT_SAVEXML, 1); 1.26 + goat3d_save(goat, "foo.xml"); 1.27 + 1.28 + goat3d_free(goat); 1.29 + return 0; 1.30 +} 1.31 + 1.32 +static struct goat3d_mesh *create_box(void) 1.33 +{ 1.34 + struct goat3d_mesh *mesh = goat3d_create_mesh(); 1.35 + 1.36 + goat3d_begin(mesh, GOAT3D_QUADS); 1.37 + // +X 1.38 + goat3d_normal3f(1, 0, 0); 1.39 + goat3d_vertex3f(-1, -1, 1); 1.40 + goat3d_vertex3f(-1, -1, -1); 1.41 + goat3d_vertex3f(-1, 1, -1); 1.42 + goat3d_vertex3f(-1, 1, 1); 1.43 + 1.44 + // -X 1.45 + goat3d_normal3f(-1, 0, 0); 1.46 + goat3d_vertex3f(-1, -1, -1); 1.47 + goat3d_vertex3f(-1, -1, 1); 1.48 + goat3d_vertex3f(-1, 1, 1); 1.49 + goat3d_vertex3f(-1, 1, -1); 1.50 + 1.51 + // +Y 1.52 + goat3d_normal3f(0, 1, 0); 1.53 + goat3d_vertex3f(-1, 1, 1); 1.54 + goat3d_vertex3f(1, 1, 1); 1.55 + goat3d_vertex3f(1, 1, -1); 1.56 + goat3d_vertex3f(-1, 1, -1); 1.57 + 1.58 + // -Y 1.59 + goat3d_normal3f(0, -1, 0); 1.60 + goat3d_vertex3f(-1, -1, -1); 1.61 + goat3d_vertex3f(1, -1, -1); 1.62 + goat3d_vertex3f(1, -1, 1); 1.63 + goat3d_vertex3f(-1, -1, 1); 1.64 + 1.65 + // +Z 1.66 + goat3d_normal3f(0, 0, 1); 1.67 + goat3d_vertex3f(-1, -1, 1); 1.68 + goat3d_vertex3f(1, -1, 1); 1.69 + goat3d_vertex3f(1, -1, 1); 1.70 + goat3d_vertex3f(-1, -1, 1); 1.71 + 1.72 + // -Z 1.73 + goat3d_normal3f(0, 0, -1); 1.74 + goat3d_vertex3f(-1, -1, 1); 1.75 + goat3d_vertex3f(1, -1, 1); 1.76 + goat3d_vertex3f(1, -1, -1); 1.77 + goat3d_vertex3f(-1, -1, -1); 1.78 + goat3d_end(); 1.79 + 1.80 + return mesh; 1.81 +}