]> git.lizzy.rs Git - dragonblocks_alpha.git/blob - src/mesh.h
a7b11affca4be83f3680c0fcfd36cdc8a5ef73d3
[dragonblocks_alpha.git] / src / mesh.h
1 #ifndef _MESH_H_
2 #define _MESH_H_
3
4 #include <GL/glew.h>
5 #include <GL/gl.h>
6 #include <linmath.h/linmath.h>
7 #include <stdbool.h>
8 #include "array.h"
9 #include "shaders.h"
10 #include "types.h"
11
12 typedef struct
13 {
14         GLfloat x, y, z;
15         GLfloat s, t;
16 } __attribute__((packed)) Vertex;
17
18 typedef struct
19 {
20         GLuint texture;
21         Array vertices;
22 } Face;
23
24 typedef struct
25 {
26         Face *current;
27         Array faces;
28 } VertexBuffer;
29
30 typedef struct
31 {
32         GLuint VAO, VBO;
33         GLuint texture;
34         Vertex *vertices;
35         GLuint vertices_count;
36 } Mesh;
37
38 typedef struct
39 {
40         v3f pos, rot, scale;
41         f32 angle;
42         bool visible;
43         mat4x4 transform;
44         bool remove;
45         Mesh **meshes;
46         size_t meshes_count;
47 } MeshObject;
48
49 struct Scene;
50
51 VertexBuffer vertexbuffer_create();
52 void vertexbuffer_set_texture(VertexBuffer *buffer, GLuint texture);
53 void vertexbuffer_add_vertex(VertexBuffer *buffer, Vertex *vertex);
54
55 MeshObject *meshobject_create(VertexBuffer buffer, struct Scene *scene, v3f pos);
56 void meshobject_delete(MeshObject *obj);
57 void meshobject_transform(MeshObject *obj);
58 void meshobject_render(MeshObject *obj, ShaderProgram *prog);
59
60 #endif