Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
blob: 487377a09bf4f2a0e0f0618ee9ca79a081cc9b04 (plain)
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
/*
   render/gl.h
   This file is part of the Osirion project and is distributed under
   the terms of the GNU General Public License version 2
*/

#ifndef __INCLUDED_RENDER_GL_H__
#define __INCLUDED_RENDER_GL_H__

#include "sys/sys.h"

#include "SDL2/SDL_opengl.h"

#include "math/vector2f.h"
#include "math/vector3f.h"
#include "math/matrix4f.h"
#include "math/axis.h"
#include "math/color.h"

#ifdef _WIN32

#ifndef GL_RESCALE_NORMAL
#define GL_RESCALE_NORMAL	0x803A
#endif

#ifndef GL_TEXTURE_MAX_LEVEL
#define GL_TEXTURE_MAX_LEVEL	0x813D
#endif

#ifndef GL_GENERATE_MIPMAP
#define GL_GENERATE_MIPMAP	0x8191
#endif

#ifndef GL_REFLECTION_MAP
#define GL_REFLECTION_MAP	0x8512
#endif

#ifndef GL_CLAMP_TO_EDGE
#define GL_CLAMP_TO_EDGE	0x812F
#endif

#ifndef GL_ARRAY_BUFFER
#define GL_ARRAY_BUFFER 	0x8892
#endif

#ifndef GL_STATIC_DRAW
#define GL_STATIC_DRAW		0x88E4
#endif

#endif // _WIN32

/*
 * @brief wrapper class for OpenGL functions
 * The gl class accesses the OpenGL library functions
 * through function pointers.
 * This allows loading the library at runtime 
 * and makes static builds possible
 */
/*
class GL {

private:
	typedef void (* APIENTRY gl_genbuffers_func)(GLuint count, GLuint *id);
	typedef void (* APIENTRY gl_deletebuffers_func)(GLuint count, GLuint *id);
	typedef void (* APIENTRY gl_bindbuffer_func)(GLenum target, GLuint id);
	typedef void (* APIENTRY gl_bufferdata_func)(GLenum target, GLsizei size, const GLvoid *data, GLenum usage);

}
*/
/// wrapper namespace for OpenGL operations
/** The gl namespace provides a wrapper to the OpenGL library functions.
 *  All methods take floats or Vector3f and Color as parameters.
 */
namespace gl
{
/// name of the hardware OpenGL renderer
std::string renderer();
/// vender of the system OpenGL implementation
std::string vendor();
/// version of the system OpenGL implementation
std::string version();
/// Opengl Extensions string
std::string extensions();

/// enum to denote Vertex drawing modes
enum Primitive {
	Points = GL_POINTS,
	Lines = GL_LINES,
	LineStrip = GL_LINE_STRIP,
	LineLoop = GL_LINE_LOOP,
	Triangles = GL_TRIANGLES,
	TriangleStrip = GL_TRIANGLE_STRIP,
	TriangleFan = GL_TRIANGLE_FAN,
	Quads = GL_QUADS,
	QuadStrip = GL_QUAD_STRIP,
	Polygon = GL_POLYGON
};

/// glViewPort
void viewport(GLint x, GLint y, GLsizei width, GLsizei height);

/// set the color used to clear to buffer
void clearcolor(math::Color const &color);

void clearcolor(const float r, const float g, const float b, const float a);

/// clear buffers to preset values
void clear(GLbitfield mask);

/// glMatrixMode
void matrixmode(GLenum mode);

/// glEnable
void enable(GLenum cap);

/// glDisable
void disable(GLenum cap);

/// glEnableClientState
void enableclientstate(GLenum cap);

/// glDisableClientState
void disableclientstate(GLenum cap);

/// glGetIntegerv
void getinteger(GLenum pname, GLint* params);

/// glShadeModel
void shademodel(GLenum mode);

/// glCullFace
void cullface(GLenum mode);

/// glFrontFace
void frontface(GLenum mode);

/// glDepthMask
void depthmask(GLenum mode);

/// glDepthFunc
void depthfunc(GLenum func);

/// glBlendFunc
void blendfunc(GLenum sfactor, GLenum dfactor);

/// glAlphaFunc
void alphafunc(GLenum func, GLclampf ref);

/// glPolygonOffset
void polygonoffset(GLfloat factor, GLfloat units);

/// Delimite the start of a sequence of verteces describing a primitive or group of primitives
/** @param primitive The type of drawing primitive
 *  @see end()
 */
void begin(Primitive primitive);

/// delimit the end of a sequence of verteces describing a primitive or group of primitives
/** @see begin()
 */
void end();

/// Add the next vertex the the current drawing operation
/** From the glVertex() description:
 *  vertex() commands are used within begin()/end() pairs to specify point,
 *  line, and polygon vertices.  The current color, normal, and texture
 *  coordinates are associated with the vertex when vertex() is called.
 */
void vertex(const math::Vector2f& vector);
void vertex(const float x, const float y);
void vertex(const math::Vector3f& vector);
void vertex(const float x, const float y, const float z);
void vertex(const GLfloat* v);

/// glTexCoord
void texcoord(const float x, const float y);

/// glTexCoord
void texcoord(const math::Vector2f& vector);

/// glTexCoord
void texcoord(const float x, const float y, const float z);

/// glTexCoordPointer
void texcoordpointer(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer);

/// glNormalPointer
void normalpointer(GLenum type, GLsizei stride, const GLvoid* pointer);

/// glVertexPointer
void vertexpointer(GLint size, GLenum type, GLsizei stride, const GLvoid* pointer);

/// glInterleavedArrays
void interleavedarrays(GLenum format, GLsizei stride, const GLvoid* pointer);

/// glNormal
void normal(const math::Vector3f & vector);

void normal(const float x, const float y, const float z);

/// multiply the current matrix by a general rotation matrix
/** @param angle The angle of the rotation, in degrees [0-360]
 *  @param vector The rotation axes, relative to the origin (0,0,0)
 */
void rotate(const float angle, const math::Vector3f& vector);

/// multiply the current matrix by a general rotation matrix
/** @param angle The angle of the rotation, in degrees
 *  @param x The x-coordinate of the rotation vector
 *  @param y The y-coordinate of the rotation vector
 *  @param z The z-coordinate of the rotation vector
 */
void rotate(const float angle, const float x, const float y, const float z);

/// multiply the current matrix by a general translation matrix
/** @param vector The translation vector, relative to the origin (0,0,0)
 */
void translate(const math::Vector3f& vector);

/// multiply the current matrix by a general translation matrix
/** @param x The x-coordinate of the translation vector
 *  @param y The y-coordinate of the translation vector
 *  @param z The z-coordinate of the translation vector
 */
void translate(const float x, const float y, const float z);

/// multiply the current matrix by a general scaling matrix
/** @param vector The scale factor for all 3 axes
 */
void scale(const math::Vector3f& vector);

/// multiply the current matrix by a general scaling matrix
/** @param x x-scaling factor
 * @param y y-scaling factor
 * @param z z-scaling factor
 */
void scale(const float x, const float y, const float z);

/// multiply the current matrix with a coordinate system transformation
void multmatrix(const math::Axis & axis);

/// multiply the current matrix with a 4x4 float matrix
void multmatrix(const math::Matrix4f & matrix);

/// specify the drawing color for the next GL functions
/** @param color the new drawing color
 */
void color(math::Color const & color);

/** @param r red value of the new drawing color
 *  @param g green value of the new drawing color
 *  @param b blue value of the new drawing color
 *  @param a alpha value of the new drawing color
 */
void color(const float r, const float g, const float b, const float a = 1.0f);

/// specify the specular reflectivity color
void specular(math::Color const & specular);

/// specify the shininess
void shininess(math::Color const & shine);

/// Push the current transformation matrix to the stack
void push();

/// Replace the transformation matrix with the top from the stack
void pop();

/// Replace the transformation matrix with the identity matrtix
void loadidentity();

/// Perspective matrix
void frustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble znear, GLdouble zfar);

