Hi Edu,
OpenGL calls including glReadPixels are all relative to 0,0 placed at
the lower left of the window, not 0,0 of the whole screen. By control
the window rectangle is relative to the whole screen.
Your glReadPixels should use the same values as the Camera's Viewport.
Robert.
On Nov 19, 2007 1:28 PM, Eduardo Gutiérrez Sanmartín
<[EMAIL PROTECTED]> wrote:
> Robert, Ralph,
>
> many thanks!
>
> Now I am taking screenshots correctly.
>
> I also had some problems getting the correct window position - I would like
> to comment the solution that I found, so it is
> in the same thread as the previous problem.
>
> I am using the following code - with the two methods that I am trying:
>
>
> class ScreenShotCallback: public osg::Camera::DrawCallback
> {
> private:
> osgViewer::Viewer::Windows _windows;
> osg::Image *_image;
>
> public:
> ScreenShotCallback(osgViewer::Viewer::Windows windows)
> {
> _windows = windows;
> _image = new osg::Image();
> }
> ~ScreenShotCallback() {};
>
> void operator() (const osg::Camera &camera) const
> {
> int x, y, width, height;
>
> // FIRST METHOD:
> _windows[0]->getWindowRectangle(x, y, width, height);
> std::cout << "\n Window: x, y: " << x << ", " << y << "\t width x
> height: " << width << " x " << height << std::endl;
>
> _image->readPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE);
> osgDB::writeImageFile(*_image, "capture1.bmp");
>
> // SECOND METHOD:
> x = (int) camera.getViewport ()->x(); y = (int)
> camera.getViewport()->y();
> width = (int) camera.getViewport()->width(); height = (int)
> camera.getViewport()->height();
> std::cout << "\n Viewport: x, y: " << x << ", " << y << "\t width x
> height: " << width << " x " << height << std::endl;
>
> _image->readPixels(x, y, width, height, GL_RGB, GL_UNSIGNED_BYTE);
> osgDB::writeImageFile(*_image, "capture2.bmp");
> }
> };
>
> int main(int argc, char** argv)
> {
> ...
>
> osgViewer::Viewer::Windows windows;
> viewer.getWindows(windows);
> viewer.getCamera()->setPostDrawCallback( new ScreenShotCallback(windows)
> );
>
> viewer.run();
> }
>
>
> There is one funny thing going on here. With
> _windows[0]->getWindowRectangle, all values printed in the console are
> right,
> but in the capture x and y are not correct. However, with
> camera.getViewport()->x()... the x and y values
> are always printed as zero, but the capture is correct. I have no idea about
> why this is happening, but at the end of the day, camera.getViewport() works
> fine! :)
>
> Thanks again,
>
> Edu
>
>
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org