Better no-texture support contributed by David Megginson.
This commit is contained in:
parent
43143ef358
commit
7638109583
3 changed files with 76 additions and 42 deletions
|
@ -451,12 +451,10 @@ void GLUTspecialkey(int k, int x, int y) {
|
||||||
if ( material_mgr.loaded() ) {
|
if ( material_mgr.loaded() ) {
|
||||||
if (current_options.get_textures()) {
|
if (current_options.get_textures()) {
|
||||||
current_options.set_textures(false);
|
current_options.set_textures(false);
|
||||||
glDisable(GL_TEXTURE_2D);
|
material_mgr.set_step(1);
|
||||||
ssgOverrideTexture(true);
|
|
||||||
} else {
|
} else {
|
||||||
current_options.set_textures(true);
|
current_options.set_textures(true);
|
||||||
glEnable(GL_TEXTURE_2D);
|
material_mgr.set_step(0);
|
||||||
ssgOverrideTexture(false);
|
|
||||||
}
|
}
|
||||||
FG_LOG( FG_INPUT, FG_INFO, "Toggling texture" );
|
FG_LOG( FG_INPUT, FG_INFO, "Toggling texture" );
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -177,54 +177,73 @@ fgMATERIAL_MGR::load_lib ( void )
|
||||||
tex_file.append( m.get_texture_name() );
|
tex_file.append( m.get_texture_name() );
|
||||||
tex_file.concat( ".rgb" );
|
tex_file.concat( ".rgb" );
|
||||||
|
|
||||||
ssgSimpleState *state = new ssgSimpleState;
|
ssgStateSelector *state = new ssgStateSelector(2);
|
||||||
|
state->setStep(0, new ssgSimpleState); // textured
|
||||||
|
state->setStep(1, new ssgSimpleState); // untextured
|
||||||
|
|
||||||
|
// Set up the textured state
|
||||||
|
state->selectStep(0);
|
||||||
state->enable( GL_LIGHTING );
|
state->enable( GL_LIGHTING );
|
||||||
if ( current_options.get_shading() == 1 ) {
|
if ( current_options.get_shading() == 1 ) {
|
||||||
state->setShadeModel( GL_SMOOTH );
|
state->setShadeModel( GL_SMOOTH );
|
||||||
} else {
|
} else {
|
||||||
state->setShadeModel( GL_FLAT );
|
state->setShadeModel( GL_FLAT );
|
||||||
}
|
}
|
||||||
state->enable ( GL_CULL_FACE ) ;
|
|
||||||
if ( current_options.get_textures() ) {
|
|
||||||
state->enable( GL_TEXTURE_2D );
|
|
||||||
state->setTexture( (char *)tex_file.c_str() );
|
|
||||||
state->setMaterial ( GL_AMBIENT_AND_DIFFUSE, 1, 1, 1, 1 ) ;
|
|
||||||
state->setMaterial ( GL_SPECULAR, 0, 0, 0, 0 ) ;
|
|
||||||
state->setMaterial ( GL_EMISSION, 0, 0, 0, 0 ) ;
|
|
||||||
} else {
|
|
||||||
state->disable( GL_TEXTURE_2D );
|
|
||||||
state->disable( GL_COLOR_MATERIAL );
|
|
||||||
GLfloat *ambient, *diffuse, *specular, *emission;
|
|
||||||
ambient = m.get_ambient();
|
|
||||||
diffuse = m.get_diffuse();
|
|
||||||
specular = m.get_specular();
|
|
||||||
emission = m.get_emission();
|
|
||||||
|
|
||||||
/* cout << "ambient = " << ambient[0] << "," << ambient[1]
|
state->enable ( GL_CULL_FACE ) ;
|
||||||
<< "," << ambient[2] << endl; */
|
state->enable( GL_TEXTURE_2D );
|
||||||
state->setMaterial ( GL_AMBIENT,
|
state->setTexture( (char *)tex_file.c_str() );
|
||||||
ambient[0], ambient[1],
|
state->setMaterial ( GL_AMBIENT_AND_DIFFUSE, 1, 1, 1, 1 ) ;
|
||||||
ambient[2], ambient[3] ) ;
|
state->setMaterial ( GL_SPECULAR, 0, 0, 0, 0 ) ;
|
||||||
state->setMaterial ( GL_DIFFUSE,
|
state->setMaterial ( GL_EMISSION, 0, 0, 0, 0 ) ;
|
||||||
diffuse[0], diffuse[1],
|
|
||||||
diffuse[2], diffuse[3] ) ;
|
// Set up the coloured state
|
||||||
state->setMaterial ( GL_SPECULAR,
|
state->selectStep(1);
|
||||||
specular[0], specular[1],
|
state->enable( GL_LIGHTING );
|
||||||
specular[2], specular[3] ) ;
|
if ( current_options.get_shading() == 1 ) {
|
||||||
state->setMaterial ( GL_EMISSION,
|
state->setShadeModel( GL_SMOOTH );
|
||||||
emission[0], emission[1],
|
} else {
|
||||||
emission[2], emission[3] ) ;
|
state->setShadeModel( GL_FLAT );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
state->enable ( GL_CULL_FACE ) ;
|
||||||
|
state->disable( GL_TEXTURE_2D );
|
||||||
|
state->disable( GL_COLOR_MATERIAL );
|
||||||
|
GLfloat *ambient, *diffuse, *specular, *emission;
|
||||||
|
ambient = m.get_ambient();
|
||||||
|
diffuse = m.get_diffuse();
|
||||||
|
specular = m.get_specular();
|
||||||
|
emission = m.get_emission();
|
||||||
|
|
||||||
|
/* cout << "ambient = " << ambient[0] << "," << ambient[1]
|
||||||
|
<< "," << ambient[2] << endl; */
|
||||||
|
state->setMaterial ( GL_AMBIENT,
|
||||||
|
ambient[0], ambient[1],
|
||||||
|
ambient[2], ambient[3] ) ;
|
||||||
|
state->setMaterial ( GL_DIFFUSE,
|
||||||
|
diffuse[0], diffuse[1],
|
||||||
|
diffuse[2], diffuse[3] ) ;
|
||||||
|
state->setMaterial ( GL_SPECULAR,
|
||||||
|
specular[0], specular[1],
|
||||||
|
specular[2], specular[3] ) ;
|
||||||
|
state->setMaterial ( GL_EMISSION,
|
||||||
|
emission[0], emission[1],
|
||||||
|
emission[2], emission[3] ) ;
|
||||||
|
|
||||||
|
// Choose the appropriate starting state.
|
||||||
|
if ( current_options.get_textures() ) {
|
||||||
|
state->selectStep(0);
|
||||||
|
} else {
|
||||||
|
state->selectStep(1);
|
||||||
|
}
|
||||||
|
|
||||||
m_slot.set_state( state );
|
m_slot.set_state( state );
|
||||||
|
|
||||||
material_mgr.material_map[material_name] = m_slot;
|
material_mgr.material_map[material_name] = m_slot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( current_options.get_textures() ) {
|
materials_loaded = true;
|
||||||
materials_loaded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,6 +277,21 @@ fgMATERIAL_MGR::~fgMATERIAL_MGR ( void ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Set the step for all of the state selectors in the material slots
|
||||||
|
void
|
||||||
|
fgMATERIAL_MGR::set_step ( int step )
|
||||||
|
{
|
||||||
|
// container::iterator it = begin();
|
||||||
|
for (container::iterator it = begin(); it != end(); it++) {
|
||||||
|
const string &key = it->first;
|
||||||
|
FG_LOG( FG_GENERAL, FG_INFO,
|
||||||
|
"Updating material " << key << " to step " << step );
|
||||||
|
FGMaterialSlot &slot = it->second;
|
||||||
|
slot.get_state()->selectStep(step);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
fgMATERIAL_MGR::render_fragments()
|
fgMATERIAL_MGR::render_fragments()
|
||||||
{
|
{
|
||||||
|
|
|
@ -83,7 +83,7 @@ private:
|
||||||
// size_t list_size;
|
// size_t list_size;
|
||||||
|
|
||||||
// ssg stage structure
|
// ssg stage structure
|
||||||
ssgSimpleState *state;
|
ssgStateSelector *state;
|
||||||
bool state_valid;
|
bool state_valid;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -115,8 +115,8 @@ public:
|
||||||
inline void set_m( FGMaterial new_m ) { m = new_m; }
|
inline void set_m( FGMaterial new_m ) { m = new_m; }
|
||||||
|
|
||||||
// ssg state
|
// ssg state
|
||||||
inline ssgSimpleState *get_state() { return state; }
|
inline ssgStateSelector *get_state() { return state; }
|
||||||
inline void set_state( ssgSimpleState *s ) { state = s; }
|
inline void set_state( ssgStateSelector *s ) { state = s; }
|
||||||
inline bool get_state_valid() const { return state_valid; }
|
inline bool get_state_valid() const { return state_valid; }
|
||||||
inline void set_state_valid( bool flag ) { state_valid = flag; }
|
inline void set_state_valid( bool flag ) { state_valid = flag; }
|
||||||
};
|
};
|
||||||
|
@ -153,6 +153,8 @@ public:
|
||||||
|
|
||||||
void render_fragments();
|
void render_fragments();
|
||||||
|
|
||||||
|
void set_step (int step);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~fgMATERIAL_MGR ( void );
|
~fgMATERIAL_MGR ( void );
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue