goat3d
view src/goat3d.h @ 24:6b651613bd9f
fixed the windows stuff
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 28 Sep 2013 06:32:00 +0300 |
parents | f1b4c27382ce |
children | d0260d80ae09 |
line source
1 #ifndef GOAT3D_H_
2 #define GOAT3D_H_
4 #include <stdio.h>
5 #include <stdlib.h>
7 #define GOAT3D_MAT_ATTR_DIFFUSE "diffuse"
8 #define GOAT3D_MAT_ATTR_SPECULAR "specular"
9 #define GOAT3D_MAT_ATTR_SHININESS "shininess"
10 #define GOAT3D_MAT_ATTR_NORMAL "normal"
11 #define GOAT3D_MAT_ATTR_BUMP "bump"
12 #define GOAT3D_MAT_ATTR_REFLECTION "reflection"
13 #define GOAT3D_MAT_ATTR_TRANSMISSION "transmission"
14 #define GOAT3D_MAT_ATTR_IOR "ior"
16 enum goat3d_mesh_attrib {
17 GOAT3D_MESH_ATTR_VERTEX,
18 GOAT3D_MESH_ATTR_NORMAL,
19 GOAT3D_MESH_ATTR_TANGENT,
20 GOAT3D_MESH_ATTR_TEXCOORD,
21 GOAT3D_MESH_ATTR_SKIN_WEIGHT,
22 GOAT3D_MESH_ATTR_SKIN_MATRIX,
23 GOAT3D_MESH_ATTR_COLOR,
25 NUM_GOAT3D_MESH_ATTRIBS
26 };
28 /* immediate mode mesh construction primitive type */
29 enum goat3d_im_primitive {
30 GOAT3D_TRIANGLES,
31 GOAT3D_QUADS
32 };
35 enum goat3d_option {
36 GOAT3D_OPT_SAVEXML, /* save in XML format */
38 NUM_GOAT3D_OPTIONS
39 };
41 struct goat3d;
42 struct goat3d_material;
43 struct goat3d_mesh;
44 struct goat3d_light;
45 struct goat3d_camera;
46 struct goat3d_node;
48 struct goat3d_io {
49 void *cls; /* closure data */
51 long (*read)(void *buf, size_t bytes, void *uptr);
52 long (*write)(const void *buf, size_t bytes, void *uptr);
53 long (*seek)(long offs, int whence, void *uptr);
54 };
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
60 /* construction/destruction */
61 struct goat3d *goat3d_create(void);
62 void goat3d_free(struct goat3d *g);
64 void goat3d_setopt(struct goat3d *g, enum goat3d_option opt, int val);
65 int goat3d_getopt(const struct goat3d *g, enum goat3d_option opt);
67 /* load/save */
68 int goat3d_load(struct goat3d *g, const char *fname);
69 int goat3d_save(const struct goat3d *g, const char *fname);
71 int goat3d_load_file(struct goat3d *g, FILE *fp);
72 int goat3d_save_file(const struct goat3d *g, FILE *fp);
74 int goat3d_load_io(struct goat3d *g, struct goat3d_io *io);
75 int goat3d_save_io(const struct goat3d *g, struct goat3d_io *io);
77 /* misc scene properties */
78 int goat3d_set_name(struct goat3d *g, const char *name);
79 const char *goat3d_get_name(const struct goat3d *g);
81 void goat3d_set_ambient(struct goat3d *g, const float *ambient);
82 void goat3d_set_ambient3f(struct goat3d *g, float ar, float ag, float ab);
83 const float *goat3d_get_ambient(const struct goat3d *g);
85 /* materials */
86 struct goat3d_material *goat3d_create_mtl(void);
87 void goat3d_destroy_mtl(struct goat3d_material *mtl);
89 void goat3d_set_mtl_name(struct goat3d_material *mtl, const char *name);
90 const char *goat3d_get_mtl_name(const struct goat3d_material *mtl);
92 void goat3d_set_mtl_attrib(struct goat3d_material *mtl, const char *attrib, const float *val);
93 void goat3d_set_mtl_attrib1f(struct goat3d_material *mtl, const char *attrib, float val);
94 void goat3d_set_mtl_attrib3f(struct goat3d_material *mtl, const char *attrib, float r, float g, float b);
95 void goat3d_set_mtl_attrib4f(struct goat3d_material *mtl, const char *attrib, float r, float g, float b, float a);
96 const float *goat3d_get_mtl_attrib(struct goat3d_material *mtl, const char *attrib);
98 void goat3d_set_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib, const char *mapname);
99 const char *goat3d_get_mtl_attrib_map(struct goat3d_material *mtl, const char *attrib);
101 void goat3d_add_mtl(struct goat3d *g, struct goat3d_material *mtl);
103 /* meshes */
104 struct goat3d_mesh *goat3d_create_mesh(void);
105 void goat3d_destroy_mesh(struct goat3d_mesh *mesh);
107 void goat3d_set_mesh_name(struct goat3d_mesh *mesh, const char *name);
108 const char *goat3d_get_mesh_name(const struct goat3d_mesh *mesh);
110 void goat3d_set_mesh_mtl(struct goat3d_mesh *mesh, struct goat3d_material *mtl);
111 struct goat3d_material *goat3d_get_mesh_mtl(struct goat3d_mesh *mesh);
113 int goat3d_get_mesh_attrib_count(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib);
114 int goat3d_get_mesh_face_count(struct goat3d_mesh *mesh);
116 /* sets all the data for a single vertex attribute array in one go.
117 * vnum is the number of *vertices* to be set, not the number of floats, ints or whatever
118 * data is expected to be something different depending on the attribute:
119 * - GOAT3D_MESH_ATTR_VERTEX - 3 floats per vertex
120 * - GOAT3D_MESH_ATTR_NORMAL - 3 floats per vertex
121 * - GOAT3D_MESH_ATTR_TANGENT - 3 floats per vertex
122 * - GOAT3D_MESH_ATTR_TEXCOORD - 2 floats per vertex
123 * - GOAT3D_MESH_ATTR_SKIN_WEIGHT - 4 floats per vertex
124 * - GOAT3D_MESH_ATTR_SKIN_MATRIX - 4 ints per vertex
125 * - GOAT3D_MESH_ATTR_COLOR - 4 floats per vertex
126 */
127 void goat3d_set_mesh_attribs(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, const void *data, int vnum);
128 /* returns a pointer to the beginning of the requested mesh attribute array */
129 void *goat3d_get_mesh_attribs(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib);
130 /* returns a pointer to the requested mesh attribute */
131 void *goat3d_get_mesh_attrib(struct goat3d_mesh *mesh, enum goat3d_mesh_attrib attrib, int idx);
133 /* sets all the faces in one go. data is an array of 3 int vertex indices per face */
134 void goat3d_set_mesh_faces(struct goat3d_mesh *mesh, const int *data, int fnum);
135 /* returns a pointer to the beginning of the face index array */
136 int *goat3d_get_mesh_faces(struct goat3d_mesh *mesh);
137 /* returns a pointer to a face index */
138 int *goat3d_get_mesh_face(struct goat3d_mesh *mesh, int idx);
140 /* immediate mode OpenGL-like interface for setting mesh data
141 * NOTE: using this interface will result in no vertex sharing between faces
142 * NOTE2: the immedate mode interface is not thread-safe, either use locks, or don't
143 * use it at all in multithreaded situations.
144 */
145 void goat3d_begin(struct goat3d_mesh *mesh, enum goat3d_im_primitive prim);
146 void goat3d_end(void);
147 void goat3d_vertex3f(float x, float y, float z);
148 void goat3d_normal3f(float x, float y, float z);
149 void goat3d_tangent3f(float x, float y, float z);
150 void goat3d_texcoord2f(float x, float y);
151 void goat3d_skin_weight4f(float x, float y, float z, float w);
152 void goat3d_skin_matrix4i(int x, int y, int z, int w);
153 void goat3d_color3f(float x, float y, float z);
154 void goat3d_color4f(float x, float y, float z, float w);
156 void goat3d_add_mesh(struct goat3d *g, struct goat3d_mesh *mesh);
158 int goat3d_get_mesh_count(struct goat3d *g);
159 struct goat3d_mesh *goat3d_get_mesh(struct goat3d *g, int idx);
161 #ifdef __cplusplus
162 }
163 #endif
165 #endif /* GOAT3D_H_ */