[osg-users] OSG 3.0.0 appearance of osg::Box changed when rendered in Wireframe mode?

2011-08-18 Thread Christian Buchner
Hi,

with OSG 2.8.2 we were able to create a cube like this and set polygon
mode to LINE. And it would show up as the outline
of a box with no diagonals in the faces.

With OSG 3.0.0 the same code produces a box that now contains diagonal
lines, as if the quads are now actually tesselated
into triangles.

Is there any compatibility flag that would allow us to get the old
behavior back?

Code snippets follow:

static osg::Geode* createCube(float fRadius,osg::Vec3 vPosition,
osg::Vec4 color)
{
// create a cube shape
osg::Box *bCube = new osg::Box(vPosition,fRadius);
// create a container that makes the cube drawable
osg::ShapeDrawable *sdCube = new osg::ShapeDrawable(bCube);
sdCube-setColor(color);
// create a geode object to as a container for our drawable cube object
osg::Geode* geodeCube = new osg::Geode();
// add our drawable cube to the geode container
geodeCube-addDrawable(sdCube);
return(geodeCube);
}

if (m_wireframeCube == NULL) m_wireframeCube = createCube(1.0,
osg::Vec3(0.0, 0.0, 0.5), osg::Vec4(0.5f, 0.5f, 0.5f, 1.0f));

//
// Wireframe box
//
osg::StateSet *state2 = new osg::StateSet();
state2-setMode( GL_LIGHTING, osg::StateAttribute::PROTECTED |
osg::StateAttribute::OFF );

m_transform2 = new osg::MatrixTransform;
m_transform2-setMatrix(osg::Matrix::scale(m_width, m_width,
m_height) * osg::Matrix::translate(position));

osg::PolygonMode *polyModeObj;
if ( !(polyModeObj = dynamic_cast osg::PolygonMode* (
state2-getAttribute( osg::StateAttribute::POLYGONMODE ))) ) {
state2-setAttribute( new osg::PolygonMode(
osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE ));
} else polyModeObj-setMode( osg::PolygonMode::FRONT_AND_BACK,
osg::PolygonMode::LINE );

osg::LineWidth *lineWidthObj;
if ( !(lineWidthObj = dynamic_cast osg::LineWidth* (
state2-getAttribute( osg::StateAttribute::LINEWIDTH ))) ) {
state2-setAttribute( new osg::LineWidth( 2.0f ) );
} else lineWidthObj-setWidth( 2.0f );

m_transform2-addChild(m_wireframeCube);

m_transform2-setStateSet(state2);
addChild(m_transform2);
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] OSG 3.0.0 appearance of osg::Box changed when rendered in Wireframe mode?

2011-08-18 Thread Christian Buchner
Hi all,

I solved this by rolling my own geometry and dropping the use of
osg::Box. This function replaces the createCube function from the
previously posted code snippet.

I simply define my own color, vertex and normal buffer using Quad primitives.
Now the wireframe looks sane again.

