-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglgrid.h
More file actions
80 lines (62 loc) · 2.05 KB
/
glgrid.h
File metadata and controls
80 lines (62 loc) · 2.05 KB
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
#ifndef GLGRID_HEADER
#define GLGRID_HEADER
#include "common.h"
#include "math.h"
#include "xbuf.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ----------------------------------------------------------- */
/* IFRect methods */
/* */
/* Abstract: */
/* IFRect_t is a C struct which contains a Rect with FLOAT */
/* and INT format */
/* */
/* use IFRectInt2Float or IFRectFloat2Int to fill IFRect_t */
/* accordignly */
/* */
/* ----------------------------------------------------------- */
typedef struct {
float x;
float y;
float width;
float height;
int ix;
int iy;
int iwidth;
int iheight;
} IFRect_t;
INLINE_METHOD void IFRectInt2Float(IFRect_t* rect) {
rect->x = (float)rect->ix;
rect->y = (float)rect->iy;
rect->width = (float)rect->iwidth;
rect->height = (float)rect->iheight;
}
INLINE_METHOD void IFRectFloat2Int(IFRect_t* rect) {
rect->ix = (int)floor(rect->x);
rect->iy = (int)floor(rect->y);
rect->iwidth = (int)ceil(rect->width);
rect->iheight = (int)ceil(rect->height);
}
/* ----------------------------------------------------------- */
/* Grid_t methods */
/* ----------------------------------------------------------- */
typedef struct {
Buffer_t * src;
IFRect_t rect;
int count;
float* vertices; // count*3 : X Y Z
float* uvs; // count*2 : U V
} Grid_t;
typedef enum {
RGB_TEXTURE_MODE,
FLOAT_TEXTURE_MODE
} TextureMode_t;
Grid_t CreateGLGrid(Buffer_t * buffer, int rows);
void FreeGLGrid(Grid_t* grid);
Buffer_t * RenderGLGrid(Grid_t * grid, TextureMode_t mode);
#ifdef __cplusplus
}
#endif
#endif //GLGRID_HEADER