[osg-users] Related to osg lines

Rambabu Repaka ramboram488 at gmail.com
Tue Apr 18 05:24:23 PDT 2017


Hi, Iam using the following code and drawing the lines in osg and clamping the lines to the terrain for the purpose of road drawing

        LineSymbol* line = style.getOrCreate<LineSymbol>();
        line->stroke()->color() = Color(Color::Black, 0.5f);
        line->stroke()->width() = 8.0f;
        line->tessellationSize() = 5;
        line->stroke()->widthUnits() = Units::METERS;

       AltitudeSymbol* alt = style.getOrCreate<AltitudeSymbol>();
        alt->clamping() = alt->CLAMP_TO_TERRAIN;

       But for me i want road with texture so what iam 
       adding the quad and applying texture in the below code

       osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
	vertices->push_back(osg::Vec3(-1.0f,0.0f,-2.0f));
	vertices->push_back(osg::Vec3(1.0f,0.0f,-2.0f));
	vertices->push_back(osg::Vec3(1.0f,0.0f,2.0f));
	vertices->push_back(osg::Vec3(-1.0f,0.0f,2.0f));

	osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
	normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f));

	osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
	colors->push_back(osg::Vec4(0.0f, 0.0f, 0.0f,0.0f));
       
        osg::ref_ptr<osg::Vec2Array> texcoords = new osg::Vec2Array;
	texcoords->push_back(osg::Vec2(0.0f, 0.0f));
	texcoords->push_back(osg::Vec2(0.0f, 1.0f));
	texcoords->push_back(osg::Vec2(1.0f, 1.0f));
	texcoords->push_back(osg::Vec2(1.0f, 0.0f));

	osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
	geom->setVertexArray(vertices.get());
	geom->setNormalArray(normals.get());
	geom->setColorArray(colors.get());
	geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
	geom->setTexCoordArray(0,texcoords.get());
	geom->setColorBinding(osg::Geometry::BIND_OVERALL);
	geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4));

	osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
	texture->setWrap(osg::Texture2D::WRAP_S,  
        osg::Texture2D::CLAMP);                                                  
	texture->setWrap(osg::Texture2D::WRAP_T, 
        osg::Texture2D::CLAMP);
	osg::ref_ptr<osg::Image> image = 
        osgDB::readImageFile("D:/Images/roadPic.jpg");
        texture->setImage(image);
       
        osg::ref_ptr<osg::Geode> root = new osg::Geode;
	root->addDrawable(geom.get());
	  root->getOrCreateStateSet()->setTextureAttributeAndModes(0,texture.get());

 how to clamp the quad to the terrain  for drawing the road in osgearth  or any other way to add the texture to those lines? 




... 

Thank you!

Cheers,
Rambabu

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








More information about the osg-users mailing list