Hi,

I have stumble on what seems to be a bug. It seems that when using the same 
coordinates for vertices with osg::PrimitiveSet::POINTS and 
osg::PrimitiveSet::LINES or LINE_LOOP, those vertices don't show up at the same 
place on the screen.  They are indeed displayed one pixel off.

I have attatched some code that produces this result.

I'm using an ortho2D projection, I don't know if it's linked to the problem.

the resulting image :
(d'oh.. can't post it yet)

Thank you!

Cheers,
lwi

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



#include <osg/Geode>
#include <osg/Geometry>
#include <osg/Material>
#include <osg/Vec3>
#include <osg/MatrixTransform>
#include <osg/Texture2D>
#include <osg/PolygonStipple>
#include <osg/TriangleFunctor>
#include <osg/io_utils>
#include <osg/Point>
#include <osg/LineWidth>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>

#include <osgGA/TrackballManipulator>

#include <osgViewer/Viewer>

#include <osg/Math>

#include <iostream>


osg::Geode* createGeode( osg::Vec3Array* vert, const osg::Vec4d& color, GLenum mode ) {

    osg::Geometry* linesGeom = new osg::Geometry();
    linesGeom->setVertexArray(vert);

    osg::Vec4Array* colors = new osg::Vec4Array;
    colors->push_back( color );
    linesGeom->setColorArray( colors);
    linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL);

    linesGeom->addPrimitiveSet(new osg::DrawArrays(mode, 0, 4));
    linesGeom->getOrCreateStateSet()->setAttribute( new osg::Point( 1.0f ), osg::StateAttribute::ON );
    osg::Geode* geode = new osg::Geode();
    geode->addDrawable(linesGeom);
    return geode;
}

int main(int, char **)
{

    int width = 100;
    int height = 100;

    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
    traits->x = 0;
    traits->y = 0;
    traits->width = width;
    traits->height = height;
    traits->windowDecoration = true;
    //traits->samples=4;
    traits->doubleBuffer = true;
    // traits->sharedContext = 0;
    traits->vsync = true;
    traits->overrideRedirect = true;
    osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());

    // create the model
    osg::Group* root = new osg::Group;

    osg::Vec3Array* va = new osg::Vec3Array(4);

    (*va)[0].set(  10, 10, 0 );
    (*va)[1].set(  20, 10, 0 );
    (*va)[2].set(  20, 20, 0 );
    (*va)[3].set(  10, 20, 0 );

    root->addChild( createGeode( va, osg::Vec4d(1,0,0,1), osg::PrimitiveSet::POINTS ) );
    root->addChild( createGeode( va, osg::Vec4d(1,1,1,1), osg::PrimitiveSet::LINE_LOOP ) );

    osgViewer::Viewer viewer;

    // add model to viewer.
    viewer.setSceneData( root );
    viewer.setUpViewInWindow(0,0,traits->width, traits->height);

    osg::Camera* camera = viewer.getCamera();
    camera->setGraphicsContext(gc.get());
    camera->setProjectionMatrix( osg::Matrix::ortho2D( 0, traits->width, 0, traits->height ) );
    camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
    camera->setClearColor( osg::Vec4(0,0,0,1 ) );
    camera->setViewMatrix(osg::Matrix::identity());
    camera->setProjectionResizePolicy( osg::Camera::FIXED );
    camera->setCullingMode( camera->getCullingMode() & ~osg::CullSettings::SMALL_FEATURE_CULLING ); // ~ == not bit

    osg::Viewport* vp = camera->getViewport();
    printf("vp: (%f, %f) .. (%f, %f)\n", vp->x(), vp->y(), vp->width(), vp->height());
    vp->setViewport( 0,0,traits->width, traits->height );

    osg::StateSet* sss = camera->getOrCreateStateSet();
    sss->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
    sss->setMode(GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::OVERRIDE);
    sss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);

    viewer.realize();

    // program loop:
    while( !viewer.done() )  viewer.frame();

    return 0;

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

Reply via email to