| OLD | NEW |
| (Empty) |
| 1 // | |
| 2 // Book: OpenGL(R) ES 2.0 Programming Guide | |
| 3 // Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner | |
| 4 // ISBN-10: 0321502795 | |
| 5 // ISBN-13: 9780321502797 | |
| 6 // Publisher: Addison-Wesley Professional | |
| 7 // URLs: http://safari.informit.com/9780321563835 | |
| 8 // http://www.opengles-book.com | |
| 9 // | |
| 10 | |
| 11 // | |
| 12 /// \file ESUtil.h | |
| 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. | |
| 16 // | |
| 17 #ifndef ESUTIL_H | |
| 18 #define ESUTIL_H | |
| 19 | |
| 20 /// | |
| 21 // Includes | |
| 22 // | |
| 23 #include <GLES2/gl2.h> | |
| 24 | |
| 25 #ifdef __cplusplus | |
| 26 extern "C" { | |
| 27 #endif // __cplusplus | |
| 28 | |
| 29 #ifndef FALSE | |
| 30 #define FALSE 0 | |
| 31 #endif // FALSE | |
| 32 #ifndef TRUE | |
| 33 #define TRUE 1 | |
| 34 #endif // TRUE | |
| 35 | |
| 36 typedef struct | |
| 37 { | |
| 38 GLfloat m[4][4]; | |
| 39 } ESMatrix; | |
| 40 | |
| 41 typedef struct | |
| 42 { | |
| 43 /// Put your user data here... | |
| 44 void* userData; | |
| 45 | |
| 46 /// Window width | |
| 47 GLint width; | |
| 48 | |
| 49 /// Window height | |
| 50 GLint height; | |
| 51 } ESContext; | |
| 52 | |
| 53 // | |
| 54 /// | |
| 55 /// \brief Initialize ES framework context. This must be called before calling
any other functions. | |
| 56 /// \param esContext Application context | |
| 57 // | |
| 58 extern void esInitContext ( ESContext *esContext ); | |
| 59 | |
| 60 // | |
| 61 /// \brief Log a message to the debug output for the platform | |
| 62 /// \param formatStr Format string for error log. | |
| 63 // | |
| 64 extern void esLogMessage ( const char *formatStr, ... ); | |
| 65 | |
| 66 // | |
| 67 /// | |
| 68 /// \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) | |
| 70 /// \param shaderSrc Shader source string | |
| 71 /// \return A new shader object on success, 0 on failure | |
| 72 // | |
| 73 extern GLuint esLoadShader ( GLenum type, const char *shaderSrc ); | |
| 74 | |
| 75 // | |
| 76 /// | |
| 77 /// \brief Load a vertex and fragment shader, create a program object, link prog
ram. | |
| 78 /// Errors output to log. | |
| 79 /// \param vertShaderSrc Vertex shader source code | |
| 80 /// \param fragShaderSrc Fragment shader source code | |
| 81 /// \return A new program object linked with the vertex/fragment shader pair, 0
on failure | |
| 82 // | |
| 83 extern GLuint esLoadProgram ( const char *vertShaderSrc, const char *fragShaderS
rc ); | |
| 84 | |
| 85 | |
| 86 // | |
| 87 /// \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 | |
| 89 /// \param numSlices The number of slices in the sphere | |
| 90 /// \param vertices If not NULL, will contain array of float3 positions | |
| 91 /// \param normals If not NULL, will contain array of float3 normals | |
| 92 /// \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 | |
| 94 /// \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 | |
| 96 // | |
| 97 extern int esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloa
t **normals, | |
| 98 GLfloat **texCoords, GLuint **indices ); | |
| 99 | |
| 100 // | |
| 101 /// \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 | |
| 103 /// \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 | |
| 105 /// \param normals If not NULL, will contain array of float3 normals | |
| 106 /// \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 | |
| 108 /// \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 | |
| 110 // | |
| 111 extern int esGenCube ( float scale, GLfloat **vertices, GLfloat **normals, | |
| 112 GLfloat **texCoords, GLuint **indices ); | |
| 113 | |
| 114 // | |
| 115 /// \brief Loads a 24-bit TGA image from a file | |
| 116 /// \param fileName Name of the file on disk | |
| 117 /// \param width Width of loaded image in pixels | |
| 118 /// \param height Height of loaded image in pixels | |
| 119 /// \return Pointer to loaded image. NULL on failure. | |
| 120 // | |
| 121 extern char* esLoadTGA ( char *fileName, int *width, int *height ); | |
| 122 | |
| 123 | |
| 124 // | |
| 125 /// \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. | |
| 127 /// \param sx, sy, sz Scale factors along the x, y and z axes respectively | |
| 128 // | |
| 129 extern void esScale(ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz); | |
| 130 | |
| 131 // | |
| 132 /// \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. | |
| 134 /// \param tx, ty, tz Scale factors along the x, y and z axes respectively | |
| 135 // | |
| 136 extern void esTranslate(ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz); | |
| 137 | |
| 138 // | |
| 139 /// \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. | |
| 141 /// \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 | |
| 143 // | |
| 144 extern void esRotate(ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfl
oat z); | |
| 145 | |
| 146 // | |
| 147 // \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. | |
| 149 /// \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 | |
| 151 /// \param nearZ, farZ Distances to the near and far depth clipping planes. Bot
h distances must be positive. | |
| 152 // | |
| 153 extern void esFrustum(ESMatrix *result, float left, float right, float bottom, f
loat top, float nearZ, float farZ); | |
| 154 | |
| 155 // | |
| 156 /// \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. | |
| 158 /// \param fovy Field of view y angle in degrees | |
| 159 /// \param aspect Aspect ratio of screen | |
| 160 /// \param nearZ Near plane distance | |
| 161 /// \param farZ Far plane distance | |
| 162 // | |
| 163 extern void esPerspective(ESMatrix *result, float fovy, float aspect, float near
Z, float farZ); | |
| 164 | |
| 165 // | |
| 166 /// \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. | |
| 168 /// \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 | |
| 170 /// \param nearZ, farZ Distances to the near and far depth clipping planes. The
se values are negative if plane is behind the viewer | |
| 171 // | |
| 172 extern void esOrtho(ESMatrix *result, float left, float right, float bottom, flo
at top, float nearZ, float farZ); | |
| 173 | |
| 174 // | |
| 175 /// \brief perform the following operation - result matrix = srcA matrix * srcB
matrix | |
| 176 /// \param result Returns multiplied matrix | |
| 177 /// \param srcA, srcB Input matrices to be multiplied | |
| 178 // | |
| 179 extern void esMatrixMultiply(ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB); | |
| 180 | |
| 181 // | |
| 182 //// \brief return an indentity matrix | |
| 183 //// \param result returns identity matrix | |
| 184 // | |
| 185 extern void esMatrixLoadIdentity(ESMatrix *result); | |
| 186 | |
| 187 #ifdef __cplusplus | |
| 188 } | |
| 189 #endif // __cplusplus | |
| 190 | |
| 191 #endif // ESUTIL_H | |
| OLD | NEW |