goat3d
view 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 source
1 #include <stdio.h>
2 #include "goat3d.h"
4 static struct goat3d_mesh *create_box(void);
6 int main(void)
7 {
8 struct goat3d *goat;
9 struct goat3d_material *mtl;
10 struct goat3d_mesh *mesh;
12 goat = goat3d_create();
14 mtl = goat3d_create_mtl();
15 goat3d_set_mtl_name(mtl, "mat");
16 goat3d_set_mtl_attrib4f(mtl, GOAT3D_MAT_ATTR_DIFFUSE, 1, 0, 0, 1);
17 goat3d_add_mtl(goat, mtl);
19 mesh = create_box();
20 goat3d_add_mesh(goat, mesh);
22 goat3d_setopt(goat, GOAT3D_OPT_SAVEXML, 1);
23 goat3d_save(goat, "foo.xml");
25 goat3d_free(goat);
26 return 0;
27 }
29 static struct goat3d_mesh *create_box(void)
30 {
31 struct goat3d_mesh *mesh = goat3d_create_mesh();
33 goat3d_begin(mesh, GOAT3D_QUADS);
34 // +X
35 goat3d_normal3f(1, 0, 0);
36 goat3d_vertex3f(-1, -1, 1);
37 goat3d_vertex3f(-1, -1, -1);
38 goat3d_vertex3f(-1, 1, -1);
39 goat3d_vertex3f(-1, 1, 1);
41 // -X
42 goat3d_normal3f(-1, 0, 0);
43 goat3d_vertex3f(-1, -1, -1);
44 goat3d_vertex3f(-1, -1, 1);
45 goat3d_vertex3f(-1, 1, 1);
46 goat3d_vertex3f(-1, 1, -1);
48 // +Y
49 goat3d_normal3f(0, 1, 0);
50 goat3d_vertex3f(-1, 1, 1);
51 goat3d_vertex3f(1, 1, 1);
52 goat3d_vertex3f(1, 1, -1);
53 goat3d_vertex3f(-1, 1, -1);
55 // -Y
56 goat3d_normal3f(0, -1, 0);
57 goat3d_vertex3f(-1, -1, -1);
58 goat3d_vertex3f(1, -1, -1);
59 goat3d_vertex3f(1, -1, 1);
60 goat3d_vertex3f(-1, -1, 1);
62 // +Z
63 goat3d_normal3f(0, 0, 1);
64 goat3d_vertex3f(-1, -1, 1);
65 goat3d_vertex3f(1, -1, 1);
66 goat3d_vertex3f(1, -1, 1);
67 goat3d_vertex3f(-1, -1, 1);
69 // -Z
70 goat3d_normal3f(0, 0, -1);
71 goat3d_vertex3f(-1, -1, 1);
72 goat3d_vertex3f(1, -1, 1);
73 goat3d_vertex3f(1, -1, -1);
74 goat3d_vertex3f(-1, -1, -1);
75 goat3d_end();
77 return mesh;
78 }