-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathestk.h
159 lines (129 loc) · 3.48 KB
/
estk.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#ifndef ESTK_H
#define ESTK_H
#include <stdlib.h>
#include <SDL/SDL_mixer.h>
enum esBool {
ES_FALSE = 0,
ES_TRUE = 1,
};
// Misc
void _esCheckGlError();
#define esCheckGlError() _esCheckGlError(__FILE__, __LINE__)
// Game loop
void esGameInit(int screen_width, int screen_height);
void esGameGlSwap(void);
void esGameLoop(void (*frame)(float t), void (*exit)(), int frame_rate);
void esGameLoopQuit(void);
void esGameRegisterKey(int sdlkey, void (*callback)(int key, int down));
// Shader
typedef int esUniform;
#define UNIFORMS_MAX 10
typedef struct {
int glprogram;
esUniform uniforms[UNIFORMS_MAX];
} esShader;
int esShaderLoad(esShader *shader,
const char *vert_file, const char *frag_file);
void esShaderUse(const esShader *shader);
void esShaderUnload(esShader *shader);
int esShaderUniformRegister(esShader *shader,
esUniform reg, const char *name);
int esShaderUniformGl(esShader *shader, esUniform reg);
// Geometry buffer
#define GEOBUFS_MAX 8
enum esGeoBufType {
GEOBUF_STATIC,
GEOBUF_DYNAMIC,
GEOBUF_STREAM,
};
typedef struct {
unsigned int glbuf;
} esGeoBuf;
void esGeoBufCreate(esGeoBuf *buf);
void esGeoBufCopy(esGeoBuf *buf,
const void *data, size_t size, enum esGeoBufType type);
void esGeoBufDelete(esGeoBuf *buf);
// Geometry
enum esGeoDataType {
GEODATA_FLOAT,
GEODATA_INT,
GEODATA_BYTE,
GEODATA_UBYTE,
};
typedef struct {
int bufcount;
struct {
esGeoBuf *geobuf;
enum esGeoDataType datatype;
int elements;
size_t offset, stride;
enum esBool normalized;
} buf[GEOBUFS_MAX];
} esGeo;
void esGeoReset(esGeo *geo, int bufcount);
void esGeoPoint(esGeo *geo, int id, esGeoBuf *geobuf,
enum esGeoDataType datatype, int elements,
size_t offset, size_t stride, enum esBool normalized);
void esGeoRender(const esGeo *geo, int vertices);
// Projection
typedef struct { float x, y, z; } esVec3;
void esProjOrtho(float *mat, float x0, float y0, float x1, float y1);
void esProjPerspective(
float *mat, float fov, float screenratio, float near, float far,
esVec3 eye, esVec3 at, esVec3 up);
// Texture
enum esTextureMipmap {
TEX_NONE,
TEX_LINEAR,
};
typedef struct {
int w, h;
int gltexture;
} esTexture;
int esTextureLoad(esTexture *tex, const char *file_name,
enum esTextureMipmap min, enum esTextureMipmap mag);
void esTextureUse(esTexture *tex);
void esTextureUnload(esTexture *tex);
// Font
typedef struct {
esTexture *texture;
esShader *shader;
int vert_count;
int buf_size, buf_alloc;
esGeoBuf geo_buf;
esGeo geo;
void *buf;
} esFont;
int esFontCreate(esFont *ft, esTexture *tex, esShader *shad,
int attrib_loc, int attrib_uv, int addition_attribs);
void esFontDelete(esFont *ft);
void esFontAddText(esFont *ft, float offset_x, float offset_y,
const char *fmt, ...);
void esFontRender(esFont *ft);
void esFontClearBuf(esFont *ft);
// Framebuffer
typedef struct {
int dimension;
int gl_fb, gl_tex, gl_depth;
} esFrameBuffer;
int esFrameBufferCreate(esFrameBuffer *fb, int dimension,
enum esTextureMipmap min, enum esTextureMipmap mag);
void esFrameBufferDelete(esFrameBuffer *fb);
void esFrameBufferSet(esFrameBuffer *fb);
void esFrameBufferUnSet(void);
void esFrameBufferBind(esFrameBuffer *fb);
// Audio
typedef struct {
Mix_Chunk *chunk;
} esSound;
int esSoundLoad(esSound *sn, const char *file_name);
void esSoundUnLoad(esSound *sn);
void esSoundPlay(esSound *sn);
typedef struct {
Mix_Music *music;
} esMusic;
int esMusicLoad(esMusic *mu, const char *file_name);
void esMusicUnLoad(esMusic *mu);
void esMusicPlay(esMusic *mu);
void esMusicHalt(void);
#endif