goat3d

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