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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // Store the program object | 142 // Store the program object |
143 userData->programObject = programObject; | 143 userData->programObject = programObject; |
144 | 144 |
145 glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f ); | 145 glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f ); |
146 return TRUE; | 146 return TRUE; |
147 } | 147 } |
148 | 148 |
149 /// | 149 /// |
150 // Draw a triangle using the shader pair created in Init() | 150 // Draw a triangle using the shader pair created in Init() |
151 // | 151 // |
152 void Draw ( ESContext *esContext ) | 152 int Draw ( ESContext *esContext ) |
153 { | 153 { |
154 UserData *userData = esContext->userData; | 154 UserData *userData = esContext->userData; |
155 GLfloat vVertices[] = { 0.0f, 0.5f, 0.0f,· | 155 GLfloat vVertices[] = { 0.0f, 0.5f, 0.0f,· |
156 -0.5f, -0.5f, 0.0f, | 156 -0.5f, -0.5f, 0.0f, |
157 0.5f, -0.5f, 0.0f }; | 157 0.5f, -0.5f, 0.0f }; |
158 ······ | 158 ······ |
159 // Set the viewport | 159 // Set the viewport |
160 glViewport ( 0, 0, esContext->width, esContext->height ); | 160 glViewport ( 0, 0, esContext->width, esContext->height ); |
161 ··· | 161 ··· |
162 // Clear the color buffer | 162 // Clear the color buffer |
163 glClear ( GL_COLOR_BUFFER_BIT ); | 163 glClear ( GL_COLOR_BUFFER_BIT ); |
164 | 164 |
165 // Use the program object | 165 // Use the program object |
166 glUseProgram ( userData->programObject ); | 166 glUseProgram ( userData->programObject ); |
167 | 167 |
168 // Load the vertex data | 168 // Load the vertex data |
169 glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE, 0, vVertices ); | 169 glVertexAttribPointer ( 0, 3, GL_FLOAT, GL_FALSE, 0, vVertices ); |
170 glEnableVertexAttribArray ( 0 ); | 170 glEnableVertexAttribArray ( 0 ); |
171 | 171 |
172 glDrawArrays ( GL_TRIANGLES, 0, 3 ); | 172 glDrawArrays ( GL_TRIANGLES, 0, 3 ); |
173 | 173 |
174 eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface ); | 174 return eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface ); |
175 } | 175 } |
176 | 176 |
177 | 177 |
178 int main ( int argc, char *argv[] ) | 178 int main ( int argc, char *argv[] ) |
179 { | 179 { |
180 ESContext esContext; | 180 ESContext esContext; |
181 UserData userData; | 181 UserData userData; |
182 | 182 |
183 esInitContext ( &esContext ); | 183 esInitContext ( &esContext ); |
184 esContext.userData = &userData; | 184 esContext.userData = &userData; |
185 | 185 |
186 esCreateWindow ( &esContext, TEXT("Hello Triangle"), 320, 240, ES_WINDOW_RGB
); | 186 esCreateWindow ( &esContext, TEXT("Hello Triangle"), 320, 240, ES_WINDOW_RGB
); |
187 ··· | 187 ··· |
188 if ( !Init ( &esContext ) ) | 188 esRegisterInitFunc ( &esContext, Init ); |
189 return 0; | |
190 | |
191 esRegisterDrawFunc ( &esContext, Draw ); | 189 esRegisterDrawFunc ( &esContext, Draw ); |
192 ··· | 190 ··· |
193 esMainLoop ( &esContext ); | 191 esMainLoop ( &esContext ); |
194 } | 192 } |
OLD | NEW |