So, I've looked at the tutorials for this, but it doesn't much in depth into
the texture coordinates and how they work. If someone could help me out, I'd
much appreciate it.
What I'm trying to do at the moment, is build a cube and apply a single texture
that will be mapped to each of the 6 faces. That's the starting point. Then I'd
like to try and build from that and apply 6 different textures to each face. I
haven't been able to do either =/
I've commented out lines that are intended for the latter goal of applying 6
different textures. Here is the code I've written so far:
**I've also attached the .cpp file since it's showing up weird on here**
Code:
#include osg/Node
#include osg/Group
#include osg/Geode
#include osg/Geometry
#include osg/Texture2D
#include osgDB/ReadFile
#include osgViewer/Viewer
#include osg/PositionAttitudeTransform
#include osgGA/TrackballManipulator
void setUpCube( osg::ref_ptr osg::Geometry );
int main()
{
osgViewer::Viewer viewer;
osg::ref_ptr osg::Group root = new osg::Group;
osg::ref_ptr osg::Geode square = new osg::Geode;
osg::ref_ptr osg::Geometry geom = new osg::Geometry;
osg::ref_ptr osg::StateSet state = root-getOrCreateStateSet();
setUpCube( geom );
root-addChild( square.get() );
square-addDrawable( geom.get() );
osg::ref_ptr osg::Vec2Array tc1 = new osg::Vec2Array;
tc1-push_back( osg::Vec2( 1.f, 1.f ) );
tc1-push_back( osg::Vec2( 0.f, 1.f ) );
tc1-push_back( osg::Vec2( 0.f, 0.f ) );
tc1-push_back( osg::Vec2( 1.f, 0.f ) );
tc1-push_back( osg::Vec2( 0.f, 0.f ) );
tc1-push_back( osg::Vec2( 1.f, 0.f ) );
tc1-push_back( osg::Vec2( 1.f, 1.f ) );
tc1-push_back( osg::Vec2( 0.f, 1.f ) );
geom-setTexCoordArray( 0, tc1.get() );/*
geom-setTexCoordArray( 1, tc1.get() );
geom-setTexCoordArray( 2, tc1.get() );
geom-setTexCoordArray( 3, tc1.get() );
geom-setTexCoordArray( 4, tc1.get() );
geom-setTexCoordArray( 5, tc1.get() );*/
osg::ref_ptr osg::Image image1 = osgDB::readImageFile(
C:\\Documents and Settings\\MTS\\My Documents\\Visual Studio
2008\\Projects\\OSG_test\\Debug\\smiley1.jpg );/*
osg::ref_ptr osg::Image image2 = osgDB::readImageFile(
C:\\Documents and Settings\\MTS\\My Documents\\Visual Studio
2008\\Projects\\OSG_test\\Debug\\smiley2.jpg );
osg::ref_ptr osg::Image image3 = osgDB::readImageFile(
C:\\Documents and Settings\\MTS\\My Documents\\Visual Studio
2008\\Projects\\OSG_test\\Debug\\smiley3.jpg );
osg::ref_ptr osg::Image image4 = osgDB::readImageFile(
C:\\Documents and Settings\\MTS\\My Documents\\Visual Studio
2008\\Projects\\OSG_test\\Debug\\smiley4.jpg );
osg::ref_ptr osg::Image image5 = osgDB::readImageFile(
C:\\Documents and Settings\\MTS\\My Documents\\Visual Studio
2008\\Projects\\OSG_test\\Debug\\smiley5.jpg );
osg::ref_ptr osg::Image image6 = osgDB::readImageFile(
C:\\Documents and Settings\\MTS\\My Documents\\Visual Studio
2008\\Projects\\OSG_test\\Debug\\smiley6.jpg );*/
osg::ref_ptr osg::Texture2D tex1 = new osg::Texture2D;/*
osg::ref_ptr osg::Texture2D tex2 = new osg::Texture2D;
osg::ref_ptr osg::Texture2D tex3 = new osg::Texture2D;
osg::ref_ptr osg::Texture2D tex4 = new osg::Texture2D;
osg::ref_ptr osg::Texture2D tex5 = new osg::Texture2D;
osg::ref_ptr osg::Texture2D tex6 = new osg::Texture2D;*/
tex1-setDataVariance( osg::Object::DYNAMIC );/*
tex2-setDataVariance( osg::Object::DYNAMIC );
tex3-setDataVariance( osg::Object::DYNAMIC );
tex4-setDataVariance( osg::Object::DYNAMIC );
tex5-setDataVariance( osg::Object::DYNAMIC );
tex6-setDataVariance( osg::Object::DYNAMIC );*/
tex1-setImage( image1.get() );/*
tex2-setImage( image2.get() );
tex3-setImage( image3.get() );
tex4-setImage( image4.get() );
tex5-setImage( image5.get() );
tex6-setImage( image6.get() );*/
state-setTextureAttributeAndModes( 0, tex1.get() );/*
state-setTextureAttributeAndModes( 1, tex2.get() );
state-setTextureAttributeAndModes( 2, tex3.get() );
state-setTextureAttributeAndModes( 3, tex4.get() );
state-setTextureAttributeAndModes( 4, tex5.get() );
state-setTextureAttributeAndModes( 5, tex6.get() );*/
state-setMode( GL_LIGHTING, osg::StateAttribute::OFF |
osg::StateAttribute::PROTECTED );
square-setStateSet( state.get() );
viewer.setSceneData( root.get() );
viewer.setCameraManipulator( new osgGA::TrackballManipulator() );
viewer.realize();
while( !viewer.done() )
viewer.frame();
return 0;
}
void setUpCube( osg::ref_ptr osg::Geometry geom )
{
osg::ref_ptr osg::Vec3Array sqVert = new osg::Vec3Array;
sqVert-push_back( osg::Vec3( 0,