Re: [osg-users] Newbie Texture Question
On 10/9/2011 9:28 AM, Robbo wrote: > I am trying to learn OSG for use in Flightgear. I have seen a technique used > regularly > that I am not able to figure out. > Essentially a scene is using an rgb file which is transparent and whilst > quite large > (1024x768), contains many different 'icons' of smaller size and what appears > to be an > 'alpha mask' for the main image area. These icons appear to be extracted and > used within > a dynamic scene, but I am not sure how this is done as it does not appear > obvious in the > code (i was expecting some image coordinates at least). > The particular example within Flightgear (for those who may be familiar) is > wxradar.cxx > and wxecho.rgb) > Could somebody please take the time to explain how this works in principle > and what the > technique is called? Sounds a bit like a Texture Atlas. Yes, I would expect either the UV coordinates to be altered, or perhaps the transform/translate of the texture coordinate matrix. > Robbo -- Chris 'Xenon' Hanson, omo sanza lettere. xe...@alphapixel.com http://www.alphapixel.com/ Digital Imaging. OpenGL. Scene Graphs. GIS. GPS. Training. Consulting. Contracting. "There is no Truth. There is only Perception. To Perceive is to Exist." - Xen ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Newbie Texture Question
Hi, I am trying to learn OSG for use in Flightgear. I have seen a technique used regularly that I am not able to figure out. Essentially a scene is using an rgb file which is transparent and whilst quite large (1024x768), contains many different 'icons' of smaller size and what appears to be an 'alpha mask' for the main image area. These icons appear to be extracted and used within a dynamic scene, but I am not sure how this is done as it does not appear obvious in the code (i was expecting some image coordinates at least). The particular example within Flightgear (for those who may be familiar) is wxradar.cxx and wxecho.rgb) Could somebody please take the time to explain how This works in principle and what the technique is called? Many thanks, Robbo ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] newbie texture question
A previous post suggested I try something other than a bmp. So just to make sure it was not my image I tried a different jpg instead and it worked fine. I then went back and tried it just using the standard osg::box and it worked as well. So It looks like the bulk of my problems was the image I was trying to map to the objects. I don't understand why, but bmp's, or my specific bmp, do not work well for some reason. I believe this solves my problems with this issue. Thanks David -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=24639#24639 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] newbie texture question
Ok. I can get the mesh to work using the mtl file, but I have gone back and tried to get the basic geometric textures working and I am still having problems. I created a simple geometry for a box using the code shown below. I set it up to try and place the texture file once on each face. When I run this I get something that looks exactly like what happens when I just use the box shape. This is getting frustrating. Any help with what I am doing wrong would be greatly appreciated. Code: osg::Geometry* CreateBoxGeometry() { osg::Geometry* box = new osg::Geometry; // Vertices osg::Vec3Array* vertices = new osg::Vec3Array; vertices->push_back(osg::Vec3(-.5, -.5, -.5)); // 0 vertices->push_back(osg::Vec3( .5, -.5, -.5)); // 3 vertices->push_back(osg::Vec3( .5, -.5, .5)); // 5 vertices->push_back(osg::Vec3(-.5, -.5, .5)); // 1 vertices->push_back(osg::Vec3(-.5, -.5, .5)); // 1 vertices->push_back(osg::Vec3( .5, -.5, .5)); // 5 vertices->push_back(osg::Vec3( .5, .5, .5)); // 7 vertices->push_back(osg::Vec3(-.5, .5, .5)); // 4 vertices->push_back(osg::Vec3(-.5, -.5, -.5)); // 0 vertices->push_back(osg::Vec3(-.5, -.5, .5)); // 1 vertices->push_back(osg::Vec3(-.5, .5, .5)); // 4 vertices->push_back(osg::Vec3(-.5, .5, -.5)); // 2 vertices->push_back(osg::Vec3( .5, -.5, -.5)); // 3 vertices->push_back(osg::Vec3( .5, .5, -.5)); // 6 vertices->push_back(osg::Vec3( .5, .5, .5)); // 7 vertices->push_back(osg::Vec3( .5, -.5, .5)); // 5 vertices->push_back(osg::Vec3( .5, .5, -.5)); // 6 vertices->push_back(osg::Vec3(-.5, .5, -.5)); // 2 vertices->push_back(osg::Vec3(-.5, .5, .5)); // 4 vertices->push_back(osg::Vec3( .5, .5, .5)); // 7 vertices->push_back(osg::Vec3( .5, -.5, -.5)); // 3 vertices->push_back(osg::Vec3(-.5, -.5, -.5)); // 0 vertices->push_back(osg::Vec3(-.5, .5, -.5)); // 2 vertices->push_back(osg::Vec3( .5, .5, -.5)); // 6 box->setVertexArray(vertices); // Normals osg::Vec3Array* normals = new osg::Vec3Array; normals->push_back(osg::Vec3( 0, -1, 0)); normals->push_back(osg::Vec3( 0, -1, 0)); normals->push_back(osg::Vec3( 0, -1, 0)); normals->push_back(osg::Vec3( 0, -1, 0)); normals->push_back(osg::Vec3( 0, 0, 1)); normals->push_back(osg::Vec3( 0, 0, 1)); normals->push_back(osg::Vec3( 0, 0, 1)); normals->push_back(osg::Vec3( 0, 0, 1)); normals->push_back(osg::Vec3(-1, 0, 0)); normals->push_back(osg::Vec3(-1, 0, 0)); normals->push_back(osg::Vec3(-1, 0, 0)); normals->push_back(osg::Vec3(-1, 0, 0)); normals->push_back(osg::Vec3( 1, 0, 0)); normals->push_back(osg::Vec3( 1, 0, 0)); normals->push_back(osg::Vec3( 1, 0, 0)); normals->push_back(osg::Vec3( 1, 0, 0)); normals->push_back(osg::Vec3( 0, 1, 0)); normals->push_back(osg::Vec3( 0, 1, 0)); normals->push_back(osg::Vec3( 0, 1, 0)); normals->push_back(osg::Vec3( 0, 1, 0)); normals->push_back(osg::Vec3( 0, 0, -1)); normals->push_back(osg::Vec3( 0, 0, -1)); normals->push_back(osg::Vec3( 0, 0, -1)); normals->push_back(osg::Vec3( 0, 0, -1)); box->setNormalArray(normals); box->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); // Faces box->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, vertices->size())); // Colors osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1,1,1,1)); box->setColorArray(colors); box->setColorBinding(osg::Geometry::BIND_OVERALL); // Text Coords osg::Vec2Array* tx = new osg::Vec2Array; tx->push_back(osg::Vec2( 0.f, 0.f)); // 0 tx->push_back(osg::Vec2( 1.f, 0.f)); // 3 tx->push_back(osg::Vec2( 1.f, 1.f)); // 5 tx->push_back(osg::Vec2( 0.f, 1.f)); // 1 tx->push_back(osg::Vec2( 0.f, 0.f)); // 1 tx->push_back(osg::Vec2( 1.f, 0.f)); // 5 tx->push_back(osg::Vec2( 1.f, 1.f)); // 7 tx->push_back(osg::Vec2( 0.f, 1.f)); // 4 tx->push_back(osg::Vec2( 0.f, 0.f)); // 0 tx->push_back(osg::Vec2( 1.f, 0.f)); // 1 tx->push_back(osg::Vec2( 1.f, 1.f)); // 4 tx->push_back(osg::Vec2( 0.f, 1.f)); // 2 tx->push_back(osg::Vec2( 0.f, 0.f)); // 3 tx->push_back(osg::Vec2( 1.f, 0.f)); // 6 tx->push_back(osg::Vec2( 1.f, 1.f)); // 7 tx->push_back(osg::Vec2( 0.f, 1.f)); // 5 tx->push_back(osg::Vec2( 0.f, 0.f)); // 6 tx->push_back(osg::Vec2( 1.f, 0.f)); // 2 tx->push_back(osg::Vec2( 1.f, 1.f)); // 4 tx->push_back(osg::Vec2( 0.f, 1.f)); // 7 tx->push_back(osg::Vec2( 0.f, 0.f)); // 3 tx->push_back(osg::Vec2( 1.f, 0.f)); // 0 tx->push_back(osg::Vec2( 1.f, 1.f)); // 2 tx->push_back(osg::Vec2( 0.f, 1.f)); // 6 box->setTexCoordArray( 0, tx ); return box; } osg::Node* createModel() { osg::Group* root = new osg::Group;
Re: [osg-users] newbie texture question
David Cofer wrote: You rock Alberto!! I flipped the bmp and it mapped correctly. It would never have occured to me to do that in a million years on my own. Thanks. Random facts you may or may not care about... DirectX uses a different origin from OpenGL when applying textures (DirectX uses the top-left, while OpenGL uses the bottom-left). You might also run into problems with winding order of primitives (triangles, etc.). Unlike the rest of the world, DirectX uses right-handed coordinates. This results in vertices for primitives being specified in a clockwise order, unlike OpenGL which expects counter-clockwise vertices. You're probably OK since you're using a .obj file directly. When I was writing the Half-Life 2 loader, I had to flip the vertex order as I was loading them, or I would get back-faces facing out, which would disappear when back-face culling was turned on. --"J" ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] newbie texture question
"David Cofer" writes: > You rock Alberto!! I flipped the bmp and it mapped correctly. It would never > have occured to me to do that in a million years on my own. Thanks. Glad I could help :) See below. > I tried to step into the osg code, but it did not work. It just stepped over > it. I am loading the debug versions, so I am not completly sure why it is not > working. I will keep playing with it to see if it is dropping the u,v coords > as you suspect. Worst case scenario I just remove the ability to apply a > texture at run-time for a mesh and make them specify it in the mesh file. Meanwhile you could specify some default texture of yours in the file and then use the osgUtil::Optimizer::TextureVisitor class to change it for another at run-time. -- Alberto ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] newbie texture question
Hi David, I will keep playing with it to see if it is dropping the u,v coords as you suspect. Worst case scenario I just remove the ability to apply a texture at run-time for a mesh and make them specify it in the mesh file. Or, just map a dummy white 1x1 texture by default, so that the obj loader thinks there's a texture and keeps the UVs (if that's indeed the problem). Applying a texture at run time is not a problem, it's getting the model loaded with the proper texture coordinates that is... After that it's just a matter of model->getOrCreateStateSet()->setTextureAttributeAndModes(0, my_new_texture.get(), osg::StateAttribute::ON); 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
Re: [osg-users] newbie texture question
You rock Alberto!! I flipped the bmp and it mapped correctly. It would never have occured to me to do that in a million years on my own. Thanks. I tried to step into the osg code, but it did not work. It just stepped over it. I am loading the debug versions, so I am not completly sure why it is not working. I will keep playing with it to see if it is dropping the u,v coords as you suspect. Worst case scenario I just remove the ability to apply a texture at run-time for a mesh and make them specify it in the mesh file. Thanks for your help. David -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=24610#24610 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] newbie texture question
"David Cofer" writes: > I added the recommended line to the mtl file and it did apply the texture to > the object this time, but it was still incorrect compared to what is seen in > directx. See picture. I tried a couple of the options for the map_Kd command > and none helped. I think the difference lies in the coordinate system for the texture space. If you flip your bmp upside down, you will get the correct result. I don't know if it's a Directx or bmp thing. Try to convert your file to other format, e.g. jpg to see if it still happens. > Also, this will not help me in the long run becuase my final application has > the option of allowing the user to specify the image file they want to use as > a texture for their objects. This means I will need to re-apply the texture > at runtime, and not load it in from the mtl file. I believe that requires the > use of the stateset objects, which are not working correclty for me. I suspect that the obj plugin *might* be discarding the uv info if it not finds any texture image in the material definition. You can check the source of the obj plugin to be sure. -- Alberto ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] newbie texture question
I added the recommended line to the mtl file and it did apply the texture to the object this time, but it was still incorrect compared to what is seen in directx. See picture. I tried a couple of the options for the map_Kd command and none helped. Also, this will not help me in the long run becuase my final application has the option of allowing the user to specify the image file they want to use as a texture for their objects. This means I will need to re-apply the texture at runtime, and not load it in from the mtl file. I believe that requires the use of the stateset objects, which are not working correclty for me. Thanks, David -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=24542#24542 Attachments: http://forum.openscenegraph.org//files/textureexamples3_717.jpg ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] newbie texture question
"David Cofer" writes: [...] > I also tested a texture mapping using a loaded .obj file. It has the > explicit u,v texture coordinates defined in the file, but it still > does not work. I have to be missing something here. Yes. There is no need to create an StateSet here. The problem is that your .mtl is incomplete. It doesn't mention what file are you using as texture. Just add this line at the end of Thorax.mtl: map_Kd GrasshopperTexture.bmp You can also use just the osgviewer program in order to test your models like this: osgviewer Thorax.obj -- Alberto ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] newbie texture question
Ok. I still think it is silly that the default implementation does not produce a basic texture mapping, but I will accept that. However, I also tested a texture mapping using a loaded .obj file. It has the explicit u,v texture coordinates defined in the file, but it still does not work. I have to be missing something here. I have attached a picture of what I get for this obj file in directx vs osg, and I have attached the code and model I am using. Am I doing something wrong that the texture coordinates are messed up or something? Why are they not working correctly in OSG? Thanks David -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=24529#24529 Attachments: http://forum.openscenegraph.org//files/textureexamples2_565.jpg http://forum.openscenegraph.org//files/meshtest_173.zip ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] newbie texture question
Hi David, The osg::ShapeDrawable classes is only simply convenience classes, it isn't able to map all the possible combinations of the way you might want to apply. For fine control you have to use osg::Geometry to build up the coordinates and texture coordinates yourself. See the osggeometry example. Robert. On Fri, Feb 19, 2010 at 10:42 PM, David Cofer wrote: > Hi, > > I am new to OSG and I am attempting to port some work that was done in > directX over to OSG. I am using some of the basic geometric objects like > osg::box and osg::sphere. I got those working like I wanted, but when I tried > to add texture mapping to them the results are very different than what I got > in DirectX. For example, by default in directX when I mapped a texture to a > box then each face got a full copy of the texture. However, when I map the > same texture to the box in osg I get some weird stretched lines over the > faces. > > Do the standard geometric objects not have texture coordinates already > defined, or am I doing something simple wrong? I have listed a code snippet > below. I have also tried using all of the different texture modes, and none > of them really worked. > Do I have to set the texture coords up manually? Seems to defeat the purpose > of having simple objects predefined if I have to do a bunch of manual texture > corrdinate code for each one. > > I have attached an image example showing the difference between the directx > and osg versions. > > > Code: > > osg::ref_ptr gNode = new > osg::MatrixTransform(osg::Matrix::translate(osg::Vec3(0, 0,0))); > osg::ref_ptr boxDrawable = new > osg::ShapeDrawable(new osg::Box(osg::Vec3(0,0,0), 10, 10, 10)); > osg::ref_ptr box = new osg::Geode; > box->addDrawable(boxDrawable.get()); > gNode->addChild(box.get()); > root->addChild(gNode.get()); > osg::ref_ptr image = osgDB::readImageFile("gravel.bmp"); > osg::StateSet* state = box->getOrCreateStateSet(); > state->setTextureAttributeAndModes(0, new osg::Texture2D(image.get())); > > > > > Thank you! > > Cheers, > David > > -- > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=24516#24516 > > > > > Attachments: > http://forum.openscenegraph.org//files/textureexamples_200.jpg > > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] newbie texture question
Hi, I am new to OSG and I am attempting to port some work that was done in directX over to OSG. I am using some of the basic geometric objects like osg::box and osg::sphere. I got those working like I wanted, but when I tried to add texture mapping to them the results are very different than what I got in DirectX. For example, by default in directX when I mapped a texture to a box then each face got a full copy of the texture. However, when I map the same texture to the box in osg I get some weird stretched lines over the faces. Do the standard geometric objects not have texture coordinates already defined, or am I doing something simple wrong? I have listed a code snippet below. I have also tried using all of the different texture modes, and none of them really worked. Do I have to set the texture coords up manually? Seems to defeat the purpose of having simple objects predefined if I have to do a bunch of manual texture corrdinate code for each one. I have attached an image example showing the difference between the directx and osg versions. Code: osg::ref_ptr gNode = new osg::MatrixTransform(osg::Matrix::translate(osg::Vec3(0, 0,0))); osg::ref_ptr boxDrawable = new osg::ShapeDrawable(new osg::Box(osg::Vec3(0,0,0), 10, 10, 10)); osg::ref_ptr box = new osg::Geode; box->addDrawable(boxDrawable.get()); gNode->addChild(box.get()); root->addChild(gNode.get()); osg::ref_ptr image = osgDB::readImageFile("gravel.bmp"); osg::StateSet* state = box->getOrCreateStateSet(); state->setTextureAttributeAndModes(0, new osg::Texture2D(image.get())); Thank you! Cheers, David -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=24516#24516 Attachments: http://forum.openscenegraph.org//files/textureexamples_200.jpg ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org