Hi Ricky,

You are doing two things that are very expensive - reading back from
GPU and writing to disk.  You can help lower the cost of GPU read by
using double buffer of PBO, and the cost of writng to disk by using a
separate thread.  Both topics aren't straight forward and pretty
advanced topics.  Go read the osg-users archives for guidance on these
topics.

Robert.

On Mon, Jun 21, 2010 at 8:21 AM, Ricky Flintoff <rickyflint...@gmail.com> wrote:
> Hi,
>
> As a solution, I decided to change the viewpoint of the camera and then take 
> pictures as I change the viewpoint. However, with the code I have, it's 
> really slow (cow rotates very slowly) Any suggestions or ways I can over come 
> this problem?
>
>
> Code:
>
> //capture an image of the scenegraph
> class CCameraPostDrawCallback: public osg::Camera::DrawCallback {
> public:
>    CCameraPostDrawCallback(const int cX, const int cY, const int w,
>            const int h, const std::string str) {
>        centerX = cX;
>        centerY = cY;
>        width = w;
>        height = h;
>        fileName = str;
>    }
>
>    void operator () (const osg::Camera& cam) const {
>        //take a picture of the scene
>        osg::ref_ptr<osg::Image> screenShot = new osg::Image;
>        screenShot->readPixels(centerX, centerY, width, height, GL_RGB, 
> GL_UNSIGNED_BYTE);
>        osgDB::writeImageFile(*screenShot, fileName);
>    }
> private:
>    int centerX;
>    int centerY;
>    int width;
>    int height;
>    std::string fileName;
> };
>
> osg::Node* CreateScene() { //add rendering modifications
>    //load the osg model
>    osg::Node* loadedModel = osgDB::readNodeFile("cow.osg");
>    return loadedModel;
> }
>
> int main(int argc, char *argv[]) {
>    osgViewer::Viewer viewer;
>    viewer.setSceneData(CreateScene());
>    viewer.getCamera()->setProjectionMatrixAsPerspective(60., 1., 1., 100. );
>    viewer.setUpViewInWindow(0, 0, 500, 500);
>
>    //create a matrix to specify a distance from the viewpoint.
>    osg::Matrix trans;
>    trans.makeTranslate(0., 0., -12.);
>
>    //Rotation angle (in radians)
>    double angle(0.);
>    while (!viewer.done()) {
>        viewer.getCamera()->setPostDrawCallback(new CCameraPostDrawCallback(0, 
> 0, 500, 500, "screenshot.jpg"));
>
>        //Create the rotation matrix.
>        osg::Matrix rot;
>        rot.makeRotate(angle, osg::Vec3(1, 0., 0.));
>        angle += 0.01;
>        viewer.getCamera()->setViewMatrix(rot * trans);
>        viewer.frame();
>    }
> }
>
>
>
>
>
> Thank you!
>
> Cheers,
> Ricky
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=29188#29188
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to