Separating out the Sky rendering as a separate unit and ssg-ifying it.
This commit is contained in:
parent
7cfecd71a3
commit
e6d5923ad0
4 changed files with 80 additions and 64 deletions
src
|
@ -57,7 +57,6 @@
|
||||||
|
|
||||||
#include <Aircraft/aircraft.hxx>
|
#include <Aircraft/aircraft.hxx>
|
||||||
#include <Airports/simple.hxx>
|
#include <Airports/simple.hxx>
|
||||||
#include <Astro/skydome.hxx>
|
|
||||||
#include <Astro/stars.hxx>
|
#include <Astro/stars.hxx>
|
||||||
#include <Astro/solarsystem.hxx>
|
#include <Astro/solarsystem.hxx>
|
||||||
#include <Autopilot/autopilot.hxx>
|
#include <Autopilot/autopilot.hxx>
|
||||||
|
@ -71,6 +70,7 @@
|
||||||
#include <Joystick/joystick.hxx>
|
#include <Joystick/joystick.hxx>
|
||||||
#include <Scenery/scenery.hxx>
|
#include <Scenery/scenery.hxx>
|
||||||
#include <Scenery/tilemgr.hxx>
|
#include <Scenery/tilemgr.hxx>
|
||||||
|
#include <Sky/skydome.hxx>
|
||||||
#include <Time/event.hxx>
|
#include <Time/event.hxx>
|
||||||
#include <Time/fg_time.hxx>
|
#include <Time/fg_time.hxx>
|
||||||
#include <Time/light.hxx>
|
#include <Time/light.hxx>
|
||||||
|
|
|
@ -74,7 +74,6 @@
|
||||||
#include <Include/general.hxx>
|
#include <Include/general.hxx>
|
||||||
|
|
||||||
#include <Aircraft/aircraft.hxx>
|
#include <Aircraft/aircraft.hxx>
|
||||||
#include <Astro/skydome.hxx>
|
|
||||||
#include <Astro/stars.hxx>
|
#include <Astro/stars.hxx>
|
||||||
#include <Astro/solarsystem.hxx>
|
#include <Astro/solarsystem.hxx>
|
||||||
|
|
||||||
|
@ -88,6 +87,8 @@
|
||||||
#include <Objects/materialmgr.hxx>
|
#include <Objects/materialmgr.hxx>
|
||||||
#include <Scenery/scenery.hxx>
|
#include <Scenery/scenery.hxx>
|
||||||
#include <Scenery/tilemgr.hxx>
|
#include <Scenery/tilemgr.hxx>
|
||||||
|
#include <Sky/skydome.hxx>
|
||||||
|
#include <Sky/sphere.hxx>
|
||||||
#include <Time/event.hxx>
|
#include <Time/event.hxx>
|
||||||
#include <Time/fg_time.hxx>
|
#include <Time/fg_time.hxx>
|
||||||
#include <Time/fg_timer.hxx>
|
#include <Time/fg_timer.hxx>
|
||||||
|
@ -145,10 +146,6 @@ ssgBranch *terrain = NULL;
|
||||||
ssgSelector *penguin_sel = NULL;
|
ssgSelector *penguin_sel = NULL;
|
||||||
ssgTransform *penguin_pos = NULL;
|
ssgTransform *penguin_pos = NULL;
|
||||||
|
|
||||||
// the sky needs to be drawn in a specific order, thus we use several
|
|
||||||
// "roots" so we can explicitely control this.
|
|
||||||
ssgRoot *sky = NULL;
|
|
||||||
|
|
||||||
#ifdef FG_NETWORK_OLK
|
#ifdef FG_NETWORK_OLK
|
||||||
ssgSelector *fgd_sel = NULL;
|
ssgSelector *fgd_sel = NULL;
|
||||||
ssgTransform *fgd_pos = NULL;
|
ssgTransform *fgd_pos = NULL;
|
||||||
|
@ -188,6 +185,31 @@ sgMat4 copy_of_ssgOpenGLAxisSwapMatrix =
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
|
ssgSimpleState *default_state;
|
||||||
|
ssgSimpleState *hud_and_panel;
|
||||||
|
ssgSimpleState *menus;
|
||||||
|
|
||||||
|
void fgBuildRenderStates( void ) {
|
||||||
|
default_state = new ssgSimpleState;
|
||||||
|
default_state->disable( GL_TEXTURE_2D );
|
||||||
|
default_state->enable( GL_CULL_FACE );
|
||||||
|
default_state->disable( GL_COLOR_MATERIAL );
|
||||||
|
default_state->disable( GL_BLEND );
|
||||||
|
default_state->disable( GL_ALPHA_TEST );
|
||||||
|
default_state->disable( GL_LIGHTING );
|
||||||
|
|
||||||
|
hud_and_panel = new ssgSimpleState;
|
||||||
|
hud_and_panel->disable( GL_CULL_FACE );
|
||||||
|
hud_and_panel->disable( GL_TEXTURE_2D );
|
||||||
|
hud_and_panel->disable( GL_LIGHTING );
|
||||||
|
|
||||||
|
menus = new ssgSimpleState;
|
||||||
|
menus->disable( GL_CULL_FACE );
|
||||||
|
menus->disable( GL_TEXTURE_2D );
|
||||||
|
menus->enable( GL_BLEND );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// fgInitVisuals() -- Initialize various GL/view parameters
|
// fgInitVisuals() -- Initialize various GL/view parameters
|
||||||
void fgInitVisuals( void ) {
|
void fgInitVisuals( void ) {
|
||||||
fgLIGHT *l;
|
fgLIGHT *l;
|
||||||
|
@ -310,6 +332,7 @@ void fgRenderFrame( void ) {
|
||||||
// ssg does to set up the model view matrix
|
// ssg does to set up the model view matrix
|
||||||
xglMatrixMode(GL_MODELVIEW);
|
xglMatrixMode(GL_MODELVIEW);
|
||||||
xglLoadIdentity();
|
xglLoadIdentity();
|
||||||
|
ssgSetCamera( current_view.VIEW );
|
||||||
|
|
||||||
/*
|
/*
|
||||||
sgMat4 vm_tmp, view_mat;
|
sgMat4 vm_tmp, view_mat;
|
||||||
|
@ -319,42 +342,48 @@ void fgRenderFrame( void ) {
|
||||||
xglLoadMatrixf( (float *)view_mat );
|
xglLoadMatrixf( (float *)view_mat );
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// set the opengl state to known default values
|
||||||
|
default_state->force();
|
||||||
|
|
||||||
// draw sky
|
// draw sky
|
||||||
xglDisable( GL_DEPTH_TEST );
|
xglDisable( GL_DEPTH_TEST );
|
||||||
// xglDisable( GL_LIGHTING );
|
|
||||||
xglDisable( GL_CULL_FACE );
|
|
||||||
xglDisable( GL_FOG );
|
xglDisable( GL_FOG );
|
||||||
xglDisable( GL_TEXTURE_2D );
|
// xglDisable( GL_TEXTURE_2D );
|
||||||
|
// xglDisable( GL_LIGHTING );
|
||||||
|
// xglDisable( GL_CULL_FACE );
|
||||||
|
// xglShadeModel( GL_SMOOTH );
|
||||||
|
|
||||||
/* if ( current_options.get_fog() > 0 ) {
|
/* if ( current_options.get_fog() > 0 ) {
|
||||||
xglEnable( GL_FOG );
|
xglEnable( GL_FOG );
|
||||||
xglFogi( GL_FOG_MODE, GL_EXP2 );
|
xglFogi( GL_FOG_MODE, GL_EXP2 );
|
||||||
xglFogfv( GL_FOG_COLOR, l->adj_fog_color );
|
xglFogfv( GL_FOG_COLOR, l->adj_fog_color );
|
||||||
} */
|
} */
|
||||||
|
|
||||||
xglShadeModel( GL_SMOOTH );
|
|
||||||
|
|
||||||
// if ( current_options.get_skyblend() ) {
|
if ( current_options.get_skyblend() ) {
|
||||||
// fgSkyRender();
|
// fgSkyRender();
|
||||||
// }
|
|
||||||
sgVec3 zero_elev;
|
|
||||||
sgSetVec3( zero_elev,
|
|
||||||
current_view.get_cur_zero_elev().x(),
|
|
||||||
current_view.get_cur_zero_elev().y(),
|
|
||||||
current_view.get_cur_zero_elev().z() );
|
|
||||||
|
|
||||||
current_sky.repaint( cur_light_params.sky_color,
|
sgVec3 zero_elev;
|
||||||
cur_light_params.fog_color,
|
sgSetVec3( zero_elev,
|
||||||
cur_light_params.sun_angle );
|
current_view.get_cur_zero_elev().x(),
|
||||||
|
current_view.get_cur_zero_elev().y(),
|
||||||
|
current_view.get_cur_zero_elev().z() );
|
||||||
|
|
||||||
current_sky.reposition( zero_elev,
|
current_sky.repaint( cur_light_params.sky_color,
|
||||||
cur_fdm_state->get_Longitude(),
|
cur_light_params.fog_color,
|
||||||
cur_fdm_state->get_Latitude(),
|
cur_light_params.sun_angle );
|
||||||
cur_light_params.sun_rotation );
|
|
||||||
|
|
||||||
xglPushMatrix();
|
current_sky.reposition( zero_elev,
|
||||||
ssgSetCamera( current_view.VIEW );
|
cur_fdm_state->get_Longitude(),
|
||||||
ssgCullAndDraw( sky );
|
cur_fdm_state->get_Latitude(),
|
||||||
xglPopMatrix();
|
cur_light_params.sun_rotation );
|
||||||
|
|
||||||
|
xglPushMatrix();
|
||||||
|
|
||||||
|
current_sky.draw();
|
||||||
|
|
||||||
|
xglPopMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
// xglDisable( GL_FOG );
|
// xglDisable( GL_FOG );
|
||||||
|
|
||||||
|
@ -385,11 +414,11 @@ void fgRenderFrame( void ) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// draw scenery
|
// draw scenery
|
||||||
if ( current_options.get_shading() ) {
|
/* if ( current_options.get_shading() ) {
|
||||||
xglShadeModel( GL_SMOOTH );
|
xglShadeModel( GL_SMOOTH );
|
||||||
} else {
|
} else {
|
||||||
xglShadeModel( GL_FLAT );
|
xglShadeModel( GL_FLAT );
|
||||||
}
|
} */
|
||||||
xglEnable( GL_DEPTH_TEST );
|
xglEnable( GL_DEPTH_TEST );
|
||||||
if ( current_options.get_fog() > 0 ) {
|
if ( current_options.get_fog() > 0 ) {
|
||||||
xglEnable( GL_FOG );
|
xglEnable( GL_FOG );
|
||||||
|
@ -495,7 +524,7 @@ void fgRenderFrame( void ) {
|
||||||
// xglLightfv(GL_LIGHT0, GL_SPECULAR, white );
|
// xglLightfv(GL_LIGHT0, GL_SPECULAR, white );
|
||||||
|
|
||||||
// texture parameters
|
// texture parameters
|
||||||
xglEnable( GL_TEXTURE_2D );
|
// xglEnable( GL_TEXTURE_2D );
|
||||||
xglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
|
xglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
|
||||||
xglHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
|
xglHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
|
||||||
// set base color (I don't think this is doing anything here)
|
// set base color (I don't think this is doing anything here)
|
||||||
|
@ -504,26 +533,6 @@ void fgRenderFrame( void ) {
|
||||||
// xglMaterialfv (GL_FRONT, GL_SPECULAR, white);
|
// xglMaterialfv (GL_FRONT, GL_SPECULAR, white);
|
||||||
// xglMaterialfv (GL_FRONT, GL_SHININESS, mat_shininess);
|
// xglMaterialfv (GL_FRONT, GL_SHININESS, mat_shininess);
|
||||||
|
|
||||||
#if 0
|
|
||||||
if ( current_options.get_textures() ) {
|
|
||||||
// texture parameters
|
|
||||||
xglEnable( GL_TEXTURE_2D );
|
|
||||||
xglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ;
|
|
||||||
xglHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST ) ;
|
|
||||||
// set base color (I don't think this is doing anything here)
|
|
||||||
xglMaterialfv (GL_FRONT, GL_AMBIENT, white);
|
|
||||||
xglMaterialfv (GL_FRONT, GL_DIFFUSE, white);
|
|
||||||
// xglMaterialfv (GL_FRONT, GL_SPECULAR, white);
|
|
||||||
// xglMaterialfv (GL_FRONT, GL_SHININESS, mat_shininess);
|
|
||||||
} else {
|
|
||||||
xglDisable( GL_TEXTURE_2D );
|
|
||||||
xglMaterialfv (GL_FRONT, GL_AMBIENT, terrain_color);
|
|
||||||
xglMaterialfv (GL_FRONT, GL_DIFFUSE, terrain_color);
|
|
||||||
// xglMaterialfv (GL_FRONT, GL_AMBIENT, white);
|
|
||||||
// xglMaterialfv (GL_FRONT, GL_DIFFUSE, white);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
sgVec3 sunpos;
|
sgVec3 sunpos;
|
||||||
sgSetVec3( sunpos, l->sun_vec[0], l->sun_vec[1], l->sun_vec[2] );
|
sgSetVec3( sunpos, l->sun_vec[0], l->sun_vec[1], l->sun_vec[2] );
|
||||||
ssgGetLight( 0 ) -> setPosition( sunpos );
|
ssgGetLight( 0 ) -> setPosition( sunpos );
|
||||||
|
@ -619,20 +628,23 @@ void fgRenderFrame( void ) {
|
||||||
// draw the ssg scene
|
// draw the ssg scene
|
||||||
ssgCullAndDraw( scene );
|
ssgCullAndDraw( scene );
|
||||||
|
|
||||||
xglDisable( GL_TEXTURE_2D );
|
|
||||||
xglDisable( GL_FOG );
|
|
||||||
|
|
||||||
// display HUD && Panel
|
// display HUD && Panel
|
||||||
xglDisable( GL_CULL_FACE );
|
xglDisable( GL_FOG );
|
||||||
|
xglDisable( GL_DEPTH_TEST );
|
||||||
|
// xglDisable( GL_CULL_FACE );
|
||||||
|
// xglDisable( GL_TEXTURE_2D );
|
||||||
|
hud_and_panel->apply();
|
||||||
fgCockpitUpdate();
|
fgCockpitUpdate();
|
||||||
|
|
||||||
// We can do translucent menus, so why not. :-)
|
// We can do translucent menus, so why not. :-)
|
||||||
xglEnable ( GL_BLEND ) ;
|
// xglEnable ( GL_BLEND ) ;
|
||||||
|
menus->apply();
|
||||||
xglBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
|
xglBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
|
||||||
puDisplay();
|
puDisplay();
|
||||||
xglDisable ( GL_BLEND ) ;
|
// xglDisable ( GL_BLEND ) ;
|
||||||
xglEnable( GL_FOG );
|
|
||||||
|
|
||||||
|
// xglEnable( GL_FOG );
|
||||||
}
|
}
|
||||||
|
|
||||||
xglutSwapBuffers();
|
xglutSwapBuffers();
|
||||||
|
@ -1345,16 +1357,16 @@ int main( int argc, char **argv ) {
|
||||||
terrain->setName( "Terrain" );
|
terrain->setName( "Terrain" );
|
||||||
scene->addKid( terrain );
|
scene->addKid( terrain );
|
||||||
|
|
||||||
// Sky branch
|
// Initialize the sky
|
||||||
sky = new ssgRoot;
|
current_sky.initialize();
|
||||||
sky->setName( "Sky" );
|
|
||||||
current_sky.initialize( sky );
|
|
||||||
|
|
||||||
// temporary visible aircraft "own ship"
|
// temporary visible aircraft "own ship"
|
||||||
penguin_sel = new ssgSelector;
|
penguin_sel = new ssgSelector;
|
||||||
penguin_pos = new ssgTransform;
|
penguin_pos = new ssgTransform;
|
||||||
ssgEntity *tux_obj = ssgLoadAC( "glider.ac" );
|
ssgBranch *tux_obj = ssgMakeSphere( 10.0, 10, 10 );
|
||||||
|
// ssgEntity *tux_obj = ssgLoadAC( "glider.ac" );
|
||||||
// ssgEntity *tux_obj = ssgLoadAC( "Tower1x.ac" );
|
// ssgEntity *tux_obj = ssgLoadAC( "Tower1x.ac" );
|
||||||
|
|
||||||
penguin_pos->addKid( tux_obj );
|
penguin_pos->addKid( tux_obj );
|
||||||
penguin_sel->addKid( penguin_pos );
|
penguin_sel->addKid( penguin_pos );
|
||||||
ssgFlatten( tux_obj );
|
ssgFlatten( tux_obj );
|
||||||
|
@ -1369,6 +1381,9 @@ int main( int argc, char **argv ) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// build our custom render states
|
||||||
|
fgBuildRenderStates();
|
||||||
|
|
||||||
// pass control off to the master GLUT event handler
|
// pass control off to the master GLUT event handler
|
||||||
glutMainLoop();
|
glutMainLoop();
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ SUBDIRS = \
|
||||||
$(NETWORK_DIRS) \
|
$(NETWORK_DIRS) \
|
||||||
Objects \
|
Objects \
|
||||||
Scenery \
|
Scenery \
|
||||||
|
Sky \
|
||||||
Time \
|
Time \
|
||||||
$(WEATHER_DIR) \
|
$(WEATHER_DIR) \
|
||||||
Main
|
Main
|
||||||
|
|
|
@ -197,7 +197,7 @@ fgMATERIAL_MGR::load_lib ( void )
|
||||||
textured->setShadeModel( GL_FLAT );
|
textured->setShadeModel( GL_FLAT );
|
||||||
}
|
}
|
||||||
|
|
||||||
textured->enable ( GL_CULL_FACE ) ;
|
textured->enable ( GL_CULL_FACE ) ;
|
||||||
textured->enable( GL_TEXTURE_2D );
|
textured->enable( GL_TEXTURE_2D );
|
||||||
textured->setTexture( (char *)tex_file.c_str() );
|
textured->setTexture( (char *)tex_file.c_str() );
|
||||||
textured->setMaterial ( GL_AMBIENT_AND_DIFFUSE, 1, 1, 1, 1 ) ;
|
textured->setMaterial ( GL_AMBIENT_AND_DIFFUSE, 1, 1, 1, 1 ) ;
|
||||||
|
|
Loading…
Add table
Reference in a new issue