From d3bacd0b738416da978c49149f50dbf909c5e41d Mon Sep 17 00:00:00 2001 From: frohlich Date: Fri, 10 Nov 2006 05:30:37 +0000 Subject: [PATCH] Modified Files: simgear/scene/material/mat.cxx simgear/scene/material/matlib.cxx simgear/scene/sky/cloud.cxx simgear/scene/sky/dome.cxx simgear/scene/sky/moon.cxx simgear/scene/sky/oursun.cxx simgear/scene/sky/sphere.cxx simgear/scene/sky/stars.cxx simgear/scene/tgdb/apt_signs.cxx simgear/scene/tgdb/leaf.cxx simgear/scene/tgdb/leaf.hxx simgear/scene/tgdb/obj.cxx simgear/scene/tgdb/pt_lights.cxx simgear/scene/util/SGDebugDrawCallback.hxx simgear/screen/Makefile.am: Use color arrays for every geode. Just use osg::Material instead of osg::Material and the associated mode. --- simgear/scene/material/mat.cxx | 12 +++++-- simgear/scene/material/matlib.cxx | 10 +++--- simgear/scene/sky/cloud.cxx | 2 -- simgear/scene/sky/dome.cxx | 6 ---- simgear/scene/sky/moon.cxx | 2 +- simgear/scene/sky/oursun.cxx | 5 ++- simgear/scene/sky/sphere.cxx | 7 +++- simgear/scene/sky/stars.cxx | 1 - simgear/scene/tgdb/apt_signs.cxx | 1 - simgear/scene/tgdb/leaf.cxx | 3 -- simgear/scene/tgdb/obj.cxx | 5 ++- simgear/scene/tgdb/pt_lights.cxx | 2 -- simgear/scene/util/SGDebugDrawCallback.hxx | 37 ++++++++++++++++++++++ 13 files changed, 66 insertions(+), 27 deletions(-) diff --git a/simgear/scene/material/mat.cxx b/simgear/scene/material/mat.cxx index c9cd8046..e73ba37c 100644 --- a/simgear/scene/material/mat.cxx +++ b/simgear/scene/material/mat.cxx @@ -275,8 +275,6 @@ SGMaterial::build_state( bool defer_tex_load ) stateSet->setAttributeAndModes(cullFace, osg::StateAttribute::ON); stateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON); - stateSet->setMode(GL_BLEND, osg::StateAttribute::OFF); - stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF); if ( !defer_tex_load ) { SG_LOG(SG_INPUT, SG_INFO, " " << _status[i].texture_path ); @@ -294,7 +292,15 @@ SGMaterial::build_state( bool defer_tex_load ) material->setEmission(osg::Material::FRONT_AND_BACK, emission.osg()); material->setShininess(osg::Material::FRONT_AND_BACK, shininess ); stateSet->setAttribute(material); - stateSet->setMode(GL_COLOR_MATERIAL, osg::StateAttribute::ON); + + if (ambient[3] < 1 || diffuse[3] < 1 || + specular[3] < 1 || emission[3] < 1) { + stateSet->setMode(GL_BLEND, osg::StateAttribute::ON); + stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON); + } else { + stateSet->setMode(GL_BLEND, osg::StateAttribute::OFF); + stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF); + } _status[i].state = stateSet; } diff --git a/simgear/scene/material/matlib.cxx b/simgear/scene/material/matlib.cxx index 07a20b11..7a8ea544 100644 --- a/simgear/scene/material/matlib.cxx +++ b/simgear/scene/material/matlib.cxx @@ -216,14 +216,15 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char osg::ref_ptr lightStateSet = new osg::StateSet; { -// lightStateSet->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); -// lightStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON); + lightStateSet->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); lightStateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); // lightStateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON); + lightStateSet->setMode(GL_BLEND, osg::StateAttribute::ON); + lightStateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF); -// lightStateSet->setAttribute(new osg::AlphaFunc(osg::AlphaFunc::GREATER, 0)); -// lightStateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON); + lightStateSet->setAttribute(new osg::AlphaFunc(osg::AlphaFunc::GREATER, 0.01)); + lightStateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON); osg::CullFace* cullFace = new osg::CullFace; cullFace->setMode(osg::CullFace::BACK); @@ -266,7 +267,6 @@ bool SGMaterialLib::load( const string &fg_root, const string& mpath, const char osg::Material* material = new osg::Material; lightStateSet->setAttribute(material); -// lightStateSet->setMode(GL_COLOR_MATERIAL, osg::StateAttribute::OFF); } diff --git a/simgear/scene/sky/cloud.cxx b/simgear/scene/sky/cloud.cxx index f236b46a..b97d39b0 100644 --- a/simgear/scene/sky/cloud.cxx +++ b/simgear/scene/sky/cloud.cxx @@ -43,7 +43,6 @@ #include #include #include -#include #include #include "newcloud.hxx" @@ -117,7 +116,6 @@ SGMakeState(const SGPath &path, const char* colorTexture, const char* normalText // material->setSpecular(osg::Material::FRONT_AND_BACK, // osg::Vec4(0, 0, 0, 1)); // stateSet->setAttribute(material); -// stateSet->setMode(GL_COLOR_MATERIAL, osg::StateAttribute::ON); stateSet->setMode(GL_FOG, osg::StateAttribute::OFF); diff --git a/simgear/scene/sky/dome.cxx b/simgear/scene/sky/dome.cxx index a859958e..e8073c2c 100644 --- a/simgear/scene/sky/dome.cxx +++ b/simgear/scene/sky/dome.cxx @@ -42,7 +42,6 @@ #include #include -#include #include #include "dome.hxx" @@ -107,7 +106,6 @@ SGSkyDome::build( double hscale, double vscale ) { // osg::Vec4(0, 0, 0, 1)); // material->setShininess(osg::Material::FRONT_AND_BACK, 0); stateSet->setAttribute(material); -// stateSet->setMode(GL_COLOR_MATERIAL, osg::StateAttribute::OFF); // initialize arrays // initially seed to all blue @@ -194,7 +192,6 @@ SGSkyDome::build( double hscale, double vscale ) { // into the provide scene graph branch osg::Geometry* geometry = new osg::Geometry; geometry->setName("Dome Center"); -// geometry->setDrawCallback(new SGDebugDrawCallback); geometry->setUseDisplayList(false); geometry->setVertexArray(center_disk_vl.get()); geometry->setColorArray(center_disk_cl.get()); @@ -205,7 +202,6 @@ SGSkyDome::build( double hscale, double vscale ) { geometry = new osg::Geometry; geometry->setName("Dome Upper Ring"); -// geometry->setDrawCallback(new SGDebugDrawCallback); geometry->setUseDisplayList(false); geometry->setVertexArray(upper_ring_vl.get()); geometry->setColorArray(upper_ring_cl.get()); @@ -216,7 +212,6 @@ SGSkyDome::build( double hscale, double vscale ) { geometry = new osg::Geometry; geometry->setName("Dome Middle Ring"); -// geometry->setDrawCallback(new SGDebugDrawCallback); geometry->setUseDisplayList(false); geometry->setVertexArray(middle_ring_vl.get()); geometry->setColorArray(middle_ring_cl.get()); @@ -227,7 +222,6 @@ SGSkyDome::build( double hscale, double vscale ) { geometry = new osg::Geometry; geometry->setName("Dome Lower Ring"); -// geometry->setDrawCallback(new SGDebugDrawCallback); geometry->setUseDisplayList(false); geometry->setVertexArray(lower_ring_vl.get()); geometry->setColorArray(lower_ring_cl.get()); diff --git a/simgear/scene/sky/moon.cxx b/simgear/scene/sky/moon.cxx index 568a89bd..6cfb8788 100644 --- a/simgear/scene/sky/moon.cxx +++ b/simgear/scene/sky/moon.cxx @@ -90,7 +90,7 @@ SGMoon::build( SGPath path, double moon_size ) { orb_material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1)); orb_material->setShininess(osg::Material::FRONT_AND_BACK, 0); - stateSet->setAttributeAndModes(orb_material.get()); + stateSet->setAttribute(orb_material.get()); stateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON); stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); stateSet->setMode(GL_FOG, osg::StateAttribute::OFF); diff --git a/simgear/scene/sky/oursun.cxx b/simgear/scene/sky/oursun.cxx index dd0d2cad..f40f7fd9 100644 --- a/simgear/scene/sky/oursun.cxx +++ b/simgear/scene/sky/oursun.cxx @@ -80,7 +80,7 @@ SGSun::build( SGPath path, double sun_size, SGPropertyNode *property_tree_Node ) osg::Vec4(0, 0, 0, 1)); material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0, 0, 1)); - stateSet->setAttributeAndModes(material); + stateSet->setAttribute(material); osg::ShadeModel* shadeModel = new osg::ShadeModel; shadeModel->setMode(osg::ShadeModel::FLAT); @@ -133,6 +133,7 @@ SGSun::build( SGPath path, double sun_size, SGPropertyNode *property_tree_Node ) geometry->setVertexArray(sun_vl); geometry->setColorArray(sun_cl.get()); geometry->setColorBinding(osg::Geometry::BIND_OVERALL); + geometry->setNormalBinding(osg::Geometry::BIND_OFF); geometry->setTexCoordArray(0, sun_tl); geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, 4)); geode->addDrawable(geometry); @@ -171,6 +172,7 @@ SGSun::build( SGPath path, double sun_size, SGPropertyNode *property_tree_Node ) geometry->setVertexArray(ihalo_vl); geometry->setColorArray(ihalo_cl.get()); geometry->setColorBinding(osg::Geometry::BIND_OVERALL); + geometry->setNormalBinding(osg::Geometry::BIND_OFF); geometry->setTexCoordArray(0, ihalo_tl); geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, 4)); geode->addDrawable(geometry); @@ -210,6 +212,7 @@ SGSun::build( SGPath path, double sun_size, SGPropertyNode *property_tree_Node ) geometry->setVertexArray(ihalo_vl); geometry->setColorArray(ihalo_cl.get()); geometry->setColorBinding(osg::Geometry::BIND_OVERALL); + geometry->setNormalBinding(osg::Geometry::BIND_OFF); geometry->setTexCoordArray(0, ihalo_tl); geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, 4)); geode->addDrawable(geometry); diff --git a/simgear/scene/sky/sphere.cxx b/simgear/scene/sky/sphere.cxx index 11251b0a..bbd68694 100644 --- a/simgear/scene/sky/sphere.cxx +++ b/simgear/scene/sky/sphere.cxx @@ -110,12 +110,17 @@ SGMakeSphere(double radius, int slices, int stacks) exit(-1); } + // colors + osg::Vec4Array* cl = new osg::Vec4Array; + cl->push_back(osg::Vec4(1, 1, 1, 1)); + geometry->setUseDisplayList(false); geometry->setVertexArray(vl); geometry->setNormalArray(nl); geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); geometry->setTexCoordArray(0, tl); - geometry->setColorBinding(osg::Geometry::BIND_OFF); + geometry->setColorArray(cl); + geometry->setColorBinding(osg::Geometry::BIND_OVERALL); geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_STRIP, 0, vl->size())); geode->addDrawable(geometry); diff --git a/simgear/scene/sky/stars.cxx b/simgear/scene/sky/stars.cxx index 22cf539a..bd31aedc 100644 --- a/simgear/scene/sky/stars.cxx +++ b/simgear/scene/sky/stars.cxx @@ -79,7 +79,6 @@ SGStars::build( int num, const SGVec3d star_data[], double star_dist ) { // material->setSpecular(osg::Material::FRONT_AND_BACK, // osg::Vec4(0, 0, 0, 1)); stateSet->setAttribute(material); -// stateSet->setMode(GL_COLOR_MATERIAL, osg::StateAttribute::OFF); osg::BlendFunc* blendFunc = new osg::BlendFunc; blendFunc->setFunction(osg::BlendFunc::SRC_ALPHA, diff --git a/simgear/scene/tgdb/apt_signs.cxx b/simgear/scene/tgdb/apt_signs.cxx index 22d6344b..543882c7 100644 --- a/simgear/scene/tgdb/apt_signs.cxx +++ b/simgear/scene/tgdb/apt_signs.cxx @@ -313,7 +313,6 @@ SGMakeSign(SGMaterialLib *matlib, const string& path, const string& content) cl->push_back(osg::Vec4(1, 1, 1, 1)); osg::Geometry* geometry = new osg::Geometry; -// geometry->setUseDisplayList(false); geometry->setVertexArray(vl); geometry->setNormalArray(nl); geometry->setNormalBinding(osg::Geometry::BIND_OVERALL); diff --git a/simgear/scene/tgdb/leaf.cxx b/simgear/scene/tgdb/leaf.cxx index dd8d743b..1d3e6d94 100644 --- a/simgear/scene/tgdb/leaf.cxx +++ b/simgear/scene/tgdb/leaf.cxx @@ -43,7 +43,6 @@ #include #include #include -// #include #include "leaf.hxx" @@ -234,8 +233,6 @@ osg::Node* SGMakeLeaf( const string& path, osg::Geometry* geometry = new osg::Geometry; -// geometry->setUseDisplayList(false); -// geometry->setDrawCallback(new SGDebugDrawCallback); geometry->setVertexArray(vl); geometry->setNormalArray(nl); geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); diff --git a/simgear/scene/tgdb/obj.cxx b/simgear/scene/tgdb/obj.cxx index a5bfcda9..363c8910 100644 --- a/simgear/scene/tgdb/obj.cxx +++ b/simgear/scene/tgdb/obj.cxx @@ -156,12 +156,15 @@ bool SGGenTile( const string& path, SGBucket b, tl->push_back(osg::Vec2(texs[i].x(), texs[i].y())); } + osg::Vec4Array* cl = new osg::Vec4Array; + cl->push_back(osg::Vec4(1, 1, 1, 1)); osg::Geometry* geometry = new osg::Geometry; geometry->setVertexArray(vl); geometry->setNormalArray(nl); geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); - geometry->setColorBinding(osg::Geometry::BIND_OFF); + geometry->setColorArray(cl); + geometry->setColorBinding(osg::Geometry::BIND_OVERALL); geometry->setTexCoordArray(0, tl); geometry->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLE_FAN, 0, vl->size())); osg::Geode* geode = new osg::Geode; diff --git a/simgear/scene/tgdb/pt_lights.cxx b/simgear/scene/tgdb/pt_lights.cxx index 6097d12d..71fbdcf2 100644 --- a/simgear/scene/tgdb/pt_lights.cxx +++ b/simgear/scene/tgdb/pt_lights.cxx @@ -146,8 +146,6 @@ gen_dir_light_group( const point_list &nodes, osg::Geometry* geometry = new osg::Geometry; geometry->setName("Dir Lights " + mat->get_names().front()); -// geometry->setDrawCallback(new SGDebugDrawCallback); -// geometry->setUseDisplayList(false); geometry->setVertexArray(vl); geometry->setNormalArray(nl); geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); diff --git a/simgear/scene/util/SGDebugDrawCallback.hxx b/simgear/scene/util/SGDebugDrawCallback.hxx index 914d0d1a..5818f641 100644 --- a/simgear/scene/util/SGDebugDrawCallback.hxx +++ b/simgear/scene/util/SGDebugDrawCallback.hxx @@ -26,6 +26,7 @@ #include #include #include +#include struct SGDebugDrawCallback : public osg::Drawable::DrawCallback { virtual void drawImplementation(osg::State& state, @@ -141,6 +142,24 @@ do { \ #undef PRINT_STATE #undef ERROR_CHECK + +#ifdef PRINT_LIGHT +#undef PRINT_LIGHT +#endif +#define PRINT_LIGHT(pname) \ +do { \ + SGVec4f color; \ + glGetLightfv(GL_LIGHT0, pname, color.data());\ + stream << " " #pname " " << color; \ +} while(0) + PRINT_LIGHT(GL_AMBIENT); + PRINT_LIGHT(GL_DIFFUSE); + PRINT_LIGHT(GL_SPECULAR); + PRINT_LIGHT(GL_POSITION); + PRINT_LIGHT(GL_SPOT_DIRECTION); + +#undef PRINT_LIGHT + if (glIsEnabled(GL_COLOR_MATERIAL)) { stream << " GL_COLOR_MATERIAL("; GLint value; @@ -156,6 +175,24 @@ do { \ if (value == GL_SPECULAR) stream << "GL_SPECULAR"; +#ifdef PRINT_MATERIAL +#undef PRINT_MATERIAL +#endif +#define PRINT_MATERIAL(pname) \ +do { \ + SGVec4f color; \ + glGetMaterialfv(GL_FRONT, pname, color.data());\ + stream << " " #pname " GL_FRONT " << color; \ + glGetMaterialfv(GL_BACK, pname, color.data()); \ + stream << " " #pname " GL_BACK " << color; \ +} while(0) + + PRINT_MATERIAL(GL_AMBIENT); + PRINT_MATERIAL(GL_DIFFUSE); + PRINT_MATERIAL(GL_EMISSION); + PRINT_MATERIAL(GL_SPECULAR); +#undef PRINT_MATERIAL + stream << ")"; } -- 2.39.5