diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-04-04 17:11:39 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-04-04 17:11:39 -0700 |
commit | 12e45ea3243b1e734e01785109ec73e76f23965c (patch) | |
tree | 80dd2a9d48f1468b75d3a524c3525becf38d2d2b /tests/glbook | |
parent | f4be2e8e34cf9394ecd5e7166a584b4224f77d6d (diff) |
add yet another working glbook testcase
Diffstat (limited to 'tests/glbook')
-rw-r--r-- | tests/glbook/CH10_MultiTexture.png | bin | 0 -> 59495 bytes | |||
-rw-r--r-- | tests/glbook/Chapter_10/MultiTexture/MultiTexture.c | 44 | ||||
-rw-r--r-- | tests/glbook/Makefile | 2 |
3 files changed, 30 insertions, 16 deletions
diff --git a/tests/glbook/CH10_MultiTexture.png b/tests/glbook/CH10_MultiTexture.png Binary files differnew file mode 100644 index 00000000..8e006eb3 --- /dev/null +++ b/tests/glbook/CH10_MultiTexture.png diff --git a/tests/glbook/Chapter_10/MultiTexture/MultiTexture.c b/tests/glbook/Chapter_10/MultiTexture/MultiTexture.c index 5324ad92..61bda608 100644 --- a/tests/glbook/Chapter_10/MultiTexture/MultiTexture.c +++ b/tests/glbook/Chapter_10/MultiTexture/MultiTexture.c @@ -33,6 +33,8 @@ typedef struct GLuint baseMapTexId;
GLuint lightMapTexId;
+ GLuint vertexObject, indexObject;
+
} UserData;
@@ -117,7 +119,27 @@ int Init ( ESContext *esContext ) if ( userData->baseMapTexId == 0 || userData->lightMapTexId == 0 )
return FALSE;
- glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );
+ GLfloat vVertices[] = { -0.5, 0.5, 0.0, // Position 0
+ 0.0, 0.0, // TexCoord 0
+ -0.5, -0.5, 0.0, // Position 1
+ 0.0, 1.0, // TexCoord 1
+ 0.5, -0.5, 0.0, // Position 2
+ 1.0, 1.0, // TexCoord 2
+ 0.5, 0.5, 0.0, // Position 3
+ 1.0, 0.0 // TexCoord 3
+ };
+ GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
+
+ glGenBuffers(1, &userData->vertexObject);
+ glBindBuffer ( GL_ARRAY_BUFFER, userData->vertexObject );
+ glBufferData ( GL_ARRAY_BUFFER, 5 * 4 * 4, vVertices, GL_STATIC_DRAW );
+
+ glGenBuffers(1, &userData->indexObject);
+ glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER, userData->indexObject );
+ glBufferData ( GL_ELEMENT_ARRAY_BUFFER, 6 * 2, indices, GL_STATIC_DRAW );
+
+ glClearColor ( 0.0, 0.0, 0.0, 1.0 );
+
return TRUE;
}
@@ -127,17 +149,7 @@ int Init ( ESContext *esContext ) void Draw ( ESContext *esContext )
{
UserData *userData = esContext->userData;
- GLfloat vVertices[] = { -0.5f, 0.5f, 0.0f, // Position 0
- 0.0f, 0.0f, // TexCoord 0
- -0.5f, -0.5f, 0.0f, // Position 1
- 0.0f, 1.0f, // TexCoord 1
- 0.5f, -0.5f, 0.0f, // Position 2
- 1.0f, 1.0f, // TexCoord 2
- 0.5f, 0.5f, 0.0f, // Position 3
- 1.0f, 0.0f // TexCoord 3
- };
- GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
-
+
// Set the viewport
glViewport ( 0, 0, esContext->width, esContext->height );
@@ -148,11 +160,12 @@ void Draw ( ESContext *esContext ) glUseProgram ( userData->programObject );
// Load the vertex position
+ glBindBuffer ( GL_ARRAY_BUFFER, userData->vertexObject );
glVertexAttribPointer ( userData->positionLoc, 3, GL_FLOAT,
- GL_FALSE, 5 * sizeof(GLfloat), vVertices );
+ GL_FALSE, 5 * sizeof(GLfloat), 0 );
// Load the texture coordinate
glVertexAttribPointer ( userData->texCoordLoc, 2, GL_FLOAT,
- GL_FALSE, 5 * sizeof(GLfloat), &vVertices[3] );
+ GL_FALSE, 5 * sizeof(GLfloat), 3 * sizeof(GLfloat) );
glEnableVertexAttribArray ( userData->positionLoc );
glEnableVertexAttribArray ( userData->texCoordLoc );
@@ -171,7 +184,8 @@ void Draw ( ESContext *esContext ) // Set the light map sampler to texture unit 1
glUniform1i ( userData->lightMapLoc, 1 );
- glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices );
+ glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER, userData->indexObject );
+ glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0 );
eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface );
}
diff --git a/tests/glbook/Makefile b/tests/glbook/Makefile index 77e83c2d..cd5f8aee 100644 --- a/tests/glbook/Makefile +++ b/tests/glbook/Makefile @@ -28,7 +28,7 @@ all: ./Chapter_2/Hello_Triangle/CH02_HelloTriangle.bc \ ./Chapter_9/MipMap2D/CH09_MipMap2D.bc \ ./Chapter_9/Simple_TextureCubemap/CH09_TextureCubemap.bc \ ./Chapter_9/TextureWrap/CH09_TextureWrap.bc \ -# ./Chapter_10/MultiTexture/CH10_MultiTexture.bc \ + ./Chapter_10/MultiTexture/CH10_MultiTexture.bc \ # ./Chapter_11/Multisample/CH11_Multisample.bc \ # ./Chapter_11/Stencil_Test/CH11_Stencil_Test.bc \ # ./Chapter_13/ParticleSystem/CH13_ParticleSystem.bc |