From 25b743bdec8d04ce3b15d560a942c1d5ee685ee2 Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 22 Aug 2000 02:40:13 +0000 Subject: [PATCH] Preserve initial "state" by careful use of glPushAttrib() and glPopAttrib() being careful to manually call getState()->apply() before the glPushAttrib() so that the ssg state handling mechanism doesn't get derailed accidentally. --- simgear/sky/dome.cxx | 12 ++++++++++-- simgear/sky/moon.cxx | 32 ++++++++++++++++++++++++++------ simgear/sky/oursun.cxx | 30 ++++++++++++++++++++++++++---- simgear/sky/stars.cxx | 15 ++++++++++++--- 4 files changed, 74 insertions(+), 15 deletions(-) diff --git a/simgear/sky/dome.cxx b/simgear/sky/dome.cxx index 74790bb0..0175a563 100644 --- a/simgear/sky/dome.cxx +++ b/simgear/sky/dome.cxx @@ -69,6 +69,13 @@ static int sgSkyDomePreDraw( ssgEntity *e ) { /* cout << endl << "Dome Pre Draw" << endl << "----------------" << endl << endl; */ + + ssgLeaf *f = (ssgLeaf *)e; + if ( f -> hasState () ) f->getState()->apply() ; + + glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_FOG_BIT ); + // cout << "push error = " << glGetError() << endl; + glDisable( GL_DEPTH_TEST ); glDisable( GL_FOG ); @@ -78,9 +85,10 @@ static int sgSkyDomePreDraw( ssgEntity *e ) { static int sgSkyDomePostDraw( ssgEntity *e ) { /* cout << endl << "Dome Post Draw" << endl << "----------------" << endl << endl; */ - glEnable( GL_DEPTH_TEST ); - glEnable( GL_FOG ); + glPopAttrib(); + // cout << "pop error = " << glGetError() << endl; + return true; } diff --git a/simgear/sky/moon.cxx b/simgear/sky/moon.cxx index c16e7e87..c5310fd4 100644 --- a/simgear/sky/moon.cxx +++ b/simgear/sky/moon.cxx @@ -45,6 +45,13 @@ static int sgMoonOrbPreDraw( ssgEntity *e ) { /* cout << endl << "Moon orb pre draw" << endl << "----------------" << endl << endl; */ + + ssgLeaf *f = (ssgLeaf *)e; + if ( f -> hasState () ) f->getState()->apply() ; + + glPushAttrib( GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT ); + // cout << "push error = " << glGetError() << endl; + glDisable( GL_DEPTH_TEST ); glDisable( GL_FOG ); glBlendFunc ( GL_SRC_ALPHA, GL_ONE ) ; @@ -55,10 +62,13 @@ static int sgMoonOrbPreDraw( ssgEntity *e ) { static int sgMoonOrbPostDraw( ssgEntity *e ) { /* cout << endl << "Moon orb post draw" << endl << "----------------" << endl << endl; */ - glEnable( GL_DEPTH_TEST ); - glEnable( GL_FOG ); - glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; + // glEnable( GL_DEPTH_TEST ); + // glEnable( GL_FOG ); + // glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; + glPopAttrib(); + // cout << "pop error = " << glGetError() << endl; + /* test glDisable( GL_LIGHTING ); glDisable( GL_CULL_FACE ); @@ -73,6 +83,13 @@ static int sgMoonOrbPostDraw( ssgEntity *e ) { static int sgMoonHaloPreDraw( ssgEntity *e ) { /* cout << endl << "Moon halo pre draw" << endl << "----------------" << endl << endl; */ + + ssgLeaf *f = (ssgLeaf *)e; + if ( f -> hasState () ) f->getState()->apply() ; + + glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_FOG_BIT | GL_COLOR_BUFFER_BIT); + cout << "push error = " << glGetError() << endl; + glDisable( GL_DEPTH_TEST ); glDisable( GL_FOG ); glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; @@ -83,9 +100,12 @@ static int sgMoonHaloPreDraw( ssgEntity *e ) { static int sgMoonHaloPostDraw( ssgEntity *e ) { /* cout << endl << "Moon halo post draw" << endl << "----------------" << endl << endl; */ - glEnable( GL_DEPTH_TEST ); - glEnable( GL_FOG ); - glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; + // glEnable( GL_DEPTH_TEST ); + // glEnable( GL_FOG ); + // glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; + + glPopAttrib(); + cout << "pop error = " << glGetError() << endl; return true; } diff --git a/simgear/sky/oursun.cxx b/simgear/sky/oursun.cxx index 915f7b28..2cac096c 100644 --- a/simgear/sky/oursun.cxx +++ b/simgear/sky/oursun.cxx @@ -43,6 +43,13 @@ static int sgSunOrbPreDraw( ssgEntity *e ) { /* cout << endl << "Sun orb pre draw" << endl << "----------------" << endl << endl; */ + + ssgLeaf *f = (ssgLeaf *)e; + if ( f -> hasState () ) f->getState()->apply() ; + + glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_FOG_BIT ); + // cout << "push error = " << glGetError() << endl; + glDisable( GL_DEPTH_TEST ); glDisable( GL_FOG ); @@ -52,8 +59,12 @@ static int sgSunOrbPreDraw( ssgEntity *e ) { static int sgSunOrbPostDraw( ssgEntity *e ) { /* cout << endl << "Sun orb post draw" << endl << "----------------" << endl << endl; */ - glEnable( GL_DEPTH_TEST ); - glEnable( GL_FOG ); + + glPopAttrib(); + // cout << "pop error = " << glGetError() << endl; + + // glEnable( GL_DEPTH_TEST ); + // glEnable( GL_FOG ); return true; } @@ -61,6 +72,13 @@ static int sgSunOrbPostDraw( ssgEntity *e ) { static int sgSunHaloPreDraw( ssgEntity *e ) { /* cout << endl << "Sun halo pre draw" << endl << "----------------" << endl << endl; */ + + ssgLeaf *f = (ssgLeaf *)e; + if ( f -> hasState () ) f->getState()->apply() ; + + glPushAttrib( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_FOG_BIT ); + // cout << "push error = " << glGetError() << endl; + glDisable( GL_DEPTH_TEST ); glDisable( GL_FOG ); glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; @@ -71,8 +89,12 @@ static int sgSunHaloPreDraw( ssgEntity *e ) { static int sgSunHaloPostDraw( ssgEntity *e ) { /* cout << endl << "Sun halo post draw" << endl << "----------------" << endl << endl; */ - glEnable( GL_DEPTH_TEST ); - glEnable( GL_FOG ); + + glPopAttrib(); + // cout << "pop error = " << glGetError() << endl; + + // glEnable( GL_DEPTH_TEST ); + // glEnable( GL_FOG ); return true; } diff --git a/simgear/sky/stars.cxx b/simgear/sky/stars.cxx index 4dd4225a..cff2a7dd 100644 --- a/simgear/sky/stars.cxx +++ b/simgear/sky/stars.cxx @@ -47,9 +47,15 @@ FG_USING_STD(endl); static int sgStarPreDraw( ssgEntity *e ) { /* cout << endl << "Star pre draw" << endl << "----------------" << endl << endl; */ + + ssgLeaf *f = (ssgLeaf *)e; + if ( f -> hasState () ) f->getState()->apply() ; + + glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_FOG_BIT ); + glDisable( GL_DEPTH_TEST ); glDisable( GL_FOG ); - glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; + // glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ; return true; } @@ -57,8 +63,11 @@ static int sgStarPreDraw( ssgEntity *e ) { static int sgStarPostDraw( ssgEntity *e ) { /* cout << endl << "Star post draw" << endl << "----------------" << endl << endl; */ - glEnable( GL_DEPTH_TEST ); - glEnable( GL_FOG ); + + glPopAttrib(); + + // glEnable( GL_DEPTH_TEST ); + // glEnable( GL_FOG ); return true; } -- 2.39.5