-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminigl.h
190 lines (164 loc) · 4.33 KB
/
minigl.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/**
* minigl.h
* -------------------------------
* This file defines the API to be implemented for MiniGL.
*/
#ifndef __MINIGL_H__
#define __MINIGL_H__
typedef int MGLint;
typedef unsigned char MGLbyte;
typedef unsigned int MGLsize;
typedef unsigned int MGLpixel;
typedef float MGLfloat;
typedef bool MGLbool;
typedef enum {
MGL_MODELVIEW,
MGL_PROJECTION
} MGLmatrix_mode;
typedef enum {
MGL_TRIANGLES,
MGL_QUADS
} MGLpoly_mode;
inline MGLpixel Make_Pixel(int r, int g, int b)
{
return (r<<24)|(g<<16)|(b<<8)|0xff;
}
inline void From_Pixel(MGLpixel p, int& r, int& g, int& b)
{
r = (p>>16)&0xff;
g = (p>>8)&0xff;
b = p&0xff;
}
/**
* Read pixel data starting with the pixel at coordinates
* (0, 0), up to (width, height), into the array
* pointed to by data. The boundaries are lower-inclusive,
* that is, a call with width = height = 1 would just read
* the pixel at (0, 0).
*
* Rasterization and z-buffering should be performed when
* this function is called, so that the data array is filled
* with the actual pixel values that should be displayed on
* the two-dimensional screen.
*/
void mglReadPixels(MGLsize width,
MGLsize height,
MGLpixel *data);
/**
* Start specifying the vertices for a group of primitives,
* whose type is specified by the given mode.
*/
void mglBegin(MGLpoly_mode mode);
/**
* Stop specifying the vertices for a group of primitives.
*/
void mglEnd();
/**
* Specify a two-dimensional vertex; the x- and y-coordinates
* are explicitly specified, while the z-coordinate is assumed
* to be zero. Must appear between calls to mglBegin() and
* mglEnd().
*/
void mglVertex2(MGLfloat x,
MGLfloat y);
/**
* Specify a three-dimensional vertex. Must appear between
* calls to mglBegin() and mglEnd().
*/
void mglVertex3(MGLfloat x,
MGLfloat y,
MGLfloat z);
/**
* Set the current matrix mode (modelview or projection).
*/
void mglMatrixMode(MGLmatrix_mode mode);
/**
* Push a copy of the current matrix onto the stack for the
* current matrix mode.
*/
void mglPushMatrix();
/**
* Pop the top matrix from the stack for the current matrix
* mode.
*/
void mglPopMatrix();
/**
* Replace the current matrix with the identity.
*/
void mglLoadIdentity();
/**
* Replace the current matrix with an arbitrary 4x4 matrix,
* specified in column-major order. That is, the matrix
* is stored as:
*
* ( a0 a4 a8 a12 )
* ( a1 a5 a9 a13 )
* ( a2 a6 a10 a14 )
* ( a3 a7 a11 a15 )
*
* where ai is the i'th entry of the array.
*/
void mglLoadMatrix(const MGLfloat *matrix);
/**
* Multiply the current matrix by an arbitrary 4x4 matrix,
* specified in column-major order. That is, the matrix
* is stored as:
*
* ( a0 a4 a8 a12 )
* ( a1 a5 a9 a13 )
* ( a2 a6 a10 a14 )
* ( a3 a7 a11 a15 )
*
* where ai is the i'th entry of the array.
*/
void mglMultMatrix(const MGLfloat *matrix);
/**
* Multiply the current matrix by the translation matrix
* for the translation vector given by (x, y, z).
*/
void mglTranslate(MGLfloat x,
MGLfloat y,
MGLfloat z);
/**
* Multiply the current matrix by the rotation matrix
* for a rotation of (angle) degrees about the vector
* from the origin to the point (x, y, z).
*/
void mglRotate(MGLfloat angle,
MGLfloat x,
MGLfloat y,
MGLfloat z);
/**
* Multiply the current matrix by the scale matrix
* for the given scale factors.
*/
void mglScale(MGLfloat x,
MGLfloat y,
MGLfloat z);
/**
* Multiply the current matrix by the perspective matrix
* with the given clipping plane coordinates.
*/
void mglFrustum(MGLfloat left,
MGLfloat right,
MGLfloat bottom,
MGLfloat top,
MGLfloat near,
MGLfloat far);
/**
* Multiply the current matrix by the orthographic matrix
* with the given clipping plane coordinates.
*/
void mglOrtho(MGLfloat left,
MGLfloat right,
MGLfloat bottom,
MGLfloat top,
MGLfloat near,
MGLfloat far);
/**
* Set the current color for drawn shapes.
*/
void mglColor(MGLfloat red,
MGLfloat green,
MGLfloat blue);
#endif