Yansen
June 15th, 2004, 06:53 AM
Hi.
I need render OpenGL to off-screnn buffer and write them as BMP image into the disk. I need very large image (like 2500x2000), I know how to write to disk image that fit in to the screen but don't know how to do this which such a large image. Where to read about that problem ("feedback" will be good solutioin as I suspose....)????
wien
June 16th, 2004, 12:19 PM
Have a search for pixel-buffer-objects (PBO's). They let you render to an offscreen buffer. Not sure how rendering to a buffer larger than the screen resolution would work out though, but it might work.
Bornish
August 11th, 2004, 07:46 AM
There are lots of ways to do off-screen rendering with OpenGL, but most of them are not widely supported (render to texture,pBuffers,etc). If your application needs to run "almost" anywhere, try to keep the implementation to what's supported in version 1.1, and I think you can do it with no sweat.
Regarding the size of the image (has nothing to do with off-screen rendering or not), as long as you cannot set the viewport at any size (again, maximum is hardware dependent), whatever you render outside the viewport gets cliped and trying to copy from outside that rectangle will give you "garbage" video memory. Maximum size of the viewport can be queried by calling glGet with argument GL_MAX_VIEWPORT_DIMS.
My suggestion is to create a DC for which to set a pixel format that supports rendering to a bitmap (DIB). Then render portions of your image, saving each, one by one.
It's quite simple. Lets say you divide your image into 4 parts:
--------------------
| part1 | part3 |
--------------------
| part2 | part4 |
--------------------
Each part can have same viewport dimensions: 1250x1000.
Optimize the following "pseudocode" for your rendering:
GLdouble savedMatrix[16];
glGetDoublev(GL_PROJECTION_MATRIX,savedMatrix);
for (int part = 0;part < 4;part++)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glScaled(0.5,0.5,1.0);
glTranslated(0.5*pow(-1,part/2+1),0.5*pow(-1,part),0.0);
glMultMatrixd(savedMatrix);
//render your entire image or optimize for curent portion:
renderWholeScene(part);
//save the rendered pixels as you like; below is an example only:
glReadPixels(0,0,viewportDimX,viewportDimY,GL_COLOR,GL_UNSIGNED_BYTE,hMem);
}
glLoadMatrixd(savedMatrix);