Discussion:
stateSet texture attribute override
Riccardo Corsi
2007-10-02 16:36:47 UTC
Permalink
Hi all,

I'm after overriding some texture attributes in a hierarchy, following
the osgmultitexture example, from within a "MyTextureSwitcher" node
derived from osg::Group.
I basically want to load a new texture on layer 1 and try to mix/blend
it with the other existing texture on the underlying geometries.
The hierarchy I have is the following:

MyTextureSwitcher
|
MatrixTransform
|
MatrixTransform
|
Geode
|-- geom1
|-- geom2

Now if I try to set the values on the MyTextureSwitcher StateSet,
nothing happen (the new texture file is not even loaded).

If I change the same attributes on the MatrixTrasform instead,
everything works nicely. The attributes I'm adding to override the other
are as well highlighted in the attached image (thanks orhialcon).
Of course, I'd like to do everything in the MyTextureSwitcher stateset,
as this is a node that I can add or remove to obtain different effects.

My code is:

MyTextureSwitcher::Setup()
{
[...]
osg::StateSet* pSS = getChild(0)->getOrCreateStateSet(); // working
case
//osg::StateSet* pSS = getOrCreateStateSet(); // NOT working

pSS->setTextureAttributeAndModes(1, mSwitchTex.get(),
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);

osg::TexEnv* texenv = new osg::TexEnv;
texenv->setMode(osg::TexEnv::BLEND);
texenv->setColor(osg::Vec4(0.3f,0.3f,0.3f,0.3f));

pSS->setTextureAttributeAndModes(1,texenv, osg::StateAttribute::ON |
osg::StateAttribute::OVERRIDE);
}

Any clue why the second case is not working?

Thank you,
Ricky
Cedric Pinson
2007-10-02 17:00:41 UTC
Permalink
I thouth the keywords OVERRIDE should be use when you want to override
the Attribute. So i would do something like that:

Switcher:
StateSet - tex0
- tex1
Geode
geom1
stateset - tex0 override
stateset - tex1 override
geom2
stateset - tex0 override
stateset - tex1 override

In this sceme geom 1 et 2 will use for tex0 and tex1 from the switcher

you can read the code here in include/osg/State in the function
State::pushAttributeList
It does not anwser directly to you questions but i hope it will help.

