X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FObjects%2Fmaterialmgr.cxx;h=315b756f64dae7dcf0873ab5ae73940e080a3fd4;hb=c3753bf6201d1482651f2cfb353476eb40ace4fe;hp=182235a6bc02c5d7d8ec53ffc95ae66b664d9063;hpb=14a8533f636b7d4ad5d95cff30e4d46b42eb57ca;p=flightgear.git diff --git a/src/Objects/materialmgr.cxx b/src/Objects/materialmgr.cxx index 182235a6b..315b756f6 100644 --- a/src/Objects/materialmgr.cxx +++ b/src/Objects/materialmgr.cxx @@ -69,19 +69,24 @@ FGMaterialSlot::~FGMaterialSlot ( void ) { // Constructor fgMATERIAL_MGR::fgMATERIAL_MGR ( void ) { - textures_loaded = false; + materials_loaded = false; } void FGMaterialSlot::render_fragments() { + FG_LOG( FG_GENERAL, FG_ALERT, + "FGMaterialSlot::render_fragments() is depricated ... " << + "we shouldn't be here!" ); + int tris_rendered = current_view.get_tris_rendered(); // cout << "rendering " + texture_name + " = " << list_size << "\n"; - if ( empty() ) + if ( empty() ) { return; + } if ( current_options.get_textures() ) { @@ -116,7 +121,7 @@ FGMaterialSlot::render_fragments() // Woohoo!!! We finally get to draw something! // printf(" display_list = %d\n", frag_ptr->display_list); - xglCallList( frag_ptr->display_list ); + // xglCallList( frag_ptr->display_list ); } current_view.set_tris_rendered( tris_rendered ); @@ -134,12 +139,18 @@ fgMATERIAL_MGR::load_lib ( void ) mpath.append( "materials" ); fg_gzifstream in( mpath.str() ); - if ( ! in ) { + if ( ! in.is_open() ) { FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << mpath.str() ); exit(-1); } +#ifndef __MWERKS__ while ( ! in.eof() ) { +#else + char c = '\0'; + while ( in.get(c) && c != '\0' ) { + in.putback(c); +#endif // printf("%s", line); // strip leading white space and comments @@ -157,18 +168,61 @@ fgMATERIAL_MGR::load_lib ( void ) FGMaterial m; in >> m; - // if ( current_options.get_textures() ) { - // m.load_texture( current_options.get_fg_root() ); - // } - FGMaterialSlot m_slot; m_slot.set_m( m ); + + // build the ssgSimpleState + FGPath tex_file( current_options.get_fg_root() ); + tex_file.append( "Textures" ); + tex_file.append( m.get_texture_name() ); + tex_file.concat( ".rgb" ); + + ssgSimpleState *state = new ssgSimpleState; + state->enable( GL_LIGHTING ); + if ( current_options.get_shading() == 1 ) { + state->setShadeModel( GL_SMOOTH ); + } else { + 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] + << "," << 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] ) ; + } + m_slot.set_state( state ); + material_mgr.material_map[material_name] = m_slot; } } if ( current_options.get_textures() ) { - textures_loaded = true; + materials_loaded = true; } return(1);