Re: [osg-users] Experiments on Textures and Images, strange behavior.

2013-06-10 Thread Sebastian Messerschmidt

Hi Gaëtan,

If you are assigning a new Image to an already existing and possibly 
bound texture, try to set the image dirty.

Secondly, you might want to try to set the texture explicitly  to:

stateset-setTextureAttributeAndModes( 0,map, osg::StateAttribute::ON | 
osg::StateAttribute::OVERRIDE);


Cheers
Sebastian


Hi,

I am trying to understand how texture ande Image are working

//some initialized texture with contents
osg::ref_ptrosg::Texture2D map

//displays correctly the texture
osg::StateSet* stateset = HUD_camera-getOrCreateStateSet();
stateset-setTextureAttributeAndModes( 0,map);

//does not display the texture
osg::ref_ptrosg::Texture2D lm = new osg::Texture2D;
lm-setImage(map-getImage());
stateset-setTextureAttributeAndModes( 0,lm);

Why ?

Thank you!

Cheers,
Gaëtan

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=54501#54501





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Experiments on Textures and Images, strange behavior.

2013-06-10 Thread Gaëtan André
Hi,

Ok I will try to make it clearer.

I have a generated CubeMap, and I want to display each face on a quad with a 
HUD Camera. I first tried to generate on face in a Texture2D and it worked 
welll since I don't have to copy the image in the original texture in a new 
texture (on the opposite if I try to use getIMage(), setImage(), this does not 
work anymore) to display it on a quad.

For the CubeMap,Ii want its images (6) to be embedded in Texture2D to simply be 
displayed on a quad.

Here is the piece of code :

//map contains the generated Cube map when the function is called
void SDDebugHUD::setTexture(osg::ref_ptrosg::TextureCubeMap map){
osg::StateSet* stateset = HUD_camera-getOrCreateStateSet();
osg::ref_ptrosg::Texture2D lm = new osg::Texture2D;
lm-setDataVariance(osg::Object::DYNAMIC);
lm-setImage(map-getImage(3));
stateset-setTextureAttributeAndModes( 0,lm);
}


Thank you!

Cheers,
Gaëtan

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=54506#54506





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Experiments on Textures and Images, strange behavior.

2013-06-10 Thread Robert Osfield
Hi Gaëtan,

There is too much information about the usage of the textures and
associated images to know what is going on, but my best guess is that
your first texture is being used and has the UnRefImageDataAfterApply
set to true (this is the default) so once it's used the image will be
discarded, so your second texture-setImage() will be simply setting 0
which of course will not work.

Personally I'd suggest not messing around with a second texture, just
reuse the first one.  If you for some reason really really need to
reuse the same image then keep a ref_ptr to it so that you can
guarantee it's lifetime.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Experiments on Textures and Images, strange behavior.

2013-06-10 Thread Gaëtan André
Hi,

I followed your advice and applied directly the cubemap on the quad using 3D 
texture coordinates.

Allow me to ask another question are things are very weird !

I render the scene in the CubeMap

Code:

 reflectionMap = new osg::TextureCubeMap;
reflectionMap-setTextureSize( 256, 256 );
reflectionMap-setInternalFormat( GL_RGBA);

camerasRoot = new osg::Group;

for(int i=0;i6;i++){


osg::ref_ptrosg::Camera camera = new osg::Camera;
camera-setViewport( 0, 0, 256, 256 );
camera-setClearMask( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );

camera-setRenderOrder( osg::Camera::PRE_RENDER );
camera-setRenderTargetImplementation(
osg::Camera::FRAME_BUFFER_OBJECT );
camera-attach( osg::Camera::COLOR_BUFFER, reflectionMap,0,i );

camera-setReferenceFrame( osg::Camera::ABSOLUTE_RF );
camera-addChild( m_sceneroot );

camera-setPreDrawCallback(pre_cam);
 camera-setPostDrawCallback(post_cam);

camera-setProjectionMatrixAsPerspective(90.0,1.0,1.0,100.0);

camerasRoot-addChild(camera);
cameras.push_back(camera);

  }




Then this CubeMap is used twice per cycle.

First on a object, via shaders.
Second on two quads,displayed by a HUD camera (in order to see what is in the 
map).

On the object, a still image is displayed corresponding to a render from a 
previous execution of the application !

On the quads, this image is blended with the correct texture being rendered.

Each time I restart the application, a image of the previous execution is used.

It is sort of confusing.

Thank you!

Cheers,
Gaëtan[/code]

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=54516#54516





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Experiments on Textures and Images, strange behavior.

2013-06-10 Thread Robert Osfield
Hi Gaëtan,


On 10 June 2013 15:26, Gaëtan André gaetan.an...@gmail.com wrote:
 Then this CubeMap is used twice per cycle.

 First on a object, via shaders.
 Second on two quads,displayed by a HUD camera (in order to see what is in the 
 map).

 On the object, a still image is displayed corresponding to a render from a 
 previous execution of the application !

 On the quads, this image is blended with the correct texture being rendered.

 Each time I restart the application, a image of the previous execution is 
 used.

 It is sort of confusing.

This is almost certainly down to an issue of order of setting the
texture contents and using them.  The OSG has a scheme for controlling
the rendering order Camera's, and for render to texture Camera's you
use camera-setRenderOrder(osg::Camera::PRE_RENDER);  Please have a
look at the osgprerender and osgprerendercubemap examples.

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Experiments on Textures and Images, strange behavior.

2013-06-10 Thread Gaëtan André
Hi,

Thanks again for replying.

In my code 
camera-setRenderOrder(osg::Camera::PRE_RENDER);
is present.

