Hi, Thank you for this quick answer. I found two ways to do what I wanted : -by adding the following line before the rendering loop ( while(!viewer->done())...): viewer->getCamera()->attach(osg::Camera::COLOR_BUFFER, image); So image is filled by a thread which has the graphics context current Then the image is stored after the command viewer->frame() by using the function osgDB::writeImageFile(...).
-by using the method setPostDrawCallback which is necessary if we want to modify the rendered image before the storage. Thanks a lot. Jean-Baptiste 2008/4/1, Robert Osfield <[EMAIL PROTECTED]>: > > Hi Jean-Baptiste, > > The most likely cause of the OpenGL error is that your code that is > calling glReadPixels doesn't have the graphics context current. You > have to call OpenGL from the thread that has the graphics context > current. The easist way to do his is to attach a Camera post draw > callback, this will be called from the appropriate graphics threads. > If you are using 2.3.x or SVN then use Camera final draw calback as > it's called later in the draw pipeline. > > Robert. > > > On Tue, Apr 1, 2008 at 6:47 PM, Jean-Baptiste Authesserre > <[EMAIL PROTECTED]> wrote: > > Hi everyone, > > > > I am trying to get screenshots of a generated scene with OSG. In order > to do > > that I am using the method readPixels of the class osg::image. But it > seems > > that the function glReadPixels used by readPixels fails. Here is a part > of > > the code: > > > > //start the rendering > > float * depthBufferRaw; > > osg::Image * depthBuffer= new osg::Image(); > > unsigned char * tmp; > > > > int height=1280; > > int width=1024; > > int i; > > depthBufferRaw = (float *) calloc(height*width, sizeof(float)); > > > > > > while(!viewer->done()) > > { > > > > viewer->frame(); > > > > //Get values of the color buffer > > depthBuffer->readPixels(0,0,width,height, > > GL_LUMINANCE,GL_UNSIGNED_BYTE); > > > > tmp = depthBuffer->data(); > > for (i=0; i<height*width; i++) > > depthBufferRaw[i]=(float) tmp[i]; > > > > //save as image > > ... > > > > > > } > > > > With the above code, i get an array (depthBufferRaw) with constant > values > > whereas i see on my screen a scene with different objects and colors. > Thanks > > to debug mode of VS2003, i can verify that depthBuffer->_data has been > > allocated. > > > > The source code of the osg::image method readPixels is the following: > > > > void Image::readPixels(int x,int y,int width,int height,GLenum > format,GLenum > > type) > > { > > allocateImage(width,height,1,format,type); > > > > glPixelStorei(GL_PACK_ALIGNMENT,_packing); > > > > glReadPixels(x,y,width,height,format,type,_data); > > } > > > > So, it seems that glReadPixels failed. I tried to show this by using > > directly glReadPixels in my implementation with glGetError. > > Strangely glGetError returns the value 1282 (GL_INVALID_OPERATION) > > whatever the position of the call to this function in my code. And when > i > > tried to use this function in a loop as : > > while (errCode != GL_NO_ERROR) > > errCode = glGetError(); > > > > I obtain an infinite loop. > > > > My questions are the following: > > -Is that possible to use glGetError with OSG? > > -Has anybody an idea of why the method readPixels fails in this case? > > > > Thanks in advance! > > > > Jean-Baptiste > > > _______________________________________________ > > 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 >
_______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org