I need help with calculating texture coordinates for the set of triangles. Is there a function that calculates them according to the vertex coordinates without shaders? Or how one can calculate them manually using vertex normals? I have a big amount of small triangles, calculated from a point cloud and have no possibility to influence them. My simplified test program looks like this:
//read texture
text = new_message->text;
osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
texture->setDataVariance(osg::Object::DYNAMIC);
osg::ref_ptr<osg::Image> image = osgDB::readImageFile( "Images/" +text );
if (!image)
{
std::cout << "Couldn't load texture." << std::endl;
}
texture->setImage( image.get() );
...
//create and fill an array of vertices
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
vertices->push_back( osg::Vec3(...) );
...
osg::ref_ptr<osg::Geometry> quad = new osg::Geometry;
quad->setVertexArray( vertices.get() );
quad->addPrimitiveSet( new osg::DrawArrays(GL_TRIANGLES, 0, 12) );
//calculate normals
osgUtil::SmoothingVisitor::smooth( *quad );
geode = new osg::Geode;
geode->addDrawable( quad.get() );
//calculate texture coordinates
osg::StateSet *state = geode->getOrCreateStateSet();
state->setTextureAttributeAndModes(1, texture.get(), osg::StateAttribute::ON);
state->setTextureMode(1, GL_TEXTURE_GEN_S, osg::StateAttribute::ON);
state->setTextureMode(1, GL_TEXTURE_GEN_T, osg::StateAttribute::ON);
state->setTextureMode(1, GL_TEXTURE_GEN_R, osg::StateAttribute::ON);
state->setTextureMode(1, GL_TEXTURE_GEN_Q, osg::StateAttribute::ON);
geode->setStateSet(state);
The calculated normals work perfectly, texture coordinates are not working at all - I get black triangles. There is not much information on how to use GL_TEXTURE_GEN_S, so any help would be really appreciated. UPD: I calculated texture coordinates manually using following formulas http://paulyg.f2s.com/uv.htm