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 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // Load the texture | 110 // Load the texture |
111 userData->textureId = CreateSimpleTexture2D (); | 111 userData->textureId = CreateSimpleTexture2D (); |
112 | 112 |
113 glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f ); | 113 glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f ); |
114 return TRUE; | 114 return TRUE; |
115 } | 115 } |
116 | 116 |
117 /// | 117 /// |
118 // Draw a triangle using the shader pair created in Init() | 118 // Draw a triangle using the shader pair created in Init() |
119 // | 119 // |
120 void Draw ( ESContext *esContext ) | 120 int Draw ( ESContext *esContext ) |
121 { | 121 { |
122 UserData *userData = esContext->userData; | 122 UserData *userData = esContext->userData; |
123 GLfloat vVertices[] = { -0.5f, 0.5f, 0.0f, // Position 0 | 123 GLfloat vVertices[] = { -0.5f, 0.5f, 0.0f, // Position 0 |
124 0.0f, 0.0f, // TexCoord 0· | 124 0.0f, 0.0f, // TexCoord 0· |
125 -0.5f, -0.5f, 0.0f, // Position 1 | 125 -0.5f, -0.5f, 0.0f, // Position 1 |
126 0.0f, 1.0f, // TexCoord 1 | 126 0.0f, 1.0f, // TexCoord 1 |
127 0.5f, -0.5f, 0.0f, // Position 2 | 127 0.5f, -0.5f, 0.0f, // Position 2 |
128 1.0f, 1.0f, // TexCoord 2 | 128 1.0f, 1.0f, // TexCoord 2 |
129 0.5f, 0.5f, 0.0f, // Position 3 | 129 0.5f, 0.5f, 0.0f, // Position 3 |
130 1.0f, 0.0f // TexCoord 3 | 130 1.0f, 0.0f // TexCoord 3 |
(...skipping 21 matching lines...) Expand all Loading... |
152 | 152 |
153 // Bind the texture | 153 // Bind the texture |
154 glActiveTexture ( GL_TEXTURE0 ); | 154 glActiveTexture ( GL_TEXTURE0 ); |
155 glBindTexture ( GL_TEXTURE_2D, userData->textureId ); | 155 glBindTexture ( GL_TEXTURE_2D, userData->textureId ); |
156 | 156 |
157 // Set the sampler texture unit to 0 | 157 // Set the sampler texture unit to 0 |
158 glUniform1i ( userData->samplerLoc, 0 ); | 158 glUniform1i ( userData->samplerLoc, 0 ); |
159 | 159 |
160 glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices ); | 160 glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices ); |
161 | 161 |
162 eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface ); | 162 return eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface ); |
163 } | |
164 | |
165 /// | |
166 // Cleanup | |
167 // | |
168 void ShutDown ( ESContext *esContext ) | |
169 { | |
170 UserData *userData = esContext->userData; | |
171 | |
172 // Delete texture object | |
173 glDeleteTextures ( 1, &userData->textureId ); | |
174 | |
175 // Delete program object | |
176 glDeleteProgram ( userData->programObject ); | |
177 } | 163 } |
178 | 164 |
179 | 165 |
180 int main ( int argc, char *argv[] ) | 166 int main ( int argc, char *argv[] ) |
181 { | 167 { |
182 ESContext esContext; | 168 ESContext esContext; |
183 UserData userData; | 169 UserData userData; |
184 | 170 |
185 esInitContext ( &esContext ); | 171 esInitContext ( &esContext ); |
186 esContext.userData = &userData; | 172 esContext.userData = &userData; |
187 | 173 |
188 esCreateWindow ( &esContext, TEXT("Simple Texture 2D"), 320, 240, ES_WINDOW_R
GB ); | 174 esCreateWindow ( &esContext, TEXT("Simple Texture 2D"), 320, 240, ES_WINDOW_R
GB ); |
189 ··· | |
190 if ( !Init ( &esContext ) ) | |
191 return 0; | |
192 | 175 |
193 esRegisterDrawFunc ( &esContext, Draw ); | 176 esRegisterDrawFunc ( &esContext, Draw ); |
194 ··· | 177 esRegisterInitFunc ( &esContext, Init ); |
| 178 ··· |
195 esMainLoop ( &esContext ); | 179 esMainLoop ( &esContext ); |
196 | |
197 ShutDown ( &esContext ); | |
198 } | 180 } |
OLD | NEW |