I've done this stuff before for buildings that are vertically extruded from a polygon shape
step 1) create an osg::Geometry 2) create a vertex buffer with two copies of the polygon vertices, the second copy having a different z coordinate. use setVertexArray() 3) For proper lighting, create a normal array also with one normal per vertex, matching the indexing in the vertex array. use setNormalArray(). 4) run a tesselation algorithm to to create a list of triangles that will form the top and bottom faces (concave polygons aren't supported in hardware, so tesselation is mandatory) 5) using an index buffer, create triangle primitives for the top and bottom faces based on the tesselation results 6) create a quads primitive for the surfaces on the side, possibly also using index buffers. You can't really use a quad strip here, or the normal vectors for touching quads will be shared, which leads to an (undesired) smooth shading effect for the sides. some very small code snippets // less then 256 vertices can use an UByte based index buffer std::vector<unsigned char> indices_c; // omitted here is the tesselation process creating the vertex indices roofGeometry->addPrimitiveSet(new osg::DrawElementsUByte( GL_TRIANGLES, indices_c.size(), &indices_c[0] )); // alternatively less then 65536 vertices can use an UShort based index buffer std::vector<unsigned short> indices_s; // omitted here is the tesselation process creating the vertex indices roofGeometry->addPrimitiveSet(new osg::DrawElementsUShort( GL_TRIANGLES, indices_s.size(), &indices_s[0] )); // I am actually storing my vertices for the quads in a separate Geometry, so I can use DrawArrays instead of an index buffer for the quads making up the sides. Then the vertices for each quad are taken in sequential order from the vertex buffer. sideGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,num_vertices_per_polygon_ring); If you need your quad strip on the side to have different color or different vertex attributes, your vertex buffer needs to contain the polygon ring four times. You should look at some osg examples that create their own geometry based on vertex buffers to get the hang of it. Christian 2013/2/26 Robert Osfield <[email protected]> > Hi Mohammed, > > On 26 February 2013 04:19, Mohammed Rashad > <[email protected]> wrote: > > Is it possible to have a 2D square looks like a cube? > > You can do anything you want with your geometry, but you have to > create what you want, the OSG doesn't provide a means of automatically > converting a square/polygon to a object with sides and end caps like > your photo. What you are asking for is very specific function and is > has to be implemented in user code. > > Once you have you geometry you can animate it using an update callback > that updates the vertices on the geometry, or use a shader to do the > same. > > Robert. > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

