Re: [osg-users] Texture and unsigned char* buffer

2010-04-21 Thread Anthony Face
Thanks for your answer, but that doesn't work. 
I found the error on my own.
It was this part of code i forgot:

Code:
osg::Vec2Array* texcoords = new osg::Vec2Array(4);
(*texcoords)[0].set(0.0f, 0.0f);
(*texcoords)[1].set(1.0f, 0.0f);
(*texcoords)[2].set(1.0f, 1.0f);
(*texcoords)[3].set(0.0f, 1.0f);
g-setTexCoordArray(0,texcoords);



Tanks who read me and try to help !

have fun !:D

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





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


[osg-users] Texture and unsigned char* buffer

2010-04-20 Thread Anthony Face
Hi.
I need to use an buffer to update a texture. I can do it but the bad point is 
that my item is a full collored Quad and not an image. The color is the first 
color of my buffer.

i can change every things but not the buffer, i receive it as a unsigned 
char* and i know the width and the height. Is it RGB mode, no alpha.

Could you help me? thanks you a lot !

This is my code to create items:

Code:

//objets from my class
osg::Texture2D* texture_;

//Constructor
osg::Image* im = new osg::Image;
im-allocateImage(1024 , 1024, 1 , GL_RGB, GL_UNSIGNED_BYTE);

texture_  = new osg::Texture2D;
texture_-setDataVariance(osg::Object::DYNAMIC);
texture_-setImage(im);

osg::ref_ptrosg::Vec3Array vertex_ = new osg::Vec3Array;
osg::Geometry * g = new osg::Geometry;
g-setVertexArray( vertex_.get() );
float x = 512;
static float zFar = -1;
vertex_-push_back( osg::Vec3( -x , -x , zFar ) );
vertex_-push_back( osg::Vec3(  x , -x , zFar ) );
vertex_-push_back( osg::Vec3(  x ,  x , zFar ) );
vertex_-push_back( osg::Vec3( -x ,  x , zFar ) );
g-addPrimitiveSet(new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0, 4 ) );

stateset_ = g-getOrCreateStateSet();
stateset_-setTextureAttributeAndModes(0, texture_, osg::StateAttribute::ON);
stateset_-setMode(GL_BLEND,osg::StateAttribute::ON);
stateset_-setRenderingHint(osg::StateSet::OPAQUE_BIN);

osg::Geode* geode = new osg::Geode;
geode-addDrawable(g);

texture_-setImage(im);



This is my code to update texture: (simplified)

Code:

void Background::majTexture(unsigned char* newValue) 
{
memcpy(texture_-getImage()-data(), newValue, 1024 * 1024 * 3);
//1024 * 1024 * 3 = height * weight * number of composant for one pixel
}



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





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


Re: [osg-users] Texture and unsigned char* buffer

2010-04-20 Thread J.P. Delport

Hi,

where are you calling the update code from?

Try adding texture_-getImage()-dirty(); after the update

jp

On 20/04/10 15:29, Anthony Face wrote:

Hi.
I need to use an buffer to update a texture. I can do it but the bad point is 
that my item is a full collored Quad and not an image. The color is the first 
color of my buffer.

i can change every things but not the buffer, i receive it as aunsigned char* 
 and i know the width and the height. Is it RGB mode, no alpha.

Could you help me? thanks you a lot !

This is my code to create items:

Code:

//objets from my class
osg::Texture2D* texture_;

//Constructor
osg::Image* im = new osg::Image;
im-allocateImage(1024 , 1024, 1 , GL_RGB, GL_UNSIGNED_BYTE);

texture_  = new osg::Texture2D;
texture_-setDataVariance(osg::Object::DYNAMIC);
texture_-setImage(im);

osg::ref_ptrosg::Vec3Array  vertex_ = new osg::Vec3Array;
osg::Geometry * g = new osg::Geometry;
g-setVertexArray( vertex_.get() );
float x = 512;
static float zFar = -1;
vertex_-push_back( osg::Vec3( -x , -x , zFar ) );
vertex_-push_back( osg::Vec3(  x , -x , zFar ) );
vertex_-push_back( osg::Vec3(  x ,  x , zFar ) );
vertex_-push_back( osg::Vec3( -x ,  x , zFar ) );
g-addPrimitiveSet(new osg::DrawArrays( osg::PrimitiveSet::QUADS, 0, 4 ) );

stateset_ = g-getOrCreateStateSet();
stateset_-setTextureAttributeAndModes(0, texture_, osg::StateAttribute::ON);
stateset_-setMode(GL_BLEND,osg::StateAttribute::ON);
stateset_-setRenderingHint(osg::StateSet::OPAQUE_BIN);

osg::Geode* geode = new osg::Geode;
geode-addDrawable(g);

texture_-setImage(im);



This is my code to update texture: (simplified)

Code:

void Background::majTexture(unsigned char* newValue)
{
memcpy(texture_-getImage()-data(), newValue, 1024 * 1024 * 3);
//1024 * 1024 * 3 = height * weight * number of composant for one pixel
}



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





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


--
This message is subject to the CSIR's copyright terms and conditions, e-mail legal notice, and implemented Open Document Format (ODF) standard. 
The full disclaimer details can be found at http://www.csir.co.za/disclaimer.html.


This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.  MailScanner thanks Transtec Computers for their support.


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