Re: [osg-users] problem with ortho2D viewport

2009-08-28 Thread Paul Martz




ximo o + wrote:

      while(!viewer.done()) {
        viewer.getCamera()->setViewMatrix(osg::Matrix::identity());
        viewer.getCamera()->setViewMatrixAsLookAt(osg::Vec3(0, 0,
-10), osg::Vec3(0, 0, 0), osg::Vec3(0, 1, 0));
        viewer.frame();
    }
  

Hi -- Try changing your main loop to this:
while( !viewer.done()) {
    viewer.frame();
}

Based on what you said you are trying to do, the two lines I removed
just don't make sense, so I don't know why you have them there.
   -Paul



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


[osg-users] problem with ortho2D viewport

2009-08-28 Thread ximo o +









Hello



I'm trying to build a 2D scene with orthographic projection. My problem
is that each time I execute the program, the viewport seems to be
different. I mean each time the quad has different size in the screen.



I'va always used the default viewer before and touching cameras and viewports 
is quite new to me. My not working code is below.



Thank you.



Xim.



int main(int argc, char *argv[]) {

osg::ArgumentParser arguments(&argc, argv);

osgViewer::Viewer viewer;



osg::ref_ptr root = simpleScene(); // quad with texture



osg::Camera *camera = new osg::Camera;

camera->setProjectionMatrix(osg::Matrix::ortho2D(-10, 10, -10, 10));

camera->setViewport(0, 0, 1280, 1024);

camera->setViewMatrix(osg::Matrix::identity());



viewer.setCamera(camera);

viewer.setSceneData(root.get());



while(!viewer.done()) {

viewer.getCamera()->setViewMatrix(osg::Matrix::identity());

viewer.getCamera()->setViewMatrixAsLookAt(osg::Vec3(0, 0, -10), 
osg::Vec3(0, 0, 0), osg::Vec3(0, 1, 0));

viewer.frame();

}



 return 0;

}





osg::Node *simpleScene(void) {


osg::Image *image = osgDB::readImageFile("tex1.jpg");


osg::Geometry *geom = new osg::Geometry;


osg::Texture2D *t2d = new osg::Texture2D;


t2d->setImage(image);


t2d->setUnRefImageDataAfterApply(true);





osg::StateSet *ss = geom->getOrCreateStateSet();


ss->setTextureAttribute(0, t2d);


ss->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::ON);





osg::Vec3Array *v = new osg::Vec3Array;


osg::Vec3Array *n = new osg::Vec3Array;


osg::Vec3Array *c = new osg::Vec3Array;


osg::Vec2Array *t = new osg::Vec2Array;


v->push_back(osg::Vec3(-1, -1, 0));


v->push_back(osg::Vec3(1,-1, 0));


v->push_back(osg::Vec3(1, 1, 0));


v->push_back(osg::Vec3(-1, 1, 0));


c->push_back(osg::Vec3(1, 1, 1));


c->push_back(osg::Vec3(1, 1, 1));


c->push_back(osg::Vec3(1, 1, 1));


c->push_back(osg::Vec3(1, 1, 1));


t->push_back(osg::Vec2(0, 0));


t->push_back(osg::Vec2(1, 0));


t->push_back(osg::Vec2(1, 1));


t->push_back(osg::Vec2(0, 1));


n->push_back(osg::Vec3(0, 0, -1));


geom->setVertexArray(v);


geom->setColorArray(c);


geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);


geom->setNormalArray(n);


geom->setNormalBinding(osg::Geometry::BIND_OVERALL);


geom->setTexCoordArray(0, t);





geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, 
v->size()));


osg::Geode *geode = new osg::Geode;


geode->addDrawable(geom);


return geode;


}
_
Entérate de todas las noticias al instante ¡Suscríbete al servicio de Alertas 
MSN!
http://especiales.es.msn.com/noticias/msninforma.aspx___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org