I looked at the examples, there does not seem to have much difference.

Cheers,
Gaëtan

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=54521#54521





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Experiments on Textures and Images, strange behavior.

2013-06-10 Thread Gaëtan André
Hi,


reflectionMap-setFilter(osg::TextureCubeMap::MIN_FILTER,osg::TextureCubeMap::LINEAR);

reflectionMap-setFilter(osg::TextureCubeMap::MAG_FILTER,osg::TextureCubeMap::LINEAR);

These two line solved my problem.

What is the default filter and why does not it work with it ?

Thank you!

Cheers,
Gaëtan

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=54526#54526





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Experiments on Textures and Images, strange behavior.

2013-06-10 Thread Robert Osfield
On 10 June 2013 18:10, Gaëtan André gaetan.an...@gmail.com wrote:
 
 reflectionMap-setFilter(osg::TextureCubeMap::MIN_FILTER,osg::TextureCubeMap::LINEAR);
 
 reflectionMap-setFilter(osg::TextureCubeMap::MAG_FILTER,osg::TextureCubeMap::LINEAR);

 These two line solved my problem.

 What is the default filter and why does not it work with it ?

The defaults are for a mipmapped texture, if you were just rendering
to the topmost level then unless you enabled the mipmap generation
then these levels will be undefined.  Note the mipMapGeneration line
from the Camera::attach() inline docs:

/** Attach a Texture to specified buffer component.
  * The level parameter controls the mip map level of the
texture that is attached.
  * The face parameter controls the face of texture cube map
or z level of 3d texture.
  * The mipMapGeneration flag controls whether mipmap
generation should be done for texture.*/
void attach(BufferComponent buffer, osg::Texture* texture,
unsigned int level = 0, unsigned int face=0, bool
mipMapGeneration=false,
unsigned int multisampleSamples = 0,
unsigned int multisampleColorSamples = 0);

Robert.
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Experiments on Textures and Images, strange behavior.

2013-06-10 Thread Gaëtan André
Hi,

Thanks fo the details.

Thank you!

Cheers,
Gaëtan

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=54530#54530





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Experiments on Textures and Images, strange behavior.

2013-06-09 Thread Gaëtan André
Hi,

I am trying to understand how texture ande Image are working

//some initialized texture with contents
osg::ref_ptrosg::Texture2D map

//displays correctly the texture
osg::StateSet* stateset = HUD_camera-getOrCreateStateSet();
stateset-setTextureAttributeAndModes( 0,map);

//does not display the texture
osg::ref_ptrosg::Texture2D lm = new osg::Texture2D;
lm-setImage(map-getImage());
stateset-setTextureAttributeAndModes( 0,lm);

Why ?

Thank you!

Cheers,
Gaëtan

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=54501#54501





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Experiments on Textures and Images, strange behavior.

2013-06-09 Thread Trajce Nikolov NICK
Hi,

initialize the texture and then reference it, in that order
osg::ref_ptrosg::Texture2D lm = new osg::Texture2D;
stateset-setTextureAttributeAndModes( 0,map);

Nick


On Sun, Jun 9, 2013 at 3:02 PM, Gaëtan André gaetan.an...@gmail.com wrote:

 Hi,

 I am trying to understand how texture ande Image are working

 //some initialized texture with contents
 osg::ref_ptrosg::Texture2D map

 //displays correctly the texture
 osg::StateSet* stateset = HUD_camera-getOrCreateStateSet();
 stateset-setTextureAttributeAndModes( 0,map);

 //does not display the texture
 osg::ref_ptrosg::Texture2D lm = new osg::Texture2D;
 lm-setImage(map-getImage());
 stateset-setTextureAttributeAndModes( 0,lm);

 Why ?

 Thank you!

 Cheers,
 Gaëtan

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=54501#54501





 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




-- 
trajce nikolov nick
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Experiments on Textures and Images, strange behavior.

2013-06-09 Thread Gaëtan André
Hi,
Thank you for the reply.

I am not quite sure to understand your answer.

Do you mean I should do this :

//does not display the texture
osg::StateSet* stateset = HUD_camera-getOrCreateStateSet();
osg::ref_ptrosg::Texture2D lm = new osg::Texture2D;
stateset-setTextureAttributeAndModes( 0,map); 
lm-setImage(map-getImage());
stateset-setTextureAttributeAndModes( 0,lm); 


Seems quite odd to me.

Cheers, 

Gaëtan[/quote]

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=54503#54503





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Experiments on Textures and Images, strange behavior.

2013-06-09 Thread Trajce Nikolov NICK
ah, I missread it. from your original post the map texture was not
initialized and was used later in the statest. I had to write something
like:

osg::ref_ptrosg::Texture2D map = new osg::Texture2D;
stateset-setTextureAttributeAndModes( 0,map);

if you post your code in whole then the chance to get help if higher

Nick




On Sun, Jun 9, 2013 at 10:29 PM, Gaëtan André gaetan.an...@gmail.comwrote:

 Hi,
 Thank you for the reply.

 I am not quite sure to understand your answer.

 Do you mean I should do this :

 //does not display the texture
 osg::StateSet* stateset = HUD_camera-getOrCreateStateSet();
 osg::ref_ptrosg::Texture2D lm = new osg::Texture2D;
 stateset-setTextureAttributeAndModes( 0,map);
 lm-setImage(map-getImage());
 stateset-setTextureAttributeAndModes( 0,lm);


 Seems quite odd to me.

 Cheers,

 Gaëtan[/quote]

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=54503#54503





 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




-- 
trajce nikolov nick
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org