Thanks Rubén,
I'm trying to use VBO, but I think something is missing... I added this to the
creation of my geometry:
myGeom->setSupportsDisplayList(false);
myGeom->setUseDisplayList(false);
myVertexBuffer = myGeom->getOrCreateVertexBufferObject();
myVertexBuffer->setArray(0,&v);
myVertexBuffer->setUsage(GL_STREAM_DRAW_ARB);
myGeom->setUseVertexBufferObjects(true);
and then inside the callback I'm try to modify the vertex data:
osg::Vec3Array *test = dynamic_cast<osg::Vec3Array
*>(testNx->myVertexBuffer->getArray(0));
for(int i = 0; i < numVertex; i++)
{
NxMat34 pose = listShapes.at(i)->shape->getGlobalPose();
osg::Vec3f trans = osg::Vec3(pose.t.x,pose.t.y,pose.t.z);
test->at(i) = trans;
}
but nothing changes in the render.... the object does not move. Does anybody
know what is missing??
thanks in advance
Crisalix.
> From: [EMAIL PROTECTED]
> To: osg-users@lists.openscenegraph.org
> Date: Wed, 6 Feb 2008 21:33:51 +0100
> Subject: Re: [osg-users] How to modify the array of vertex from a
> Geometry object
>
> Hi,
>
> Some hints:
>
> 1. Be sure that test->size() is equal to numVertex
>
> 2. I don't know what the "at" method is, I couldn't find it either on
> the TemplateArray class or the std::vector class. Try with the vector []
> operator, ie: (*test)[i] = trans
>
> 3. If you are updating the vertex data once per frame, don't use display
> lists, it is the worst thing that you can ever do! It is cheaper even to
> use direct mode. Use vertex buffer objects and configure the VBO
> (getOrCreateVertexBufferObject) in streaming mode (GL_STREAM_DRAW).
>
> Hope this helps.
>
> Regards.
>
> Rubén
>
> El mié, 06-02-2008 a las 14:08 +0100, lucas Grijander escribió:
> > Dear all,
> >
> > I have to create a 3D surface, and then such surface will be modified
> > during the application with several deformations. I've tried to create a
> > Geometry object, then I set the VertexArray, and finally inside the render
> > callback I update such vertex with the new ones. I got some errors during
> > the rendering:
> >
> > Warning: detected OpenGL error "value not valid" after RenderBin::draw(,)
> >
> > Does anyone has an idea of such error? In addition, I'm sure the way I am
> > accessing the vertex is not the right one, anybody knows the best way?
> >
> > here is the code:
> >
> >
> > //Create the 3D geometry
> > -------------------------------------------------------------------------
> > osg::Vec3Array(m*n));
> > osg::Vec2Array& t = *(new osg::Vec2Array(m*n));
> > osg::Vec4Array& col = *(new osg::Vec4Array(1));
> >
> > col[0][0] = col[0][1] = col[0][2] = col[0][3] = 1.0f;
> >
> > int index = 0;
> > for( i = 0; i < m; i++ )
> > {
> > for(j = 0; j < n; j++)
> > {
> > v[index][0] = i;
> > v[index][1] = 0;
> > v[index][2] = j;
> >
> > t[index][0] = (float)i/(m-1);
> > t[index][1] = (float)j/(n-1);
> >
> > index++;
> > }
> > }
> >
> > myGeom = new osg::Geometry;
> >
> > myGeom->setVertexArray( &v );
> > myGeom->setTexCoordArray( 0, &t );
> >
> > myGeom->setColorArray( &col );
> > myGeom->setColorBinding( osg::Geometry::BIND_OVERALL );
> >
> > for( i = 0; i < m-1; i++ )
> > {
> > osg::DrawElementsUShort* elements = new
> > osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLE_STRIP);
> > elements->reserve(m*2);
> > for( j = 0; j < n; j++ )
> > {
> > elements->push_back((i+0)*n+j);
> > elements->push_back((i+1)*n+j);
> > }
> > myGeom->addPrimitiveSet(elements);
> > }
> >
> >
> > osg::Texture2D *tex = new osg::Texture2D;
> >
> > tex->setImage(osgDB::readImageFile("Images/breast.png"));
> >
> > osg::StateSet *dstate = new osg::StateSet;
> > dstate->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
> > dstate->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON );
> > dstate->setTextureAttribute(0, new osg::TexEnv );
> >
> > myGeom->setStateSet( dstate );
> >
> > osg::Geode *geode = new osg::Geode;
> > geode->addDrawable( myGeom );
> >
> > -------------------------------------------------------
> >
> > //Accessing the elements
> > -------------------------------------------
> >
> > osg::Vec3Array *test = dynamic_cast(myGeom->getVertexArray());
> >
> > for(int i = 0; i < numVertex; i++)
> > {
> > NxMat34 pose = listShapes.at(i)->shape->getGlobalPose();
> > osg::Vec3f trans = osg::Vec3(pose.t.x,pose.t.y,pose.t.z);
> >
> > test->at(i) = trans;
> >
> >
> >
> > }
> > myGeom->dirtyDisplayList();
> > myGeom->dirtyBound();
> > --------------------------------------------
> >
> > thank you very much for your help!!!
> >
> > Crisalix.
> >
> >
> > _________________________________________________________________
> > Express yourself instantly with MSN Messenger! Download today it's FREE!
> > http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
> > _______________________________________________
> > 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
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org