aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/glbook/CH09_SimpleTexture2D.pngbin0 -> 1943 bytes
-rw-r--r--tests/glbook/Chapter_9/Simple_Texture2D/Simple_Texture2D.c52
-rw-r--r--tests/glbook/Makefile2
-rwxr-xr-xtests/runner.py5
4 files changed, 37 insertions, 22 deletions
diff --git a/tests/glbook/CH09_SimpleTexture2D.png b/tests/glbook/CH09_SimpleTexture2D.png
new file mode 100644
index 00000000..e33539e9
--- /dev/null
+++ b/tests/glbook/CH09_SimpleTexture2D.png
Binary files differ
diff --git a/tests/glbook/Chapter_9/Simple_Texture2D/Simple_Texture2D.c b/tests/glbook/Chapter_9/Simple_Texture2D/Simple_Texture2D.c
index cc465c9a..5276bda4 100644
--- a/tests/glbook/Chapter_9/Simple_Texture2D/Simple_Texture2D.c
+++ b/tests/glbook/Chapter_9/Simple_Texture2D/Simple_Texture2D.c
@@ -32,6 +32,8 @@ typedef struct
// Texture handle
GLuint textureId;
+ GLuint vertexObject, indexObject;
+
} UserData;
///
@@ -111,7 +113,27 @@ int Init ( ESContext *esContext )
// Load the texture
userData->textureId = CreateSimpleTexture2D ();
- glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );
+ // Setup the vertex data
+ 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, sizeof(vVertices), vVertices, GL_STATIC_DRAW );
+
+ glGenBuffers(1, &userData->indexObject);
+ glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER, userData->indexObject );
+ glBufferData ( GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW );
+
+ glClearColor ( 0.0f, 0.0f, 0.0f, 1.0f );
return GL_TRUE;
}
@@ -119,34 +141,26 @@ int Init ( ESContext *esContext )
// Draw a triangle using the shader pair created in Init()
//
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 );
// Clear the color buffer
glClear ( GL_COLOR_BUFFER_BIT );
+ UserData *userData = esContext->userData;
+
// Use the program object
glUseProgram ( userData->programObject );
// Load the vertex position
- glVertexAttribPointer ( userData->positionLoc, 3, GL_FLOAT,
- GL_FALSE, 5 * sizeof(GLfloat), vVertices );
+ glBindBuffer (GL_ARRAY_BUFFER, userData->vertexObject );
+ glVertexAttribPointer ( userData->positionLoc, 3, GL_FLOAT,
+ GL_FALSE, 5 * 4, 0 );
// Load the texture coordinate
glVertexAttribPointer ( userData->texCoordLoc, 2, GL_FLOAT,
- GL_FALSE, 5 * sizeof(GLfloat), &vVertices[3] );
+ GL_FALSE, 5 * 4,
+ 3 * 4 );
glEnableVertexAttribArray ( userData->positionLoc );
glEnableVertexAttribArray ( userData->texCoordLoc );
@@ -158,8 +172,8 @@ void Draw ( ESContext *esContext )
// Set the sampler texture unit to 0
glUniform1i ( userData->samplerLoc, 0 );
- glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices );
-
+ glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER, userData->indexObject );
+ glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0 );
}
///
diff --git a/tests/glbook/Makefile b/tests/glbook/Makefile
index 386d5717..6220fc3c 100644
--- a/tests/glbook/Makefile
+++ b/tests/glbook/Makefile
@@ -24,7 +24,7 @@ default: all
all: ./Chapter_2/Hello_Triangle/CH02_HelloTriangle.bc \
./Chapter_8/Simple_VertexShader/CH08_SimpleVertexShader.bc \
-# ./Chapter_9/Simple_Texture2D/CH09_SimpleTexture2D.bc \
+ ./Chapter_9/Simple_Texture2D/CH09_SimpleTexture2D.bc \
# ./Chapter_9/MipMap2D/CH09_MipMap2D.bc \
# ./Chapter_9/Simple_TextureCubemap/CH09_TextureCubemap.bc \
# ./Chapter_9/TextureWrap/CH09_TextureWrap.bc \
diff --git a/tests/runner.py b/tests/runner.py
index 93c50b20..c340d3a5 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -6878,8 +6878,9 @@ elif 'browser' in str(sys.argv):
def test_glbook(self):
programs = self.get_library('glbook', [
- os.path.join('Chapter_2/Hello_Triangle/CH02_HelloTriangle.bc'),
- os.path.join('Chapter_8/Simple_VertexShader/CH08_SimpleVertexShader.bc')
+ os.path.join('Chapter_2', 'Hello_Triangle', 'CH02_HelloTriangle.bc'),
+ os.path.join('Chapter_8', 'Simple_VertexShader', 'CH08_SimpleVertexShader.bc'),
+ os.path.join('Chapter_9/Simple_Texture2D/CH09_SimpleTexture2D.bc'),
], configure=None)
for program in programs:
print program