static osg::Geode* createCube(float fRadius, osg::Vec3 vPosition,
osg::Vec4 color)
{
osg::Geode* geode = new osg::Geode();
osg::Geometry* cubeGeom = new osg::Geometry();

osg::Vec4Array *colors = new osg::Vec4Array;
colors-push_back(color);

// define normals for each face
osg::ref_ptrosg::Vec3Array cube_normals = new osg::Vec3Array;
cube_normals-push_back(osg::Vec3( 0.0f,-1.0f, 0.0f));
cube_normals-push_back(osg::Vec3( 0.0f,-1.0f, 0.0f));
cube_normals-push_back(osg::Vec3( 0.0f,-1.0f, 0.0f));
cube_normals-push_back(osg::Vec3( 0.0f,-1.0f, 0.0f));

cube_normals-push_back(osg::Vec3( 0.0f,+1.0f, 0.0f));
cube_normals-push_back(osg::Vec3( 0.0f,+1.0f, 0.0f));
cube_normals-push_back(osg::Vec3( 0.0f,+1.0f, 0.0f));
cube_normals-push_back(osg::Vec3( 0.0f,+1.0f, 0.0f));

cube_normals-push_back(osg::Vec3(+1.0f,+0.0f, 0.0f));
cube_normals-push_back(osg::Vec3(+1.0f,+0.0f, 0.0f));
cube_normals-push_back(osg::Vec3(+1.0f,+0.0f, 0.0f));
cube_normals-push_back(osg::Vec3(+1.0f,+0.0f, 0.0f));

cube_normals-push_back(osg::Vec3(-1.0f,+0.0f, 0.0f));
cube_normals-push_back(osg::Vec3(-1.0f,+0.0f, 0.0f));
cube_normals-push_back(osg::Vec3(-1.0f,+0.0f, 0.0f));
cube_normals-push_back(osg::Vec3(-1.0f,+0.0f, 0.0f));

cube_normals-push_back(osg::Vec3( 0.0f,+0.0f,-1.0f));
cube_normals-push_back(osg::Vec3( 0.0f,+0.0f,-1.0f));
cube_normals-push_back(osg::Vec3( 0.0f,+0.0f,-1.0f));
cube_normals-push_back(osg::Vec3( 0.0f,+0.0f,-1.0f));

cube_normals-push_back(osg::Vec3( 0.0f,+0.0f,+1.0f));
cube_normals-push_back(osg::Vec3( 0.0f,+0.0f,+1.0f));
cube_normals-push_back(osg::Vec3( 0.0f,+0.0f,+1.0f));
cube_normals-push_back(osg::Vec3( 0.0f,+0.0f,+1.0f));

vPosition += osg::Vec3(+fRadius/2, +fRadius/2, +fRadius/2);

// note, counterclockwise winding order with respect to normals
osg::Vec3 myCoords[] =
{
// bottom face
osg::Vec3(-fRadius, -fRadius, -fRadius) + vPosition,
osg::Vec3(+fRadius, -fRadius, -fRadius) + vPosition,
osg::Vec3(+fRadius, -fRadius, +fRadius) + vPosition,
osg::Vec3(-fRadius, -fRadius, +fRadius) + vPosition,

// top face
osg::Vec3(-fRadius, +fRadius, +fRadius) + vPosition,
osg::Vec3(+fRadius, +fRadius, +fRadius) + vPosition,
osg::Vec3(+fRadius, +fRadius, -fRadius) + vPosition,
osg::Vec3(-fRadius, +fRadius, -fRadius) + vPosition,

// right face
osg::Vec3(+fRadius, -fRadius, -fRadius) + vPosition,
osg::Vec3(+fRadius, +fRadius, -fRadius) + vPosition,
osg::Vec3(+fRadius, +fRadius, +fRadius) + vPosition,
osg::Vec3(+fRadius, -fRadius, +fRadius) + vPosition,

// left face
osg::Vec3(-fRadius, -fRadius, +fRadius) + vPosition,
osg::Vec3(-fRadius, +fRadius, +fRadius) + vPosition,
osg::Vec3(-fRadius, +fRadius, -fRadius) + vPosition,
osg::Vec3(-fRadius, -fRadius, -fRadius) + vPosition,

// front face
osg::Vec3(-fRadius, +fRadius, -fRadius) + vPosition,
osg::Vec3(+fRadius, +fRadius, -fRadius) + vPosition,
osg::Vec3(+fRadius, -fRadius, -fRadius) + vPosition,
osg::Vec3(-fRadius, -fRadius, -fRadius) + vPosition,

// back face
osg::Vec3(-fRadius, -fRadius, +fRadius) + vPosition,
osg::Vec3(+fRadius, -fRadius, +fRadius) + vPosition,
osg::Vec3(+fRadius, +fRadius, +fRadius) + vPosition,
osg::Vec3(-fRadius, +fRadius, +fRadius) + vPosition
};

int numCoords = sizeof(myCoords)/sizeof(osg::Vec3);
osg::Vec3Array* vertices = new osg::Vec3Array(numCoords,myCoords);
cubeGeom-setVertexArray(vertices);

cubeGeom-addPrimitiveSet(new
osg::DrawArrays(osg::PrimitiveSet::QUADS,0,numCoords));

cubeGeom-setColorArray(colors);
cubeGeom-setColorBinding(osg::Geometry::BIND_OVERALL);

cubeGeom-setNormalArray(cube_normals.get());
cubeGeom-setNormalBinding(osg::Geometry::BIND_PER_VERTEX);

geode-addDrawable(cubeGeom);

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


Re: [osg-users] OSG 3.0.0 appearance of osg::Box changed when rendered in Wireframe mode?

2011-08-18 Thread Paul Martz

On 8/18/2011 4:28 AM, Christian Buchner wrote:

Hi,

with OSG 2.8.2 we were able to create a cube like this and set polygon
mode to LINE. And it would show up as the outline
of a box with no diagonals in the faces.

With OSG 3.0.0 the same code produces a box that now contains diagonal
lines, as if the quads are now actually tesselated
into triangles.
Right. The GL_QUADS primitive was removed in OpenGL 3.1. The OSG ShapeDrawable 
code was modified to use triangles so that the same code path could be used for 
both GL 3x and GL 1x/2x.

Is there any compatibility flag that would allow us to get the old
behavior back?
For ShapeDrawable? Not that I know of. However, osgworks.googlecode.com offers a 
Geometry-based version of OSG's ShapeDrawables, and the makeWireBox function 
will produce results similar to what you are used to seeing, so you might want 
to consider that. osgWorks is compatible with OSG v2.6 through current v3.0.1.

   -Paul

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