| 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 24 matching lines...) Expand all Loading... |
| 35 "void main() \n" | 35 "void main() \n" |
| 36 "{ \n" | 36 "{ \n" |
| 37 " gl_FragColor = u_color; \n" | 37 " gl_FragColor = u_color; \n" |
| 38 "} \n"; | 38 "} \n"; |
| 39 | 39 |
| 40 GLfloat vVertices[] = { | 40 GLfloat vVertices[] = { |
| 41 -0.75f, 0.25f, 0.50f, // Quad #0 | 41 -0.75f, 0.25f, 0.50f, // Quad #0 |
| 42 -0.25f, 0.25f, 0.50f, | 42 -0.25f, 0.25f, 0.50f, |
| 43 -0.25f, 0.75f, 0.50f, | 43 -0.25f, 0.75f, 0.50f, |
| 44 -0.75f, 0.75f, 0.50f, | 44 -0.75f, 0.75f, 0.50f, |
| 45 0.25f, 0.25f, 0.90f, // Quad #1 | 45 0.25f, 0.25f, 0.50f, // Quad #1 |
| 46 0.75f, 0.25f, 0.90f, | 46 0.75f, 0.25f, 0.50f, |
| 47 0.75f, 0.75f, 0.90f, | 47 0.75f, 0.75f, 0.50f, |
| 48 0.25f, 0.75f, 0.90f, | 48 0.25f, 0.75f, 0.50f, |
| 49 -0.75f, -0.75f, 0.50f, // Quad #2 | 49 -0.75f, -0.75f, 0.50f, // Quad #2 |
| 50 -0.25f, -0.75f, 0.50f, | 50 -0.25f, -0.75f, 0.50f, |
| 51 -0.25f, -0.25f, 0.50f, | 51 -0.25f, -0.25f, 0.50f, |
| 52 -0.75f, -0.25f, 0.50f, | 52 -0.75f, -0.25f, 0.50f, |
| 53 0.25f, -0.75f, 0.50f, // Quad #3 | 53 0.25f, -0.75f, 0.50f, // Quad #3 |
| 54 0.75f, -0.75f, 0.50f, | 54 0.75f, -0.75f, 0.50f, |
| 55 0.75f, -0.25f, 0.50f, | 55 0.75f, -0.25f, 0.50f, |
| 56 0.25f, -0.25f, 0.50f, | 56 0.25f, -0.25f, 0.50f, |
| 57 -1.00f, -1.00f, 0.00f, // Big Quad | 57 -1.00f, -1.00f, 0.00f, // Big Quad |
| 58 1.00f, -1.00f, 0.00f, | 58 1.00f, -1.00f, 0.00f, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 int i; | 111 int i; |
| 112 GLubyte *offset = NULL; | 112 GLubyte *offset = NULL; |
| 113 | 113 |
| 114 STUserData *userData = esContext->userData; | 114 STUserData *userData = esContext->userData; |
| 115 | 115 |
| 116 #define NumTests 4 | 116 #define NumTests 4 |
| 117 GLfloat colors[NumTests][4] = { | 117 GLfloat colors[NumTests][4] = { |
| 118 { 1.0f, 0.0f, 0.0f, 1.0f }, | 118 { 1.0f, 0.0f, 0.0f, 1.0f }, |
| 119 { 0.0f, 1.0f, 0.0f, 1.0f }, | 119 { 0.0f, 1.0f, 0.0f, 1.0f }, |
| 120 { 0.0f, 0.0f, 1.0f, 1.0f }, | 120 { 0.0f, 0.0f, 1.0f, 1.0f }, |
| 121 { 1.0f, 1.0f, 0.0f, 0.0f } | 121 { 1.0f, 1.0f, 0.0f, 1.0f } |
| 122 }; | 122 }; |
| 123 | 123 |
| 124 GLint numStencilBits = 0; | |
| 125 GLuint stencilValues[NumTests] = { | 124 GLuint stencilValues[NumTests] = { |
| 126 0x7, // Result of test 0 | 125 0x7, // Result of test 0 |
| 127 0x0, // Result of test 1 | 126 0x0, // Result of test 1 |
| 128 0x2, // Result of test 2 | 127 0x2, // Result of test 2 |
| 129 0xff // Result of test 3. We need to fill this | 128 0xfe // Result of test 3 |
| 130 // value in a run-time | |
| 131 }; | 129 }; |
| 132 | 130 |
| 133 // Set the viewport | 131 // Set the viewport |
| 134 glViewport ( 0, 0, esContext->width, esContext->height ); | 132 glViewport ( 0, 0, esContext->width, esContext->height ); |
| 135 | 133 |
| 136 // Clear the color, depth, and stencil buffers. At this | 134 // Clear the color, depth, and stencil buffers. At this |
| 137 // point, the stencil buffer will be 0x1 for all pixels | 135 // point, the stencil buffer will be 0x1 for all pixels |
| 138 glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT )
; | 136 glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT )
; |
| 139 | 137 |
| 140 // Use the program object | 138 // Use the program object |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 // ( 0x2 & 0x1 ) == ( 0x1 & 0x1 ) | 205 // ( 0x2 & 0x1 ) == ( 0x1 & 0x1 ) |
| 208 // | 206 // |
| 209 // The stencil value here will be set to ~((2^s-1) & 0x1), | 207 // The stencil value here will be set to ~((2^s-1) & 0x1), |
| 210 // (with the 0x1 being from the stencil clear value), | 208 // (with the 0x1 being from the stencil clear value), |
| 211 // where 's' is the number of bits in the stencil buffer | 209 // where 's' is the number of bits in the stencil buffer |
| 212 // | 210 // |
| 213 glStencilFunc( GL_EQUAL, 0x2, 0x1 ); | 211 glStencilFunc( GL_EQUAL, 0x2, 0x1 ); |
| 214 glStencilOp( GL_INVERT, GL_KEEP, GL_KEEP ); | 212 glStencilOp( GL_INVERT, GL_KEEP, GL_KEEP ); |
| 215 offset += 6; | 213 offset += 6; |
| 216 glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, offset ); | 214 glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, offset ); |
| 217 | |
| 218 // Since we don't know at compile time how many stecil bits are present, | |
| 219 // we'll query, and update the value correct value in the | |
| 220 // stencilValues arrays for the fourth tests. We'll use this value | |
| 221 // later in rendering. | |
| 222 glGetIntegerv( GL_STENCIL_BITS, &numStencilBits ); | |
| 223 | |
| 224 stencilValues[3] = ~(((1 << numStencilBits) - 1) & 0x1) & 0xff; | |
| 225 | 215 |
| 226 // Use the stencil buffer for controlling where rendering will | 216 // Use the stencil buffer for controlling where rendering will |
| 227 // occur. We diable writing to the stencil buffer so we | 217 // occur. We diable writing to the stencil buffer so we |
| 228 // can test against them without modifying the values we | 218 // can test against them without modifying the values we |
| 229 // generated. | 219 // generated. |
| 230 glStencilMask( 0x0 ); | 220 glStencilMask( 0x0 ); |
| 231 offset += 6; | 221 offset += 6; |
| 232 for ( i = 0; i < NumTests; ++i ) | 222 for ( i = 0; i < NumTests; ++i ) |
| 233 { | 223 { |
| 234 glStencilFunc( GL_EQUAL, stencilValues[i], 0xff ); | 224 glStencilFunc( GL_EQUAL, stencilValues[i], 0xff ); |
| 235 glUniform4fv( userData->colorLoc, 1, colors[i] ); | 225 glUniform4fv( userData->colorLoc, 1, colors[i] ); |
| 236 glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, offset ); | 226 glDrawElements( GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, offset ); |
| 237 } | 227 } |
| 238 } | 228 } |
| 239 | 229 |
| 240 /// | 230 /// |
| 241 // Cleanup | 231 // Cleanup |
| 242 // | 232 // |
| 243 void stShutDown ( ESContext *esContext ) | 233 void stShutDown ( ESContext *esContext ) |
| 244 { | 234 { |
| 245 STUserData *userData = esContext->userData; | 235 STUserData *userData = esContext->userData; |
| 246 | 236 |
| 247 // Delete program object | 237 // Delete program object |
| 248 glDeleteProgram ( userData->programObject ); | 238 glDeleteProgram ( userData->programObject ); |
| 249 | 239 |
| 250 // Delete vertex buffer objects | 240 // Delete vertex buffer objects |
| 251 glDeleteBuffers ( 2, userData->vboIds ); | 241 glDeleteBuffers ( 2, userData->vboIds ); |
| 252 } | 242 } |
| OLD | NEW |