Cedric
Post by Riccardo Corsi
Hi all,
I'm after overriding some texture attributes in a hierarchy, following
the osgmultitexture example, from within a "MyTextureSwitcher" node
derived from osg::Group.
I basically want to load a new texture on layer 1 and try to mix/blend
it with the other existing texture on the underlying geometries.
MyTextureSwitcher
|
MatrixTransform
|
MatrixTransform
|
Geode
|-- geom1
|-- geom2
Now if I try to set the values on the MyTextureSwitcher StateSet,
nothing happen (the new texture file is not even loaded).
If I change the same attributes on the MatrixTrasform instead,
everything works nicely. The attributes I'm adding to override the
other are as well highlighted in the attached image (thanks orhialcon).
Of course, I'd like to do everything in the MyTextureSwitcher
stateset, as this is a node that I can add or remove to obtain
different effects.
MyTextureSwitcher::Setup()
{
[...]
osg::StateSet* pSS = getChild(0)->getOrCreateStateSet(); //
working case
//osg::StateSet* pSS = getOrCreateStateSet(); // NOT working
pSS->setTextureAttributeAndModes(1, mSwitchTex.get(),
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
osg::TexEnv* texenv = new osg::TexEnv;
texenv->setMode(osg::TexEnv::BLEND);
texenv->setColor(osg::Vec4(0.3f,0.3f,0.3f,0.3f));
pSS->setTextureAttributeAndModes(1,texenv, osg::StateAttribute::ON
| osg::StateAttribute::OVERRIDE);
}
Any clue why the second case is not working?
Thank you,
Ricky
------------------------------------------------------------------------
------------------------------------------------------------------------
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
--
+33 (0) 6 63 20 03 56 Cedric Pinson mailto:mornifle-***@public.gmane.org http://www.plopbyte.net
Riccardo Corsi
2007-10-02 17:31:36 UTC
Permalink
Hi Cedric,

I believe the override keyword works in the other way: when you use it,
you override the attributes of objects that are below in the graph
hierarchy, for instance in the following scheme:

Switcher:
StateSet - tex0
- tex1 override
Geode
geom1
stateset - tex0
stateset - tex1
geom2
stateset - tex0
stateset - tex1

the tex1 from the Switcher StateSet will be used instead of the one
specified in the geoms.
That's exactly what happens in my application when I do the override in
the MatrixTransform.

Unfortunately, it does not work when I apply the same to the Switcher
stateset, don't know why...

Cheers,
Ricky
Post by Cedric Pinson
I thouth the keywords OVERRIDE should be use when you want to override
StateSet - tex0
- tex1
Geode
geom1
stateset - tex0 override
stateset - tex1 override
geom2
stateset - tex0 override
stateset - tex1 override
In this sceme geom 1 et 2 will use for tex0 and tex1 from the switcher
you can read the code here in include/osg/State in the function
State::pushAttributeList
It does not anwser directly to you questions but i hope it will help.
Cedric
Post by Riccardo Corsi
Hi all,
I'm after overriding some texture attributes in a hierarchy, following
the osgmultitexture example, from within a "MyTextureSwitcher" node
derived from osg::Group.
I basically want to load a new texture on layer 1 and try to mix/blend
it with the other existing texture on the underlying geometries.
MyTextureSwitcher
|
MatrixTransform
|
MatrixTransform
|
Geode
|-- geom1
|-- geom2
Now if I try to set the values on the MyTextureSwitcher StateSet,
nothing happen (the new texture file is not even loaded).
If I change the same attributes on the MatrixTrasform instead,
everything works nicely. The attributes I'm adding to override the
other are as well highlighted in the attached image (thanks orhialcon).
Of course, I'd like to do everything in the MyTextureSwitcher
stateset, as this is a node that I can add or remove to obtain
different effects.
MyTextureSwitcher::Setup()
{
[...]
osg::StateSet* pSS = getChild(0)->getOrCreateStateSet(); //
working case
//osg::StateSet* pSS = getOrCreateStateSet(); // NOT working
pSS->setTextureAttributeAndModes(1, mSwitchTex.get(),
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
osg::TexEnv* texenv = new osg::TexEnv;
texenv->setMode(osg::TexEnv::BLEND);
texenv->setColor(osg::Vec4(0.3f,0.3f,0.3f,0.3f));
pSS->setTextureAttributeAndModes(1,texenv, osg::StateAttribute::ON
| osg::StateAttribute::OVERRIDE);
}
Any clue why the second case is not working?
Thank you,
Ricky
------------------------------------------------------------------------
------------------------------------------------------------------------
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
David Spilling
2007-10-03 08:24:39 UTC
Permalink
I've had similar problems due to the optimiser optimising away "empty"
groups that had attached statesets. Are you optimising? If you are, try
outputting the file as .osg and comparing it with and without an optimiser
pass.

David
Post by Riccardo Corsi
Hi Cedric,
I believe the override keyword works in the other way: when you use it,
you override the attributes of objects that are below in the graph
StateSet - tex0
- tex1 override
Geode
geom1
stateset - tex0
stateset - tex1
geom2
stateset - tex0
stateset - tex1
the tex1 from the Switcher StateSet will be used instead of the one
specified in the geoms.
That's exactly what happens in my application when I do the override in
the MatrixTransform.
Unfortunately, it does not work when I apply the same to the Switcher
stateset, don't know why...
Cheers,
Ricky
Post by Cedric Pinson
I thouth the keywords OVERRIDE should be use when you want to override
StateSet - tex0
- tex1
Geode
geom1
stateset - tex0 override
stateset - tex1 override
geom2
stateset - tex0 override
stateset - tex1 override
In this sceme geom 1 et 2 will use for tex0 and tex1 from the switcher
you can read the code here in include/osg/State in the function
State::pushAttributeList
It does not anwser directly to you questions but i hope it will help.
Cedric
Post by Riccardo Corsi
Hi all,
I'm after overriding some texture attributes in a hierarchy, following
the osgmultitexture example, from within a "MyTextureSwitcher" node
derived from osg::Group.
I basically want to load a new texture on layer 1 and try to mix/blend
it with the other existing texture on the underlying geometries.
MyTextureSwitcher
|
MatrixTransform
|
MatrixTransform
|
Geode
|-- geom1
|-- geom2
Now if I try to set the values on the MyTextureSwitcher StateSet,
nothing happen (the new texture file is not even loaded).
If I change the same attributes on the MatrixTrasform instead,
everything works nicely. The attributes I'm adding to override the
other are as well highlighted in the attached image (thanks orhialcon).
Of course, I'd like to do everything in the MyTextureSwitcher
stateset, as this is a node that I can add or remove to obtain
different effects.
MyTextureSwitcher::Setup()
{
[...]
osg::StateSet* pSS = getChild(0)->getOrCreateStateSet(); //
working case
//osg::StateSet* pSS = getOrCreateStateSet(); // NOT working
pSS->setTextureAttributeAndModes(1, mSwitchTex.get(),
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
osg::TexEnv* texenv = new osg::TexEnv;
texenv->setMode(osg::TexEnv::BLEND);
texenv->setColor(osg::Vec4(0.3f,0.3f,0.3f,0.3f));
pSS->setTextureAttributeAndModes(1,texenv, osg::StateAttribute::ON
| osg::StateAttribute::OVERRIDE);
}
Any clue why the second case is not working?
Thank you,
Ricky
------------------------------------------------------------------------
------------------------------------------------------------------------
Post by Cedric Pinson
Post by Riccardo Corsi
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Riccardo Corsi
2007-10-03 09:55:22 UTC
Permalink
Hi David,

I'm a total idiot!
I was not optimizing, but I compared the .osg anyway.
The StateSet were doing their job correctly in both cases, but I was
using replaceChild with and index ("0") instead of child pointer... so
the switcher was never inserted in the graph correctly. (RTFM always...)

Thanks for the tip!
Ricky
Post by David Spilling
I've had similar problems due to the optimiser optimising away "empty"
groups that had attached statesets. Are you optimising? If you are,
try outputting the file as .osg and comparing it with and without an
optimiser pass.
David
Hi Cedric,
I believe the override keyword works in the other way: when you use it,
you override the attributes of objects that are below in the graph
StateSet - tex0
- tex1 override
Geode
geom1
stateset - tex0
stateset - tex1
geom2
stateset - tex0
stateset - tex1
the tex1 from the Switcher StateSet will be used instead of the one
specified in the geoms.
That's exactly what happens in my application when I do the override in
the MatrixTransform.
Unfortunately, it does not work when I apply the same to the Switcher
stateset, don't know why...
Cheers,
Ricky
Post by Cedric Pinson
I thouth the keywords OVERRIDE should be use when you want to
override
Post by Cedric Pinson
StateSet - tex0
- tex1
Geode
geom1
stateset - tex0 override
stateset - tex1 override
geom2
stateset - tex0 override
stateset - tex1 override
In this sceme geom 1 et 2 will use for tex0 and tex1 from the
switcher
Post by Cedric Pinson
you can read the code here in include/osg/State in the function
State::pushAttributeList
It does not anwser directly to you questions but i hope it will
help.
Post by Cedric Pinson
Cedric
Post by Riccardo Corsi
Hi all,
I'm after overriding some texture attributes in a hierarchy,
following
Post by Cedric Pinson
Post by Riccardo Corsi
the osgmultitexture example, from within a "MyTextureSwitcher"
node
Post by Cedric Pinson
Post by Riccardo Corsi
derived from osg::Group.
I basically want to load a new texture on layer 1 and try to
mix/blend
Post by Cedric Pinson
Post by Riccardo Corsi
it with the other existing texture on the underlying geometries.
MyTextureSwitcher
|
MatrixTransform
|
MatrixTransform
|
Geode
|-- geom1
|-- geom2
Now if I try to set the values on the MyTextureSwitcher StateSet,
nothing happen (the new texture file is not even loaded).
If I change the same attributes on the MatrixTrasform instead,
everything works nicely. The attributes I'm adding to override the
other are as well highlighted in the attached image (thanks
orhialcon).
Post by Cedric Pinson
Post by Riccardo Corsi
Of course, I'd like to do everything in the MyTextureSwitcher
stateset, as this is a node that I can add or remove to obtain
different effects.
MyTextureSwitcher::Setup()
{
[...]
osg::StateSet* pSS = getChild(0)->getOrCreateStateSet(); //
working case
//osg::StateSet* pSS = getOrCreateStateSet(); // NOT working
pSS->setTextureAttributeAndModes(1, mSwitchTex.get(),
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
osg::TexEnv* texenv = new osg::TexEnv;
texenv->setMode(osg::TexEnv::BLEND);
texenv->setColor(osg::Vec4( 0.3f,0.3f,0.3f,0.3f));
pSS->setTextureAttributeAndModes(1,texenv,
osg::StateAttribute::ON
Post by Cedric Pinson
Post by Riccardo Corsi
| osg::StateAttribute::OVERRIDE);
}
Any clue why the second case is not working?
Thank you,
Ricky
------------------------------------------------------------------------
------------------------------------------------------------------------
Post by Cedric Pinson
Post by Riccardo Corsi
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
<http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org>
------------------------------------------------------------------------
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Cedric Pinson
2007-10-03 08:24:23 UTC
Permalink
My bad you are right, sorry for the confusion...
Post by Riccardo Corsi
Hi Cedric,
I believe the override keyword works in the other way: when you use it,
you override the attributes of objects that are below in the graph
StateSet - tex0
- tex1 override
Geode
geom1
stateset - tex0
stateset - tex1
geom2
stateset - tex0
stateset - tex1
the tex1 from the Switcher StateSet will be used instead of the one
specified in the geoms.
That's exactly what happens in my application when I do the override in
the MatrixTransform.
Unfortunately, it does not work when I apply the same to the Switcher
stateset, don't know why...
Cheers,
Ricky
Post by Cedric Pinson
I thouth the keywords OVERRIDE should be use when you want to override
StateSet - tex0
- tex1
Geode
geom1
stateset - tex0 override
stateset - tex1 override
geom2
stateset - tex0 override
stateset - tex1 override
In this sceme geom 1 et 2 will use for tex0 and tex1 from the switcher
you can read the code here in include/osg/State in the function
State::pushAttributeList
It does not anwser directly to you questions but i hope it will help.
Cedric
Post by Riccardo Corsi
Hi all,
I'm after overriding some texture attributes in a hierarchy, following
the osgmultitexture example, from within a "MyTextureSwitcher" node
derived from osg::Group.
I basically want to load a new texture on layer 1 and try to mix/blend
it with the other existing texture on the underlying geometries.
MyTextureSwitcher
|
MatrixTransform
|
MatrixTransform
|
Geode
|-- geom1
|-- geom2
Now if I try to set the values on the MyTextureSwitcher StateSet,
nothing happen (the new texture file is not even loaded).
If I change the same attributes on the MatrixTrasform instead,
everything works nicely. The attributes I'm adding to override the
other are as well highlighted in the attached image (thanks orhialcon).
Of course, I'd like to do everything in the MyTextureSwitcher
stateset, as this is a node that I can add or remove to obtain
different effects.
MyTextureSwitcher::Setup()
{
[...]
osg::StateSet* pSS = getChild(0)->getOrCreateStateSet(); //
working case
//osg::StateSet* pSS = getOrCreateStateSet(); // NOT working
pSS->setTextureAttributeAndModes(1, mSwitchTex.get(),
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
osg::TexEnv* texenv = new osg::TexEnv;
texenv->setMode(osg::TexEnv::BLEND);
texenv->setColor(osg::Vec4(0.3f,0.3f,0.3f,0.3f));
pSS->setTextureAttributeAndModes(1,texenv, osg::StateAttribute::ON
| osg::StateAttribute::OVERRIDE);
}
Any clue why the second case is not working?
Thank you,
Ricky
------------------------------------------------------------------------
------------------------------------------------------------------------
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
--
+33 (0) 6 63 20 03 56 Cedric Pinson mailto:mornifle-***@public.gmane.org http://www.plopbyte.net
Loading...