diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-04-05 16:39:22 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-04-05 16:39:22 -0700 |
commit | f8c938e92410c02aebf8306541fd876bec86d568 (patch) | |
tree | b68bc8b6a5b9b3d9fc31702a9fe2590fb73c5c4c /tests | |
parent | 85532b83fdc18160cb727e5d4415a283f4c73100 (diff) |
add final glbook test
Diffstat (limited to 'tests')
-rw-r--r-- | tests/glbook/CH13_ParticleSystem.png | bin | 0 -> 11936 bytes | |||
-rw-r--r-- | tests/glbook/Chapter_13/ParticleSystem/ParticleSystem.c | 70 | ||||
-rw-r--r-- | tests/glbook/Makefile | 2 | ||||
-rwxr-xr-x | tests/runner.py | 9 |
4 files changed, 51 insertions, 30 deletions
diff --git a/tests/glbook/CH13_ParticleSystem.png b/tests/glbook/CH13_ParticleSystem.png Binary files differnew file mode 100644 index 00000000..39b9af0a --- /dev/null +++ b/tests/glbook/CH13_ParticleSystem.png diff --git a/tests/glbook/Chapter_13/ParticleSystem/ParticleSystem.c b/tests/glbook/Chapter_13/ParticleSystem/ParticleSystem.c index 378d05a7..f48e871a 100644 --- a/tests/glbook/Chapter_13/ParticleSystem/ParticleSystem.c +++ b/tests/glbook/Chapter_13/ParticleSystem/ParticleSystem.c @@ -17,9 +17,16 @@ #include <math.h>
#include "esUtil.h"
-#define NUM_PARTICLES 1000
+#define NUM_PARTICLES 2000
#define PARTICLE_SIZE 7
+int randomTemp = 8765;
+float myrandom() {
+ int curr = randomTemp;
+ randomTemp = (1140671485 * randomTemp + 12820163) % 4294967296;
+ return ((float)curr) / 4294967296;
+}
+
typedef struct
{
// Handle to a program object
@@ -40,11 +47,12 @@ typedef struct GLuint textureId;
// Particle vertex data
- float particleData[ NUM_PARTICLES * PARTICLE_SIZE ];
+ GLfloat particleData[ NUM_PARTICLES * PARTICLE_SIZE ];
// Current time
float time;
+ GLuint vertexObject;
} UserData;
///
@@ -136,29 +144,31 @@ int Init ( ESContext *esContext ) userData->colorLoc = glGetUniformLocation ( userData->programObject, "u_color" );
userData->samplerLoc = glGetUniformLocation ( userData->programObject, "s_texture" );
- glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );
+ glClearColor ( 0.0f, 0.0f, 0.0f, 1.0f );
// Fill in particle data array
- srand ( 0 );
for ( i = 0; i < NUM_PARTICLES; i++ )
{
- float *particleData = &userData->particleData[i * PARTICLE_SIZE];
+ GLfloat *particleData = &userData->particleData[i * PARTICLE_SIZE];
// Lifetime of particle
- (*particleData++) = ( (float)(rand() % 10000) / 10000.0f );
+ (*particleData++) = myrandom();
// End position of particle
- (*particleData++) = ( (float)(rand() % 10000) / 5000.0f ) - 1.0f;
- (*particleData++) = ( (float)(rand() % 10000) / 5000.0f ) - 1.0f;
- (*particleData++) = ( (float)(rand() % 10000) / 5000.0f ) - 1.0f;
+ (*particleData++) = myrandom() * 2 - 1.0f;
+ (*particleData++) = myrandom() * 2 - 1.0f;
+ (*particleData++) = myrandom() * 2 - 1.0f;
// Start position of particle
- (*particleData++) = ( (float)(rand() % 10000) / 40000.0f ) - 0.125f;
- (*particleData++) = ( (float)(rand() % 10000) / 40000.0f ) - 0.125f;
- (*particleData++) = ( (float)(rand() % 10000) / 40000.0f ) - 0.125f;
-
+ (*particleData++) = myrandom() * 0.25 - 0.125f;
+ (*particleData++) = myrandom() * 0.25 - 0.125f;
+ (*particleData++) = myrandom() * 0.25 - 0.125f;
}
+ glGenBuffers(1, &userData->vertexObject);
+ glBindBuffer( GL_ARRAY_BUFFER, userData->vertexObject );
+ glBufferData( GL_ARRAY_BUFFER, NUM_PARTICLES * PARTICLE_SIZE * 4, userData->particleData, GL_STATIC_DRAW );
+
// Initialize time to cause reset on first update
userData->time = 1.0f;
@@ -176,6 +186,7 @@ int Init ( ESContext *esContext ) //
void Update ( ESContext *esContext, float deltaTime )
{
+// deltaTime = 0.1;
UserData *userData = esContext->userData;
userData->time += deltaTime;
@@ -188,17 +199,17 @@ void Update ( ESContext *esContext, float deltaTime ) userData->time = 0.0f;
// Pick a new start location and color
- centerPos[0] = ( (float)(rand() % 10000) / 10000.0f ) - 0.5f;
- centerPos[1] = ( (float)(rand() % 10000) / 10000.0f ) - 0.5f;
- centerPos[2] = ( (float)(rand() % 10000) / 10000.0f ) - 0.5f;
+ centerPos[0] = myrandom() - 0.5f;
+ centerPos[1] = myrandom() - 0.5f;
+ centerPos[2] = myrandom() - 0.5f;
glUniform3fv ( userData->centerPositionLoc, 1, ¢erPos[0] );
// Random color
- color[0] = ( (float)(rand() % 10000) / 20000.0f ) + 0.5f;
- color[1] = ( (float)(rand() % 10000) / 20000.0f ) + 0.5f;
- color[2] = ( (float)(rand() % 10000) / 20000.0f ) + 0.5f;
- color[3] = 0.5;
+ color[0] = myrandom() * 0.5 + 0.5f;
+ color[1] = myrandom() * 0.5 + 0.5f;
+ color[2] = myrandom() * 0.5 + 0.5f;
+ color[3] = 1.0;
glUniform4fv ( userData->colorLoc, 1, &color[0] );
}
@@ -224,17 +235,18 @@ void Draw ( ESContext *esContext ) glUseProgram ( userData->programObject );
// Load the vertex attributes
+ glBindBuffer( GL_ARRAY_BUFFER, userData->vertexObject );
glVertexAttribPointer ( userData->lifetimeLoc, 1, GL_FLOAT,
GL_FALSE, PARTICLE_SIZE * sizeof(GLfloat),
- userData->particleData );
+ 0 );
glVertexAttribPointer ( userData->endPositionLoc, 3, GL_FLOAT,
GL_FALSE, PARTICLE_SIZE * sizeof(GLfloat),
- &userData->particleData[1] );
+ 4 );
glVertexAttribPointer ( userData->startPositionLoc, 3, GL_FLOAT,
GL_FALSE, PARTICLE_SIZE * sizeof(GLfloat),
- &userData->particleData[4] );
+ 4 * 4 );
glEnableVertexAttribArray ( userData->lifetimeLoc );
@@ -247,11 +259,13 @@ void Draw ( ESContext *esContext ) // Bind the texture
glActiveTexture ( GL_TEXTURE0 );
glBindTexture ( GL_TEXTURE_2D, userData->textureId );
- glEnable ( GL_TEXTURE_2D );
+ //glEnable ( GL_TEXTURE_2D );
// Set the sampler texture unit to 0
glUniform1i ( userData->samplerLoc, 0 );
+ Update ( esContext, 133 * 0.001125 );
+
glDrawArrays( GL_POINTS, 0, NUM_PARTICLES );
eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface );
@@ -280,15 +294,17 @@ int main ( int argc, char *argv[] ) esInitContext ( &esContext );
esContext.userData = &userData;
- esCreateWindow ( &esContext, "ParticleSystem", 640, 480, ES_WINDOW_RGB );
+ esCreateWindow ( &esContext, "ParticleSystem", 320, 240, ES_WINDOW_RGB );
if ( !Init ( &esContext ) )
return 0;
esRegisterDrawFunc ( &esContext, Draw );
- esRegisterUpdateFunc ( &esContext, Update );
+// esRegisterUpdateFunc ( &esContext, Update );
- esMainLoop ( &esContext );
+ Draw (&esContext);
+ Draw (&esContext);
+ //esMainLoop ( &esContext );
ShutDown ( &esContext );
}
diff --git a/tests/glbook/Makefile b/tests/glbook/Makefile index cd5f8aee..62cffedf 100644 --- a/tests/glbook/Makefile +++ b/tests/glbook/Makefile @@ -29,9 +29,9 @@ all: ./Chapter_2/Hello_Triangle/CH02_HelloTriangle.bc \ ./Chapter_9/Simple_TextureCubemap/CH09_TextureCubemap.bc \ ./Chapter_9/TextureWrap/CH09_TextureWrap.bc \ ./Chapter_10/MultiTexture/CH10_MultiTexture.bc \ + ./Chapter_13/ParticleSystem/CH13_ParticleSystem.bc # ./Chapter_11/Multisample/CH11_Multisample.bc \ # ./Chapter_11/Stencil_Test/CH11_Stencil_Test.bc \ -# ./Chapter_13/ParticleSystem/CH13_ParticleSystem.bc clean: find . -name "CH??_*" | xargs rm -f diff --git a/tests/runner.py b/tests/runner.py index 1c822ac9..21be107c 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -6639,8 +6639,8 @@ elif 'browser' in str(sys.argv): } img.src = '%s'; }; - Module.postRun = doReftest; - Module.preRun = function() { + Module['postRun'] = doReftest; + Module['preRun'] = function() { setTimeout(doReftest, 0); // if run() throws an exception and postRun is not called, this will kick in }; ''' % basename) @@ -6928,6 +6928,7 @@ elif 'browser' in str(sys.argv): os.path.join('Chapter_9', 'Simple_TextureCubemap', 'CH09_TextureCubemap.bc'), os.path.join('Chapter_9', 'TextureWrap', 'CH09_TextureWrap.bc'), os.path.join('Chapter_10', 'MultiTexture', 'CH10_MultiTexture.bc'), + os.path.join('Chapter_13', 'ParticleSystem', 'CH13_ParticleSystem.bc'), ], configure=None) for program in programs: print program @@ -6937,6 +6938,10 @@ elif 'browser' in str(sys.argv): shutil.copyfile(path_from_root('tests', 'glbook', 'Chapter_10', 'MultiTexture', 'basemap.tga'), os.path.join(self.get_dir(), 'basemap.tga')) shutil.copyfile(path_from_root('tests', 'glbook', 'Chapter_10', 'MultiTexture', 'lightmap.tga'), os.path.join(self.get_dir(), 'lightmap.tga')) args = ['--preload-file', 'basemap.tga', '--preload-file', 'lightmap.tga'] + elif basename == 'CH13_ParticleSystem.bc': + shutil.copyfile(path_from_root('tests', 'glbook', 'Chapter_13', 'ParticleSystem', 'smoke.tga'), os.path.join(self.get_dir(), 'smoke.tga')) + args = ['--preload-file', 'smoke.tga', '-O2'] # test optimizations and closure here as well for more coverage + self.reftest(path_from_root('tests', 'glbook', basename.replace('.bc', '.png'))) Popen(['python', EMCC, program, '-o', 'program.html', '--pre-js', 'reftest.js'] + args).communicate() self.run_browser('program.html', '', '/report_result?0') |