OLD | NEW |
1 // | 1 // |
2 // Book: OpenGL(R) ES 2.0 Programming Guide | 2 // Book: OpenGL(R) ES 2.0 Programming Guide |
3 // Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner | 3 // Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner |
4 // ISBN-10: 0321502795 | 4 // ISBN-10: 0321502795 |
5 // ISBN-13: 9780321502797 | 5 // ISBN-13: 9780321502797 |
6 // Publisher: Addison-Wesley Professional | 6 // Publisher: Addison-Wesley Professional |
7 // URLs: http://safari.informit.com/9780321563835 | 7 // URLs: http://safari.informit.com/9780321563835 |
8 // http://www.opengles-book.com | 8 // http://www.opengles-book.com |
9 // | 9 // |
10 | 10 |
11 // | 11 // |
12 /// \file ESUtil.h | 12 /// \file ESUtil.h |
13 /// \brief A utility library for OpenGL ES. This library provides a | 13 /// \brief A utility library for OpenGL ES. This library provides a |
14 /// basic common framework for the example applications in the | 14 /// basic common framework for the example applications in the |
15 /// OpenGL ES 2.0 Programming Guide. | 15 /// OpenGL ES 2.0 Programming Guide. |
16 // | 16 // |
17 #ifndef ESUTIL_H | 17 #ifndef ESUTIL_H |
18 #define ESUTIL_H | 18 #define ESUTIL_H |
19 | 19 |
20 /// | 20 /// |
21 // Includes | 21 // Includes |
22 // | 22 // |
23 #include <GLES2/gl2.h> | 23 #include <GLES2/gl2.h> |
| 24 #include <EGL/egl.h> |
24 | 25 |
25 #ifdef __cplusplus | 26 #ifdef __cplusplus |
| 27 |
26 extern "C" { | 28 extern "C" { |
27 #endif // __cplusplus | 29 #endif |
28 | 30 |
29 #ifndef FALSE | 31 |
30 #define FALSE 0 | 32 /// |
31 #endif // FALSE | 33 // Macros |
32 #ifndef TRUE | 34 // |
33 #define TRUE 1 | 35 #define ESUTIL_API __cdecl |
34 #endif // TRUE | 36 #define ESCALLBACK __cdecl |
| 37 |
| 38 |
| 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 |
| 49 |
| 50 |
| 51 /// |
| 52 // Types |
| 53 // |
35 | 54 |
36 typedef struct | 55 typedef struct |
37 { | 56 { |
38 GLfloat m[4][4]; | 57 GLfloat m[4][4]; |
39 } ESMatrix; | 58 } ESMatrix; |
40 | 59 |
41 typedef struct | 60 typedef struct |
42 { | 61 { |
43 /// Put your user data here... | 62 /// Put your user data here... |
44 void* userData; | 63 void* userData; |
45 | 64 |
46 /// Window width | 65 /// Window width |
47 GLint width; | 66 GLint width; |
48 | 67 |
49 /// Window height | 68 /// Window height |
50 GLint height; | 69 GLint height; |
| 70 |
| 71 /// Window handle |
| 72 EGLNativeWindowType hWnd; |
| 73 |
| 74 /// EGL display |
| 75 EGLDisplay eglDisplay; |
| 76 |
| 77 /// EGL context |
| 78 EGLContext eglContext; |
| 79 |
| 80 /// EGL surface |
| 81 EGLSurface eglSurface; |
| 82 |
| 83 /// Callbacks |
| 84 void (ESCALLBACK *drawFunc) ( void* ); |
| 85 void (ESCALLBACK *keyFunc) ( void*, unsigned char, int, int ); |
| 86 void (ESCALLBACK *updateFunc) ( void*, float deltaTime ); |
51 } ESContext; | 87 } ESContext; |
52 | 88 |
| 89 |
| 90 /// |
| 91 // Public Functions |
| 92 // |
| 93 |
53 // | 94 // |
54 /// | 95 /// |
55 /// \brief Initialize ES framework context. This must be called before calling
any other functions. | 96 /// \brief Initialize ES framework context. This must be called before calling
any other functions. |
56 /// \param esContext Application context | 97 /// \param esContext Application context |
57 // | 98 // |
58 extern void esInitContext ( ESContext *esContext ); | 99 void ESUTIL_API esInitContext ( ESContext *esContext ); |
59 | 100 |
60 // | 101 // |
| 102 /// \brief Create a window with the specified parameters |
| 103 /// \param esContext Application context |
| 104 /// \param title Name for title bar of window |
| 105 /// \param width Width in pixels of window to create |
| 106 /// \param height Height in pixels of window to create |
| 107 /// \param flags Bitfield for the window creation flags |
| 108 /// ES_WINDOW_RGB - specifies that the color buffer should have R,G,
B channels |
| 109 /// ES_WINDOW_ALPHA - specifies that the color buffer should have alph
a |
| 110 /// ES_WINDOW_DEPTH - specifies that a depth buffer should be created |
| 111 /// ES_WINDOW_STENCIL - specifies that a stencil buffer should be create
d |
| 112 /// ES_WINDOW_MULTISAMPLE - specifies that a multi-sample buffer should
be created |
| 113 /// \return GL_TRUE if window creation is succesful, GL_FALSE otherwise |
| 114 GLboolean ESUTIL_API esCreateWindow ( ESContext *esContext, const char *title, G
Lint width, GLint height, GLuint flags ); |
| 115 |
| 116 // |
| 117 /// \brief Start the main loop for the OpenGL ES application |
| 118 /// \param esContext Application context |
| 119 // |
| 120 void ESUTIL_API esMainLoop ( ESContext *esContext ); |
| 121 |
| 122 // |
| 123 /// \brief Register a draw callback function to be used to render each frame |
| 124 /// \param esContext Application context |
| 125 /// \param drawFunc Draw callback function that will be used to render the scene |
| 126 // |
| 127 void ESUTIL_API esRegisterDrawFunc ( ESContext *esContext, void (ESCALLBACK *dra
wFunc) ( ESContext* ) ); |
| 128 |
| 129 // |
| 130 /// \brief Register an update callback function to be used to update on each tim
e step |
| 131 /// \param esContext Application context |
| 132 /// \param updateFunc Update callback function that will be used to render the s
cene |
| 133 // |
| 134 void ESUTIL_API esRegisterUpdateFunc ( ESContext *esContext, void (ESCALLBACK *u
pdateFunc) ( ESContext*, float ) ); |
| 135 |
| 136 // |
| 137 /// \brief Register an keyboard input processing callback function |
| 138 /// \param esContext Application context |
| 139 /// \param keyFunc Key callback function for application processing of keyboard
input |
| 140 // |
| 141 void ESUTIL_API esRegisterKeyFunc ( ESContext *esContext, |
| 142 void (ESCALLBACK *drawFunc) ( ESContext*, un
signed char, int, int ) ); |
| 143 // |
61 /// \brief Log a message to the debug output for the platform | 144 /// \brief Log a message to the debug output for the platform |
62 /// \param formatStr Format string for error log. | 145 /// \param formatStr Format string for error log. |
63 // | 146 // |
64 extern void esLogMessage ( const char *formatStr, ... ); | 147 void ESUTIL_API esLogMessage ( const char *formatStr, ... ); |
65 | 148 |
66 // | 149 // |
67 /// | 150 /// |
68 /// \brief Load a shader, check for compile errors, print error messages to outp
ut log | 151 /// \brief Load a shader, check for compile errors, print error messages to outp
ut log |
69 /// \param type Type of shader (GL_VERTEX_SHADER or GL_FRAGMENT_SHADER) | 152 /// \param type Type of shader (GL_VERTEX_SHADER or GL_FRAGMENT_SHADER) |
70 /// \param shaderSrc Shader source string | 153 /// \param shaderSrc Shader source string |
71 /// \return A new shader object on success, 0 on failure | 154 /// \return A new shader object on success, 0 on failure |
72 // | 155 // |
73 extern GLuint esLoadShader ( GLenum type, const char *shaderSrc ); | 156 GLuint ESUTIL_API esLoadShader ( GLenum type, const char *shaderSrc ); |
74 | 157 |
75 // | 158 // |
76 /// | 159 /// |
77 /// \brief Load a vertex and fragment shader, create a program object, link prog
ram. | 160 /// \brief Load a vertex and fragment shader, create a program object, link prog
ram. |
78 /// Errors output to log. | 161 /// Errors output to log. |
79 /// \param vertShaderSrc Vertex shader source code | 162 /// \param vertShaderSrc Vertex shader source code |
80 /// \param fragShaderSrc Fragment shader source code | 163 /// \param fragShaderSrc Fragment shader source code |
81 /// \return A new program object linked with the vertex/fragment shader pair, 0
on failure | 164 /// \return A new program object linked with the vertex/fragment shader pair, 0
on failure |
82 // | 165 // |
83 extern GLuint esLoadProgram ( const char *vertShaderSrc, const char *fragShaderS
rc ); | 166 GLuint ESUTIL_API esLoadProgram ( const char *vertShaderSrc, const char *fragSha
derSrc ); |
84 | 167 |
85 | 168 |
86 // | 169 // |
87 /// \brief Generates geometry for a sphere. Allocates memory for the vertex dat
a and stores | 170 /// \brief Generates geometry for a sphere. Allocates memory for the vertex dat
a and stores |
88 /// the results in the arrays. Generate index list for a TRIANGLE_STRIP | 171 /// the results in the arrays. Generate index list for a TRIANGLE_STRIP |
89 /// \param numSlices The number of slices in the sphere | 172 /// \param numSlices The number of slices in the sphere |
90 /// \param vertices If not NULL, will contain array of float3 positions | 173 /// \param vertices If not NULL, will contain array of float3 positions |
91 /// \param normals If not NULL, will contain array of float3 normals | 174 /// \param normals If not NULL, will contain array of float3 normals |
92 /// \param texCoords If not NULL, will contain array of float2 texCoords | 175 /// \param texCoords If not NULL, will contain array of float2 texCoords |
93 /// \param indices If not NULL, will contain the array of indices for the triang
le strip | 176 /// \param indices If not NULL, will contain the array of indices for the triang
le strip |
94 /// \return The number of indices required for rendering the buffers (the number
of indices stored in the indices array | 177 /// \return The number of indices required for rendering the buffers (the number
of indices stored in the indices array |
95 /// if it is not NULL ) as a GL_TRIANGLE_STRIP | 178 /// if it is not NULL ) as a GL_TRIANGLE_STRIP |
96 // | 179 // |
97 extern int esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloa
t **normals, | 180 int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GL
float **normals, |
98 GLfloat **texCoords, GLuint **indices ); | 181 GLfloat **texCoords, GLuint **indices ); |
99 | 182 |
100 // | 183 // |
101 /// \brief Generates geometry for a cube. Allocates memory for the vertex data
and stores | 184 /// \brief Generates geometry for a cube. Allocates memory for the vertex data
and stores |
102 /// the results in the arrays. Generate index list for a TRIANGLES | 185 /// the results in the arrays. Generate index list for a TRIANGLES |
103 /// \param scale The size of the cube, use 1.0 for a unit cube. | 186 /// \param scale The size of the cube, use 1.0 for a unit cube. |
104 /// \param vertices If not NULL, will contain array of float3 positions | 187 /// \param vertices If not NULL, will contain array of float3 positions |
105 /// \param normals If not NULL, will contain array of float3 normals | 188 /// \param normals If not NULL, will contain array of float3 normals |
106 /// \param texCoords If not NULL, will contain array of float2 texCoords | 189 /// \param texCoords If not NULL, will contain array of float2 texCoords |
107 /// \param indices If not NULL, will contain the array of indices for the triang
le strip | 190 /// \param indices If not NULL, will contain the array of indices for the triang
le strip |
108 /// \return The number of indices required for rendering the buffers (the number
of indices stored in the indices array | 191 /// \return The number of indices required for rendering the buffers (the number
of indices stored in the indices array |
109 /// if it is not NULL ) as a GL_TRIANGLES | 192 /// if it is not NULL ) as a GL_TRIANGLES |
110 // | 193 // |
111 extern int esGenCube ( float scale, GLfloat **vertices, GLfloat **normals, | 194 int ESUTIL_API esGenCube ( float scale, GLfloat **vertices, GLfloat **normals, |
112 GLfloat **texCoords, GLuint **indices ); | 195 GLfloat **texCoords, GLuint **indices ); |
113 | 196 |
114 // | 197 // |
115 /// \brief Loads a 24-bit TGA image from a file | 198 /// \brief Loads a 24-bit TGA image from a file |
116 /// \param fileName Name of the file on disk | 199 /// \param fileName Name of the file on disk |
117 /// \param width Width of loaded image in pixels | 200 /// \param width Width of loaded image in pixels |
118 /// \param height Height of loaded image in pixels | 201 /// \param height Height of loaded image in pixels |
119 /// \return Pointer to loaded image. NULL on failure. | 202 /// \return Pointer to loaded image. NULL on failure. |
120 // | 203 // |
121 extern char* esLoadTGA ( char *fileName, int *width, int *height ); | 204 char* ESUTIL_API esLoadTGA ( char *fileName, int *width, int *height ); |
122 | 205 |
123 | 206 |
124 // | 207 // |
125 /// \brief multiply matrix specified by result with a scaling matrix and return
new matrix in result | 208 /// \brief multiply matrix specified by result with a scaling matrix and return
new matrix in result |
126 /// \param result Specifies the input matrix. Scaled matrix is returned in resu
lt. | 209 /// \param result Specifies the input matrix. Scaled matrix is returned in resu
lt. |
127 /// \param sx, sy, sz Scale factors along the x, y and z axes respectively | 210 /// \param sx, sy, sz Scale factors along the x, y and z axes respectively |
128 // | 211 // |
129 extern void esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz); | 212 void ESUTIL_API esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz); |
130 | 213 |
131 // | 214 // |
132 /// \brief multiply matrix specified by result with a translation matrix and ret
urn new matrix in result | 215 /// \brief multiply matrix specified by result with a translation matrix and ret
urn new matrix in result |
133 /// \param result Specifies the input matrix. Translated matrix is returned in
result. | 216 /// \param result Specifies the input matrix. Translated matrix is returned in
result. |
134 /// \param tx, ty, tz Scale factors along the x, y and z axes respectively | 217 /// \param tx, ty, tz Scale factors along the x, y and z axes respectively |
135 // | 218 // |
136 extern void esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz); | 219 void ESUTIL_API esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz
); |
137 | 220 |
138 // | 221 // |
139 /// \brief multiply matrix specified by result with a rotation matrix and return
new matrix in result | 222 /// \brief multiply matrix specified by result with a rotation matrix and return
new matrix in result |
140 /// \param result Specifies the input matrix. Rotated matrix is returned in res
ult. | 223 /// \param result Specifies the input matrix. Rotated matrix is returned in res
ult. |
141 /// \param angle Specifies the angle of rotation, in degrees. | 224 /// \param angle Specifies the angle of rotation, in degrees. |
142 /// \param x, y, z Specify the x, y and z coordinates of a vector, respectively | 225 /// \param x, y, z Specify the x, y and z coordinates of a vector, respectively |
143 // | 226 // |
144 extern void esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfl
oat z); | 227 void ESUTIL_API esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y,
GLfloat z); |
145 | 228 |
146 // | 229 // |
147 // \brief multiply matrix specified by result with a perspective matrix and retu
rn new matrix in result | 230 // \brief multiply matrix specified by result with a perspective matrix and retu
rn new matrix in result |
148 /// \param result Specifies the input matrix. new matrix is returned in result. | 231 /// \param result Specifies the input matrix. new matrix is returned in result. |
149 /// \param left, right Coordinates for the left and right vertical clipping plan
es | 232 /// \param left, right Coordinates for the left and right vertical clipping plan
es |
150 /// \param bottom, top Coordinates for the bottom and top horizontal clipping pl
anes | 233 /// \param bottom, top Coordinates for the bottom and top horizontal clipping pl
anes |
151 /// \param nearZ, farZ Distances to the near and far depth clipping planes. Bot
h distances must be positive. | 234 /// \param nearZ, farZ Distances to the near and far depth clipping planes. Bot
h distances must be positive. |
152 // | 235 // |
153 extern void esFrustum(ESMatrix *result, float left, float right, float bottom, f
loat top, float nearZ, float farZ); | 236 void ESUTIL_API esFrustum(ESMatrix *result, float left, float right, float botto
m, float top, float nearZ, float farZ); |
154 | 237 |
155 // | 238 // |
156 /// \brief multiply matrix specified by result with a perspective matrix and ret
urn new matrix in result | 239 /// \brief multiply matrix specified by result with a perspective matrix and ret
urn new matrix in result |
157 /// \param result Specifies the input matrix. new matrix is returned in result. | 240 /// \param result Specifies the input matrix. new matrix is returned in result. |
158 /// \param fovy Field of view y angle in degrees | 241 /// \param fovy Field of view y angle in degrees |
159 /// \param aspect Aspect ratio of screen | 242 /// \param aspect Aspect ratio of screen |
160 /// \param nearZ Near plane distance | 243 /// \param nearZ Near plane distance |
161 /// \param farZ Far plane distance | 244 /// \param farZ Far plane distance |
162 // | 245 // |
163 extern void esPerspective(ESMatrix *result, float fovy, float aspect, float near
Z, float farZ); | 246 void ESUTIL_API esPerspective(ESMatrix *result, float fovy, float aspect, float
nearZ, float farZ); |
164 | 247 |
165 // | 248 // |
166 /// \brief multiply matrix specified by result with a perspective matrix and ret
urn new matrix in result | 249 /// \brief multiply matrix specified by result with a perspective matrix and ret
urn new matrix in result |
167 /// \param result Specifies the input matrix. new matrix is returned in result. | 250 /// \param result Specifies the input matrix. new matrix is returned in result. |
168 /// \param left, right Coordinates for the left and right vertical clipping plan
es | 251 /// \param left, right Coordinates for the left and right vertical clipping plan
es |
169 /// \param bottom, top Coordinates for the bottom and top horizontal clipping pl
anes | 252 /// \param bottom, top Coordinates for the bottom and top horizontal clipping pl
anes |
170 /// \param nearZ, farZ Distances to the near and far depth clipping planes. The
se values are negative if plane is behind the viewer | 253 /// \param nearZ, farZ Distances to the near and far depth clipping planes. The
se values are negative if plane is behind the viewer |
171 // | 254 // |
172 extern void esOrtho(ESMatrix *result, float left, float right, float bottom, flo
at top, float nearZ, float farZ); | 255 void ESUTIL_API esOrtho(ESMatrix *result, float left, float right, float bottom,
float top, float nearZ, float farZ); |
173 | 256 |
174 // | 257 // |
175 /// \brief perform the following operation - result matrix = srcA matrix * srcB
matrix | 258 /// \brief perform the following operation - result matrix = srcA matrix * srcB
matrix |
176 /// \param result Returns multiplied matrix | 259 /// \param result Returns multiplied matrix |
177 /// \param srcA, srcB Input matrices to be multiplied | 260 /// \param srcA, srcB Input matrices to be multiplied |
178 // | 261 // |
179 extern void esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB); | 262 void ESUTIL_API esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *src
B); |
180 | 263 |
181 // | 264 // |
182 //// \brief return an indentity matrix | 265 //// \brief return an indentity matrix |
183 //// \param result returns identity matrix | 266 //// \param result returns identity matrix |
184 // | 267 // |
185 extern void esMatrixLoadIdentity(ESMatrix *result); | 268 void ESUTIL_API esMatrixLoadIdentity(ESMatrix *result); |
186 | 269 |
187 #ifdef __cplusplus | 270 #ifdef __cplusplus |
188 } | 271 } |
189 #endif // __cplusplus | 272 #endif |
190 | 273 |
191 #endif // ESUTIL_H | 274 #endif // ESUTIL_H |
OLD | NEW |