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
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to