diff options
author | David Mikos <metastability@opencompositing.org> | 2007-12-26 10:39:37 +1030 |
---|---|---|
committer | David Mikos <metastability@opencompositing.org> | 2007-12-26 10:39:37 +1030 |
commit | 7a9efa3b9c593e78216369d17a52d9fa33390219 (patch) | |
tree | 5dbdedd0843eb14d9af542046f803bc0b5d54387 | |
parent | ac0a52e21627156cffec2f4b02adbc7ed4bd5127 (diff) | |
download | snowglobe-7a9efa3b9c593e78216369d17a52d9fa33390219.tar.gz snowglobe-7a9efa3b9c593e78216369d17a52d9fa33390219.tar.bz2 |
Precompile snowflakes in display list.
-rw-r--r-- | snowflake.c | 31 | ||||
-rw-r--r-- | snowglobe-internal.h | 17 | ||||
-rw-r--r-- | snowglobe.c | 15 |
3 files changed, 39 insertions, 24 deletions
diff --git a/snowflake.c b/snowflake.c index 76ae798..7155bc2 100644 --- a/snowflake.c +++ b/snowflake.c @@ -85,19 +85,6 @@ static const float N0035[3] = {0.390179, -0.892727, 0.225257}; void DrawSnowflake(int wire) { -glRotatef(180.0, 0.0, 1.0, 0.0); -glRotatef(90.0, 0.0, 1.0, 0.0); -glEnable(GL_CULL_FACE); -glEnable(GL_DEPTH_TEST); -glDisable(GL_NORMALIZE); - - -glDisable (GL_COLOR_MATERIAL); -glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); -glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, null_shininess); -glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, null_ambient); -glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, null_diffuse); -glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, null_specular); GLenum capQuads = wire ? GL_LINE_LOOP : GL_QUADS; glBegin(capQuads); glNormal3fv(N0000); @@ -371,7 +358,23 @@ glVertex3fv(P0028); glNormal3fv(N0031); glVertex3fv(P0031); glEnd (); +} -glDisable(GL_CULL_FACE); +void initDrawSnowflake() { +glRotatef(180.0, 0.0, 1.0, 0.0); +glRotatef(90.0, 0.0, 1.0, 0.0); +glEnable(GL_CULL_FACE); +glEnable(GL_DEPTH_TEST); +glEnable(GL_RESCALE_NORMAL); + +glDisable (GL_COLOR_MATERIAL); +glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, null_shininess); +glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, null_ambient); +glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, null_diffuse); +glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, null_specular); } +void finDrawSnowflake() { +glDisable(GL_CULL_FACE); +} diff --git a/snowglobe-internal.h b/snowglobe-internal.h index 13bcf92..5538a13 100644 --- a/snowglobe-internal.h +++ b/snowglobe-internal.h @@ -142,7 +142,11 @@ void SnowflakeDrift (SnowglobeScreen *, int); void initializeWorldVariables(int, float); void updateSpeedFactor(float); void RenderWater(int, float, Bool, Bool); + void DrawSnowflake (int); +void initDrawSnowflake(void); +void finDrawSnowflake(void); + void DrawSnowman (int); //utility methods @@ -153,7 +157,8 @@ float symmDistr(void); //symmetric distribution //maybe define a struct for these values float speedFactor; // global variable (fish/crab speeds multiplied by this value) -float radius;//radius on which the hSize points lie (corners for odd #, midpoints for even #) +float radius;//radius on which the hSize points lie +float distance;//perpendicular distance to wall from centre float waterHeight; //water surface height int waveGridSize; float waveAmplitude; @@ -162,16 +167,16 @@ float smallWaveAmplitude; float smallWaveFrequency; Bool renderGround; -//All calculations that matter with angles are done clockwise. -//I think of it as x=radius, y=0 being directed from the cetnre towards the 1st desktop +GLuint snowflakeDisplayList; + + +//All calculations that matter with angles are done clockwise from top. +//I think of it as x=radius, y=0 being the top (towards 1st desktop from above view) //and the z coordinate as height. -//NOTE - might scrap *th if it is not used. -float *invTanTh; // 1/tanf(th[index]) - used in calculating perp. distance to wall int hSize; // horizontal desktop size float q; // equal to float version of hSize (replace with hSizef some time) -float distance; #endif diff --git a/snowglobe.c b/snowglobe.c index 4730161..51282be 100644 --- a/snowglobe.c +++ b/snowglobe.c @@ -116,9 +116,12 @@ initSnowglobe (CompScreen *s) waterHeight = 50000; - speedFactor = snowglobeGetSpeedFactor(s); - + + snowflakeDisplayList = glGenLists(1); + glNewList(snowflakeDisplayList, GL_COMPILE); + DrawSnowflake(0); + glEndList(); } void initializeWorldVariables(int hs, float perpDistCentreToWall) { //precalculate some values @@ -140,6 +143,8 @@ freeSnowglobe (CompScreen *s) freeWater (as->water); freeWater (as->ground); + + glDeleteLists(snowflakeDisplayList, 1); } static void @@ -272,7 +277,7 @@ static void snowglobePaintInside (CompScreen *s, glEnable (GL_COLOR_MATERIAL); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - + for (i = 0; i < as->numSnowflakes; i++) { glPushMatrix(); @@ -281,7 +286,9 @@ static void snowglobePaintInside (CompScreen *s, float scale = 0.01*as->snow[i].size; glScalef (scale, scale, scale); - DrawSnowflake(0); + initDrawSnowflake(); + glCallList(snowflakeDisplayList); + finDrawSnowflake(); glPopMatrix(); } |