Re: [osg-users] Texture wrapping for a geometry object

2009-11-23 Thread Dominic Stalder

Hi Robert

thanks a lot, I got it from this mailing list message:

http://www.mail-archive.com/osg-us...@openscenegraph.net/msg11209.html

I will try the texture coordinates scaling. But just for interesting, 
how would the texture matrix work, do you have some basic code snippet?


Regards
Dominic

Robert Osfield schrieb:

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.stal...@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_ptrVec3Array 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_ptrVec3Array normalsGround = new Vec3Array;
  normalsGround-push_back(Vec3(0.0, 1.0, 0.0));
// creates the texture coordinates array
  ref_ptrVec2Array 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_ptrImage imgGrass =
osgDB::readImageFile(Utilities::filePath(res/osg/grass.png).toStdString());
// attaches the image to the texture
  ref_ptrTexture2D 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_ptrGeometry 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_ptrStateSet stateGroundGeometry = geomGround-getOrCreateStateSet();
  stateGroundGeometry-setTextureAttributeAndModes(0, texGround.get(),
StateAttribute::ON);

  // creates the geode
  ref_ptrGeode geoGround = new Geode;
  geoGround-addDrawable(geomGround.get());

Thanks a lot in advance!

Best regards
Dominic
___
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

  


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


Re: [osg-users] Texture wrapping for a geometry object

2009-11-23 Thread Ulrich Hertlein

On 23/11/09 10:09 AM, Dominic Stalder wrote:

I will try the texture coordinates scaling. But just for interesting,
how would the texture matrix work, do you have some basic code snippet?


osg::TexMat provides a matrix and any texture coordinates you specify will be multiplied 
by that.


The matrix can translate, scale, and rotate the texture coordinates.  For example if you 
specify a x2 scaling matrix and the texture coordinates are 0..1 then that has the same 
effect as if you specified texture coordinates 0..2.


Hope this helps,
/ulrich
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Texture wrapping for a geometry object

2009-11-23 Thread Dominic Stalder
Hi everybody

thanks for the help. It's really that easy, but I didn't see the hint ;-)

Sorry for that. Now I just set the value of the geometry width instead just 1.0.

Cheers,
Dominic

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





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


Re: [osg-users] Texture wrapping for a geometry object

2009-11-22 Thread Robert Osfield
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.stal...@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_ptrVec3Array 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_ptrVec3Array normalsGround = new Vec3Array;
   normalsGround-push_back(Vec3(0.0, 1.0, 0.0));
     // creates the texture coordinates array
   ref_ptrVec2Array 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_ptrImage imgGrass =
 osgDB::readImageFile(Utilities::filePath(res/osg/grass.png).toStdString());
     // attaches the image to the texture
   ref_ptrTexture2D 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_ptrGeometry 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_ptrStateSet stateGroundGeometry = geomGround-getOrCreateStateSet();
   stateGroundGeometry-setTextureAttributeAndModes(0, texGround.get(),
 StateAttribute::ON);

   // creates the geode
   ref_ptrGeode geoGround = new Geode;
   geoGround-addDrawable(geomGround.get());

 Thanks a lot in advance!

 Best regards
 Dominic
 ___
 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