Jump to content


writing image files in OpenSceneGraph


1 reply to this topic

#1 James Monroe

    New Member

  • Members
  • Pip
  • 2 posts

Posted 11 August 2007 - 06:04 PM

I am somewhat new to the computer graphics field, and I am trying to familiarize myself with the basics of OpenGL and OpenSceneGraph. I have a simple OSG application that can render an STL file and allow the user to freely rotate the rendered object. This needs to be extended with a screenshot capability. So far I have tried using the osgDB::writeImageFile function, but this function always returns false (but does not give me an error message). I've tried the OSG documentation, what little there is, to no avail. Does anyone have experience with OSG, and feel like trying to help me?

#2 James Monroe

    New Member

  • Members
  • Pip
  • 2 posts

Posted 11 August 2007 - 06:38 PM

I suppose I should include my code, as well:

osg::ref_ptr<osg::Viewport> viewport = new osg::Viewport;


viewport->setViewport(0,0,800,600);
std::string filename("screenshot.bmp");

glReadBuffer(GL_FRONT);
osg::ref_ptr<osg::Image> image = new osg::Image;
image->readPixels(viewport->x(),viewport->y(),viewport->width(),viewport->height(),
GL_BITMAP,GL_UNSIGNED_BYTE);

if (osgDB::writeImageFile(*image,filename))
osg::notify(osg::NOTICE) << "Saved screen image to `"<<filename<<"`"<< std::endl;
else
TRACE("Failed to write image.\n");





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users