[osg-users] Texture wrapping for a geometry object

Robert Osfield robert.osfield at gmail.com
Sun Nov 22 09:31:19 PST 2009


Hi Dominc,

I don't know where you might have got the impression that you can't
set up texture repeats with geometry - you just using texture
coordinates beyond the 0.0 to 1.0 range and you'll get repeats.
Another way is to use a texture matrix to up the tex coords from 0.0
to 1.0 range to what you want.

Robert.

On Sun, Nov 22, 2009 at 3:28 PM, Dominic Stalder
<dominic.stalder at bluewin.ch> wrote:
> Hi there
>
> I would like to wrap (repeated) my texture image on a geometry object. I
> read somewhere, that this is not possible directly on the geometry, but how
> can I do it otherwise? Here is my code:
>
>   /*
>    * creates the ground geometry
>    */
>   // creates the vertices array
>   ref_ptr<Vec3Array> verticesGround = new Vec3Array;
>   verticesGround->push_back(Vec3(-WORLD_INFINITY, 0.0, -WORLD_INFINITY)); //
> back left
>   verticesGround->push_back(Vec3(WORLD_INFINITY, 0.0, -WORLD_INFINITY));  //
> back right
>   verticesGround->push_back(Vec3(WORLD_INFINITY, 0.0, WORLD_INFINITY));   //
> front right
>   verticesGround->push_back(Vec3(-WORLD_INFINITY, 0.0, WORLD_INFINITY));  //
> front left
>     // creates the normal array
>   ref_ptr<Vec3Array> normalsGround = new Vec3Array;
>   normalsGround->push_back(Vec3(0.0, 1.0, 0.0));
>     // creates the texture coordinates array
>   ref_ptr<Vec2Array> texCoordGround = new Vec2Array;
>   texCoordGround->push_back(Vec2(0.0, 0.0));
>   texCoordGround->push_back(Vec2(1.0, 0.0));
>   texCoordGround->push_back(Vec2(1.0, 1.0));
>   texCoordGround->push_back(Vec2(0.0, 1.0));
>     // loads the texture image
>   ref_ptr<Image> imgGrass =
> osgDB::readImageFile(Utilities::filePath("res/osg/grass.png").toStdString());
>     // attaches the image to the texture
>   ref_ptr<Texture2D> texGround = new Texture2D;
>   texGround->setDataVariance(Object::DYNAMIC);
>   texGround->setWrap(Texture::WRAP_S, Texture::REPEAT);
>   texGround->setWrap(Texture::WRAP_T, Texture::REPEAT);
>   texGround->setImage(imgGrass.get());
>     // releases the image after applying
>   texGround->setUnRefImageDataAfterApply(true);
>     // creates the geometry
>   ref_ptr<Geometry> geomGround = new Geometry;
>   geomGround->setVertexArray(verticesGround.get());
>   geomGround->setNormalArray(normalsGround.get());
>   geomGround->setTexCoordArray(0, texCoordGround.get());
>
>   // adds the primitive set to the geometry
>   geomGround->addPrimitiveSet(new DrawArrays(PrimitiveSet::QUADS, 0, 4));
>     // enables all the necessary states for the ground geometry node
>   ref_ptr<StateSet> stateGroundGeometry = geomGround->getOrCreateStateSet();
>   stateGroundGeometry->setTextureAttributeAndModes(0, texGround.get(),
> StateAttribute::ON);
>
>   // creates the geode
>   ref_ptr<Geode> geoGround = new Geode;
>   geoGround->addDrawable(geomGround.get());
>
> Thanks a lot in advance!
>
> Best regards
> Dominic
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>


More information about the osg-users mailing list