Hi, all,
I want to use two cameras to composite result in the same window,
so two slave cameras are used with an projection offset .
However, there is a distortion, e.g, a ball looks like an ellipse.
And I find that osgViewer::Viewer::adSlave(.) doesn't work properly by
itself.
Here is simple example to demo this problem, it's obvious that a ball is
distorted.
==
#include osgViewer/Viewer
#include osgDB/ReadFile
#include osg/GraphicsContext
#include osg/Camera
#include osg/ShapeDrawable
#include iostream
osg::GraphicsContext* createGraphicsContext(int x, int y,
int width, int height ){
osg::ref_ptrosg::GraphicsContext::Traits traits =
new osg::GraphicsContext::Traits;
traits-x = x;
traits-y = y;
traits-width = width;
traits-height = height;
traits-windowDecoration = true;
traits-doubleBuffer = true;
traits-sharedContext = 0;
osg::ref_ptrosg::GraphicsContext gc =
osg::GraphicsContext::createGraphicsContext(traits.get());
if(gc.valid()){
gc-setClearColor(osg::Vec4(0.2f,0.2f,0.0f,1.0f));
gc-setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
return gc.release();
}
osg::Camera* setupCamera(osg::GraphicsContext* gc) {
int width,height;
width = gc-getTraits()-width;
height = gc-getTraits()-height;
GLenum buffer = gc-getTraits()-doubleBuffer ? GL_BACK : GL_FRONT;
osg::ref_ptrosg::Camera camera = new osg::Camera;
camera-setGraphicsContext(gc);
camera-setViewport(0,0,width,height);
camera-setDrawBuffer(buffer);
camera-setReadBuffer(buffer);
return camera.release();
}
osg::Node* createBall() {
osg::ref_ptrosg::ShapeDrawable drawable = new osg::ShapeDrawable;
drawable-setShape(new osg::Sphere(osg::Vec3f(0,0,0), 10));
osg::ref_ptrosg::Geode geode = new osg::Geode;
geode-addDrawable(drawable.get());
return geode.release();
}
int main(int argc, char* argv[]){
osgViewer::Viewer viewer;
viewer.addSlave(setupCamera(createGraphicsContext(0,0,800,600)));
//viewer.setCamera(setupCamera(createGraphicsContext(0,0,800,600)));
viewer.setSceneData(createBall());
viewer.run();
return 0;
}
===
So, where is the problem? And how to handle it?
Any advice will be appreciated.
--
Bob
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org