diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-04-02 16:26:54 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-04-02 16:26:54 -0700 |
commit | 385457fd62f247de66462d16c54c4c89e040adc2 (patch) | |
tree | 85743185f56ba5d66d33fb34d7bb42d6c01b8cc1 | |
parent | 75c2d2007fd7dc03c69ccaca2d65ab75fe6c3d08 (diff) |
add second working glbook test
-rw-r--r-- | tests/glbook/CH08_SimpleVertexShader.png | bin | 0 -> 1600 bytes | |||
-rw-r--r-- | tests/glbook/Chapter_8/Simple_VertexShader/Simple_VertexShader.c | 21 | ||||
-rw-r--r-- | tests/glbook/Common/esShapes.c | 6 | ||||
-rw-r--r-- | tests/glbook/Common/esUtil.h | 2 | ||||
-rw-r--r-- | tests/glbook/Makefile | 2 | ||||
-rwxr-xr-x | tests/runner.py | 5 |
6 files changed, 26 insertions, 10 deletions
diff --git a/tests/glbook/CH08_SimpleVertexShader.png b/tests/glbook/CH08_SimpleVertexShader.png Binary files differnew file mode 100644 index 00000000..84b276fd --- /dev/null +++ b/tests/glbook/CH08_SimpleVertexShader.png diff --git a/tests/glbook/Chapter_8/Simple_VertexShader/Simple_VertexShader.c b/tests/glbook/Chapter_8/Simple_VertexShader/Simple_VertexShader.c index 6036bf0c..44380c18 100644 --- a/tests/glbook/Chapter_8/Simple_VertexShader/Simple_VertexShader.c +++ b/tests/glbook/Chapter_8/Simple_VertexShader/Simple_VertexShader.c @@ -29,7 +29,7 @@ typedef struct // Vertex daata GLfloat *vertices; - GLuint *indices; + GLushort *indices; int numIndices; // Rotation angle @@ -37,6 +37,8 @@ typedef struct // MVP matrix ESMatrix mvpMatrix; + + GLuint vertPosObject, indicesObject; } UserData; /// @@ -78,6 +80,14 @@ int Init ( ESContext *esContext ) // Starting rotation angle for the cube userData->angle = 45.0f; + glGenBuffers(1, &userData->vertPosObject); + glBindBuffer(GL_ARRAY_BUFFER, userData->vertPosObject); + glBufferData(GL_ARRAY_BUFFER, 24 * sizeof(GLfloat) * 3, userData->vertices, GL_STATIC_DRAW); + + glGenBuffers(1, &userData->indicesObject); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, userData->indicesObject); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, userData->numIndices * sizeof(GLushort), userData->indices, GL_STATIC_DRAW); + glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f ); return GL_TRUE; } @@ -137,17 +147,20 @@ void Draw ( ESContext *esContext ) glUseProgram ( userData->programObject ); // Load the vertex position + glBindBuffer(GL_ARRAY_BUFFER, userData->vertPosObject); glVertexAttribPointer ( userData->positionLoc, 3, GL_FLOAT, - GL_FALSE, 3 * sizeof(GLfloat), userData->vertices ); - + GL_FALSE, 0, 0 ); glEnableVertexAttribArray ( userData->positionLoc ); + // Load the index buffer + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, userData->indicesObject); + // Load the MVP matrix glUniformMatrix4fv( userData->mvpLoc, 1, GL_FALSE, (GLfloat*) &userData->mvpMatrix.m[0][0] ); // Draw the cube - glDrawElements ( GL_TRIANGLES, userData->numIndices, GL_UNSIGNED_INT, userData->indices ); + glDrawElements ( GL_TRIANGLES, userData->numIndices, GL_UNSIGNED_SHORT, 0 ); } /// diff --git a/tests/glbook/Common/esShapes.c b/tests/glbook/Common/esShapes.c index 0fa65057..aecd37ce 100644 --- a/tests/glbook/Common/esShapes.c +++ b/tests/glbook/Common/esShapes.c @@ -139,7 +139,7 @@ int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GL /// if it is not NULL ) as a GL_TRIANGLE_STRIP // int ESUTIL_API esGenCube ( float scale, GLfloat **vertices, GLfloat **normals, - GLfloat **texCoords, GLuint **indices ) + GLfloat **texCoords, GLushort **indices ) { int i; int numVertices = 24; @@ -256,7 +256,7 @@ int ESUTIL_API esGenCube ( float scale, GLfloat **vertices, GLfloat **normals, // Generate the indices if ( indices != NULL ) { - GLuint cubeIndices[] = + GLushort cubeIndices[] = { 0, 2, 1, 0, 3, 2, @@ -272,7 +272,7 @@ int ESUTIL_API esGenCube ( float scale, GLfloat **vertices, GLfloat **normals, 20, 22, 21 }; - *indices = malloc ( sizeof(GLuint) * numIndices ); + *indices = malloc ( sizeof(GLushort) * numIndices ); memcpy( *indices, cubeIndices, sizeof( cubeIndices ) ); } diff --git a/tests/glbook/Common/esUtil.h b/tests/glbook/Common/esUtil.h index b675e367..1ff236de 100644 --- a/tests/glbook/Common/esUtil.h +++ b/tests/glbook/Common/esUtil.h @@ -199,7 +199,7 @@ int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GL /// if it is not NULL ) as a GL_TRIANGLES
//
int ESUTIL_API esGenCube ( float scale, GLfloat **vertices, GLfloat **normals,
- GLfloat **texCoords, GLuint **indices );
+ GLfloat **texCoords, GLushort **indices );
//
/// \brief Loads a 24-bit TGA image from a file
diff --git a/tests/glbook/Makefile b/tests/glbook/Makefile index 299b594f..386d5717 100644 --- a/tests/glbook/Makefile +++ b/tests/glbook/Makefile @@ -23,7 +23,7 @@ CH13SRC2=./Chapter_13/ParticleSystem/ParticleSystem.c default: all all: ./Chapter_2/Hello_Triangle/CH02_HelloTriangle.bc \ -# ./Chapter_8/Simple_VertexShader/CH08_SimpleVertexShader.bc \ + ./Chapter_8/Simple_VertexShader/CH08_SimpleVertexShader.bc \ # ./Chapter_9/Simple_Texture2D/CH09_SimpleTexture2D.bc \ # ./Chapter_9/MipMap2D/CH09_MipMap2D.bc \ # ./Chapter_9/Simple_TextureCubemap/CH09_TextureCubemap.bc \ diff --git a/tests/runner.py b/tests/runner.py index e2d05ca7..431a1c6e 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -6878,7 +6878,10 @@ elif 'browser' in str(sys.argv): self.run_browser('something.html', 'You should not see animating gears.', '/report_gl_result?false') def test_glbook(self): - programs = self.get_library('glbook', [os.path.join('Chapter_2/Hello_Triangle/CH02_HelloTriangle.bc')], configure=None) + 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') + ], configure=None) for program in programs: print program self.reftest(path_from_root('tests', 'glbook', os.path.basename(program).replace('.bc', '.png'))) |