[osg-users] problem with cessna texturing
Vadim Balashoff
vvb.backup at rambler.ru
Tue Oct 27 20:35:38 PDT 2015
here is my code:
http://vvb.nailedgames.com/osg/main.htm
Code:
#include <stdio.h>
#include <osg/Geometry>
#include <osg/Geode>
#include <osg/Material>
#include <osg/ShapeDrawable>
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osgUtil/SmoothingVisitor>
#include <osgViewer/Viewer>
int main ()
{
osg::Material *material = new osg::Material();
material->setEmission(osg::Material::FRONT, osg::Vec4(0.8, 0.8, 0.8, 1.0));
osg::Image* image = osgDB::readImageFile("FD_image.jpg");
if (!image) {
std::cout << "Couldn't load texture." << std::endl;
return -1;
}
osg::Texture2D *texture = new osg::Texture2D;
texture->setDataVariance(osg::Object::DYNAMIC);
texture->setFilter(osg::Texture2D::MIN_FILTER, osg::Texture2D::LINEAR);
texture->setFilter(osg::Texture2D::MAG_FILTER, osg::Texture2D::LINEAR);
texture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::MIRROR);
texture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::MIRROR);
texture->setWrap(osg::Texture2D::WRAP_R, osg::Texture2D::MIRROR);
texture->setImage(image);
osg::ref_ptr<osg::Node> plane = osgDB::readNodeFile( "cessna.osg" );
osg::StateSet *planeStateSet = plane->getOrCreateStateSet();
planeStateSet->ref();
planeStateSet->setAttribute(material);
planeStateSet->setTextureAttributeAndModes(0, texture, osg::StateAttribute::OVERRIDE);
planeStateSet->setTextureMode(0, GL_TEXTURE_2D,osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
planeStateSet->setTextureMode(0, GL_TEXTURE_GEN_S,osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
planeStateSet->setTextureMode(0, GL_TEXTURE_GEN_R,osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
planeStateSet->setTextureMode(0, GL_TEXTURE_GEN_T,osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
planeStateSet->setAttribute(material, osg::StateAttribute::OVERRIDE);
planeStateSet->setMode( GL_RESCALE_NORMAL, osg::StateAttribute::ON );
planeStateSet->setMode( GL_NORMALIZE, osg::StateAttribute::ON );
osgViewer::Viewer viewer;
viewer.setSceneData( plane );
return viewer.run();
};
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=65467#65467
More information about the osg-users
mailing list