Hi JS,

As a general guide, with OpenGL setting the glColor on many seperate
objects will be faster than setting it via glMaterial.

Another general hint is the using ShapeDrawable to render sphere's is
not efficient, especially if you are creating/destroying them as it
relies very simple rendering techniques to draw the shapes and display
listing to make up for the OpenGL slow paths used.  ShapeDrawable is
really just a convinience tool, it not a tool for getting good
performance.  Its better to create osg::Geometry to represent your
geometry, this way you can optimize the representation to get best
OpenGL throughput using vertex arrays and index primitives.

Finally, glMaterial and glColor interact, with glColour override the
glMaterial (that is used for the final lighting calculation).  You
really need to read up on glMaterial/glColorMaterial in OpenGL docs
for a good explanation of the what the ins and outs are.
Material::setColorMode is the OSG's equivilant to glColorMaterial.

Robert.

On 12/15/06, Jean-Sebastien Guay <[EMAIL PROTECTED]> wrote:
Hello,

I am trying out some things by creating scene graphs on the fly, and one thing
seems weird in my opinion.

Say I have a ShapeDrawable (with a sphere Shape) attached to a Geode, which is a
child of a Transform. I can call setColor() on the ShapeDrawable to make the
sphere red. That works fine. But I would think that adding a Material with a
diffuse color of red in the stateSet for either the geode or the transform
would have the same effect. But it doesn't seem to.

In other words:

    // The sphere
    osg::ref_ptr<osg::Shape> sphere = new osg::Sphere(osg::Vec3f(0.0, 0.0, 0.0),
1.0);
    osg::ref_ptr<osg::ShapeDrawable> sphereDrawable = new
osg::ShapeDrawable(sphere.get());
    osg::ref_ptr<osg::Geode> sphereGeode = new osg::Geode;
    sphereGeode->addDrawable(sphereDrawable.get());

    // Its transform
    osg::ref_ptr<osg::PositionAttitudeTransform> sphereTransform = new
osg::PositionAttitudeTransform;
    sphereTransform->setPosition(osg::Vec3d(0.0, 0.5, 0.0));
    sphereTransform->addChild(sphereGeode.get());


    // Now try to make the sphere red.
    // This works
    //sphereDrawable->setColor(osg::Vec4f(1, 0, 0, 1));

    // Try it with a Material
    osg::ref_ptr<osg::Material> material = new osg::Material;
    material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4f(1, 0, 0, 1));

    // This does not work
    //sphereTransform->getOrCreateStateSet()->setAttribute(material.get());

    // This does not work either
    //sphereDrawable->getOrCreateStateSet()->setAttribute(material.get());

In all cases except setting the color on the drawable directly, the sphere stays
white (default color I guess).

I tried to pass either osg::StateAttribute::ON or osg::StateAttribute::OVERRIDE
as the second argument to setAttribute(), which changed nothing. Am I missing
something? Is this intended?

I guess I could just fire up some 3D authoring tool, make a unit sphere, load it
into the subgraph under the transform and then I would not use the ShapeDrawable
and that might work, but I would expect the ShapeDrawable to inherit the state
of the geode it's attached to...

Thanks,

J-S
--
______________________________________________________
Jean-Sebastien Guay     [EMAIL PROTECTED]
                        http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to