/// Light source parameters
void light(GLenum light, GLenum pname, GLfloat param);
void light(GLenum light, GLenum pname, GLint param);
void light(GLenum light, GLenum pname, const GLfloat* params);
void light(GLenum light, GLenum pname, const GLint* params);

/// Light model
void lightmodel(GLenum pname, GLfloat param);
void lightmodel(GLenum pname, GLint param);
void lightmodel(GLenum pname, const GLfloat* param);
void lightmodel(GLenum pname, const GLint* param);

/// Polygon mode
void polygonmode(GLenum face, GLenum mode);

/// Color material parameters
void colormaterial(GLenum face, GLenum mode);

/// Material parameters
void material(GLenum face, GLenum pname, GLfloat param);
void material(GLenum face, GLenum pname, GLint param);
void material(GLenum face, GLenum pname, const GLfloat* param);
void material(GLenum face, GLenum pname, const GLint* param);

/// Texture environment parameters
void texenv(GLenum target, GLenum pname, GLfloat param);
void texenv(GLenum target, GLenum pname, GLint param);
void texenv(GLenum target, GLenum pname, const GLfloat* param);
void texenv(GLenum target, GLenum pname, const GLint* param);

/// Texture coordinate generation
void texgen(GLenum coord, GLenum param, GLint value);
void texgen(GLenum coord, GLenum param, GLfloat value);
void texgen(GLenum coord, GLenum param, GLdouble value);
void texgen(GLenum coord, GLenum param, const GLint* value);
void texgen(GLenum coord, GLenum param, const GLfloat* value);
void texgen(GLenum coord, GLenum param, const GLdouble* value);

/// Texture parameters
void texparameter(GLenum target, GLenum pname, GLfloat param);
void texparameter(GLenum target, GLenum pname, GLint param);
void texparameter(GLenum target, GLenum pname, const GLfloat* params);
void texparameter(GLenum target, GLenum pname, const GLint* params);

typedef void (* APIENTRY genbuffers_func)(GLuint count, GLuint *id);
typedef void (* APIENTRY deletebuffers_func)(GLuint count, GLuint *id);
typedef void (* APIENTRY bindbuffer_func)(GLenum target, GLuint id);
typedef void (* APIENTRY bufferdata_func)(GLenum target, GLsizei size, const GLvoid *data, GLenum usage);
typedef void (*APIENTRY activetexture_func)(GLenum texture);
typedef void (*APIENTRY clientactivetexture_func)(GLenum texture);

extern genbuffers_func genbuffers;
extern deletebuffers_func deletebuffers;
extern bindbuffer_func bindbuffer;
extern bufferdata_func bufferdata;
extern activetexture_func activetexture;
extern clientactivetexture_func clientactivetexture;

}

#endif // __INCLUDED_RENDER_GL_H__