Re: [osg-users] Having trouble with basic texture mapping on a 3d object

2010-05-28 Thread Michael Platings
 or have different textures in each texture unit as you were going to do.


N don't put a texture in each texture unit. You should only be using
multiple texture units if you need to combine the textures somehow e.g. in a
shader that requires a diffuse texture with a bump map and normal map and
specular map etc...
What you should do is separate your geometry into a different square for
each face of the cube, and for each geometry add a stateset with a texture
assigned to unit 0.

e.g.

for (int i = 0; i  6; ++i)
{
std::stringstream ss;
ss  C:\\Documents and Settings\\MTS\\My Documents\\Visual Studio
2008\\Projects\\OSG_test\\Debug\\smiley  i+1 .jpg;
Texture2D* tex = new Texture2D(osgDB::readImage(ss.str()));
Geometry* geom = createGeometryForFace(i);//set up vertices and texture
coordinates for a square at the appropriate position
geom-getOrCreateStateSet()-setTextureAttributeAndModes( 0, tex.get() );
geode-addDrawable(geom);
}
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Having trouble with basic texture mapping on a 3d object

2010-05-27 Thread Justen Falk
bump?

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





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


Re: [osg-users] Having trouble with basic texture mapping on a 3d object

2010-05-27 Thread Jean-Sébastien Guay

Hi Justen,


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.


You seem to have the right idea. I didn't have to change anything in 
your code (other than the path to the texture, I used 
Images/osg256.png which is found through OSG_FILE_PATH) and it worked.


If it doesn't work for you, put a breakpoint after the 
osgDB::readImageFile() call and see if the image loaded. If not, that 
means there's some problem with your plugins. You can set an environment 
variable called OSG_NOTIFY_LEVEL=DEBUG and OSG will be more verbose 
about where it searches for its plugins and also where it looks for data 
files you ask it to load. That will help you debug this.


Now, since you're using vertex indices, and you needed to list the 
vertices in counter-clockwise order to get the right front-facing, the 
texture coordinates don't work for half the faces (the texture is 
warped). I would suggest listing the vertices of each face directly (you 
can use triangle strips to get less data, though for a simple cube it 
won't matter much.


As for having a different texture on each face, you can do that in 
different ways: either have one texture that has all faces unwrapped, 
and set up the texcoords to use the right portion of the texture for 
each face, or have different textures in each texture unit as you were 
going to do.


In general this is work that is much easier to do in a 3D modeling 
software. There is little reason to go making geometry (especially with 
complex texture mapping) through code, it's much easier to do it 
visually and it just becomes data you can replace more easily than 
having to modify an algorithm, recompile the code, test it, debug it...


Hope this helps,

J-S
--
__
Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Having trouble with basic texture mapping on a 3d object

2010-05-25 Thread Justen Falk
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,