Hi Ulrich
because the osg website is not reachable (again), can you show me how to
implement a texture matrix - I didn't find any other sites showing some
examples.
Here is my code:
// defines the file path
QString fileGroundTexture = "res/osg/grass.png";
// creates a new OSG height field
osg::HeightField* gridGround = new osg::HeightField;
gridGround->allocate(widthX, widthZ);
gridGround->setXInterval(1.0);
gridGround->setYInterval(1.0);
// iterates through the rows of the OSG height field
for(int z=0; z<widthZ; z++)
{
...
// iterates through the columns of the OSG height field
for(int x=0; x<widthX; x++)
{
...
// defines a terrain for the ground in z-direction
gridGround->setHeight(x, z, (heightX+heightZ) / 2.0);
}
}
// loads the texture image
ref_ptr<Image> imgGroundTexture =
osgDB::readImageFile(Utilities::filePath(fileGroundTexture).toStdString());
// checks if loading of PNG file was not successful, if so, exit the
application
if (!imgGroundTexture)
Application::alert(Application::ALERT_WARNING,
QString(QObject::tr("Error openening texture file
%1.")).arg(Utilities::filePath(fileGroundTexture)));
// 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(imgGroundTexture.get());
texGround->setUnRefImageDataAfterApply(true);
// creates a new OSG geode
ref_ptr<Geode> geoGround = new Geode;
geoGround->addDrawable(new ShapeDrawable(gridGround));
// enables all the necessary states
geoGround->getOrCreateStateSet()->setTextureAttributeAndModes(0,
texGround.get(), StateAttribute::ON);
Thanks a lot!
Dominic
Ulrich Hertlein schrieb:
On 6/12/09 7:27 PM, Dominic Stalder wrote:
is it possible to set the textue coordinates (for repeating a texture)
of a HeightField node? If yes, how?
If you're using HeightField/ShapeDrawable then no, you cannot specify the
texture
coordinates manually. But you can achieve the same by using a TextureMatrix to
scale the
assigned texcoords to your requirements.
/ulrich
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org