2
// Book: OpenGL(R) ES 2.0 Programming Guide
3
// Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner
5
// ISBN-13: 9780321502797
6
// Publisher: Addison-Wesley Professional
7
// URLs: http://safari.informit.com/9780321563835
8
// http://www.opengles-book.com
13
/// \brief A utility library for OpenGL ES. This library provides a
14
/// basic common framework for the example applications in the
15
/// OpenGL ES 2.0 Programming Guide.
23
#include <GLES2/gl2.h>
39
/// esCreateWindow flag - RGB color buffer
40
#define ES_WINDOW_RGB 0
41
/// esCreateWindow flag - ALPHA color buffer
42
#define ES_WINDOW_ALPHA 1
43
/// esCreateWindow flag - depth buffer
44
#define ES_WINDOW_DEPTH 2
45
/// esCreateWindow flag - stencil buffer
46
#define ES_WINDOW_STENCIL 4
47
/// esCreateWindow flat - multi-sample buffer
48
#define ES_WINDOW_MULTISAMPLE 8
67
typedef struct _escontext
69
/// Put your user data here...
79
EGLNativeWindowType hWnd;
82
EGLDisplay eglDisplay;
85
EGLContext eglContext;
88
EGLSurface eglSurface;
91
void (ESCALLBACK *drawFunc) ( struct _escontext * );
92
void (ESCALLBACK *keyFunc) ( struct _escontext *, unsigned char, int, int );
93
void (ESCALLBACK *updateFunc) ( struct _escontext *, float deltaTime );
103
/// \brief Initialize ES framework context. This must be called before calling any other functions.
104
/// \param esContext Application context
106
void ESUTIL_API esInitContext ( ESContext *esContext );
109
/// \brief Create a window with the specified parameters
110
/// \param esContext Application context
111
/// \param title Name for title bar of window
112
/// \param width Width in pixels of window to create
113
/// \param height Height in pixels of window to create
114
/// \param flags Bitfield for the window creation flags
115
/// ES_WINDOW_RGB - specifies that the color buffer should have R,G,B channels
116
/// ES_WINDOW_ALPHA - specifies that the color buffer should have alpha
117
/// ES_WINDOW_DEPTH - specifies that a depth buffer should be created
118
/// ES_WINDOW_STENCIL - specifies that a stencil buffer should be created
119
/// ES_WINDOW_MULTISAMPLE - specifies that a multi-sample buffer should be created
120
/// \return GL_TRUE if window creation is succesful, GL_FALSE otherwise
121
GLboolean ESUTIL_API esCreateWindow ( ESContext *esContext, const char *title, GLint width, GLint height, GLuint flags );
124
/// \brief Start the main loop for the OpenGL ES application
125
/// \param esContext Application context
127
void ESUTIL_API esMainLoop ( ESContext *esContext );
130
/// \brief Register a draw callback function to be used to render each frame
131
/// \param esContext Application context
132
/// \param drawFunc Draw callback function that will be used to render the scene
134
void ESUTIL_API esRegisterDrawFunc ( ESContext *esContext, void (ESCALLBACK *drawFunc) ( ESContext* ) );
137
/// \brief Register an update callback function to be used to update on each time step
138
/// \param esContext Application context
139
/// \param updateFunc Update callback function that will be used to render the scene
141
void ESUTIL_API esRegisterUpdateFunc ( ESContext *esContext, void (ESCALLBACK *updateFunc) ( ESContext*, float ) );
144
/// \brief Register an keyboard input processing callback function
145
/// \param esContext Application context
146
/// \param keyFunc Key callback function for application processing of keyboard input
148
void ESUTIL_API esRegisterKeyFunc ( ESContext *esContext,
149
void (ESCALLBACK *drawFunc) ( ESContext*, unsigned char, int, int ) );
151
/// \brief Log a message to the debug output for the platform
152
/// \param formatStr Format string for error log.
154
void ESUTIL_API esLogMessage ( const char *formatStr, ... );
158
/// \brief Load a shader, check for compile errors, print error messages to output log
159
/// \param type Type of shader (GL_VERTEX_SHADER or GL_FRAGMENT_SHADER)
160
/// \param shaderSrc Shader source string
161
/// \return A new shader object on success, 0 on failure
163
GLuint ESUTIL_API esLoadShader ( GLenum type, const char *shaderSrc );
167
/// \brief Load a vertex and fragment shader, create a program object, link program.
168
/// Errors output to log.
169
/// \param vertShaderSrc Vertex shader source code
170
/// \param fragShaderSrc Fragment shader source code
171
/// \return A new program object linked with the vertex/fragment shader pair, 0 on failure
173
GLuint ESUTIL_API esLoadProgram ( const char *vertShaderSrc, const char *fragShaderSrc );
177
/// \brief Generates geometry for a sphere. Allocates memory for the vertex data and stores
178
/// the results in the arrays. Generate index list for a TRIANGLE_STRIP
179
/// \param numSlices The number of slices in the sphere
180
/// \param vertices If not NULL, will contain array of float3 positions
181
/// \param normals If not NULL, will contain array of float3 normals
182
/// \param texCoords If not NULL, will contain array of float2 texCoords
183
/// \param indices If not NULL, will contain the array of indices for the triangle strip
184
/// \return The number of indices required for rendering the buffers (the number of indices stored in the indices array
185
/// if it is not NULL ) as a GL_TRIANGLE_STRIP
187
int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloat **normals,
188
GLfloat **texCoords, GLushort **indices );
191
/// \brief Generates geometry for a cube. Allocates memory for the vertex data and stores
192
/// the results in the arrays. Generate index list for a TRIANGLES
193
/// \param scale The size of the cube, use 1.0 for a unit cube.
194
/// \param vertices If not NULL, will contain array of float3 positions
195
/// \param normals If not NULL, will contain array of float3 normals
196
/// \param texCoords If not NULL, will contain array of float2 texCoords
197
/// \param indices If not NULL, will contain the array of indices for the triangle strip
198
/// \return The number of indices required for rendering the buffers (the number of indices stored in the indices array
199
/// if it is not NULL ) as a GL_TRIANGLES
201
int ESUTIL_API esGenCube ( float scale, GLfloat **vertices, GLfloat **normals,
202
GLfloat **texCoords, GLushort **indices );
205
/// \brief Loads a 24-bit TGA image from a file
206
/// \param fileName Name of the file on disk
207
/// \param width Width of loaded image in pixels
208
/// \param height Height of loaded image in pixels
209
/// \return Pointer to loaded image. NULL on failure.
211
char* ESUTIL_API esLoadTGA ( char *fileName, int *width, int *height );
215
/// \brief multiply matrix specified by result with a scaling matrix and return new matrix in result
216
/// \param result Specifies the input matrix. Scaled matrix is returned in result.
217
/// \param sx, sy, sz Scale factors along the x, y and z axes respectively
219
void ESUTIL_API esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz);
222
/// \brief multiply matrix specified by result with a translation matrix and return new matrix in result
223
/// \param result Specifies the input matrix. Translated matrix is returned in result.
224
/// \param tx, ty, tz Scale factors along the x, y and z axes respectively
226
void ESUTIL_API esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz);
229
/// \brief multiply matrix specified by result with a rotation matrix and return new matrix in result
230
/// \param result Specifies the input matrix. Rotated matrix is returned in result.
231
/// \param angle Specifies the angle of rotation, in degrees.
232
/// \param x, y, z Specify the x, y and z coordinates of a vector, respectively
234
void ESUTIL_API esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
237
// \brief multiply matrix specified by result with a perspective matrix and return new matrix in result
238
/// \param result Specifies the input matrix. new matrix is returned in result.
239
/// \param left, right Coordinates for the left and right vertical clipping planes
240
/// \param bottom, top Coordinates for the bottom and top horizontal clipping planes
241
/// \param nearZ, farZ Distances to the near and far depth clipping planes. Both distances must be positive.
243
void ESUTIL_API esFrustum(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ);
246
/// \brief multiply matrix specified by result with a perspective matrix and return new matrix in result
247
/// \param result Specifies the input matrix. new matrix is returned in result.
248
/// \param fovy Field of view y angle in degrees
249
/// \param aspect Aspect ratio of screen
250
/// \param nearZ Near plane distance
251
/// \param farZ Far plane distance
253
void ESUTIL_API esPerspective(ESMatrix *result, float fovy, float aspect, float nearZ, float farZ);
256
/// \brief multiply matrix specified by result with a perspective matrix and return new matrix in result
257
/// \param result Specifies the input matrix. new matrix is returned in result.
258
/// \param left, right Coordinates for the left and right vertical clipping planes
259
/// \param bottom, top Coordinates for the bottom and top horizontal clipping planes
260
/// \param nearZ, farZ Distances to the near and far depth clipping planes. These values are negative if plane is behind the viewer
262
void ESUTIL_API esOrtho(ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ);
265
/// \brief perform the following operation - result matrix = srcA matrix * srcB matrix
266
/// \param result Returns multiplied matrix
267
/// \param srcA, srcB Input matrices to be multiplied
269
void ESUTIL_API esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB);
272
//// \brief return an indentity matrix
273
//// \param result returns identity matrix
275
void ESUTIL_API esMatrixLoadIdentity(ESMatrix *result);