I want to take very large screenshots from my application in OpenGL like 20000x20000 for printing on the banner. First of all, I am not able to create such big framebuffers because of the maximum GPU texture size limitation. Anyone can help me how to capture the framebuffer in different chunks?
1 Answers
As you already noted, capturing it in multiple passes is the way to go. In the simplest form, you can use multiple passes, each rendering a part of the scene.
To get the properr image sub-region, all you need to do is applying another transformation to the clip-space positions of your vertices. This boils down to simple translations and scalings in x
and y
:
When considering the euclidiean interpretation of the clip space - the normalized device space - the viewing volume is represented by a cube [-1,1] in all 3 dimensions.
To render only an axis-aligned sub-region of that cube, we have to upscale it so that only the sub-region fits into the [-1,1] area, and we have to translate it properly.
Assuming we want to divide the image into an uniform grid of m
times n
tiles, we could do the following transformations when rendering tile i
,j
:
Move the bottom left of the tile to the origin. That tile position will be at
(-1 + 2*i/m, -1 + 2*j/n)
, so we have to translate with the negated value:x' = x + 1 - 2*i/m
,y' = y + 1 - 2*j/n
This is only a helper step to make the final translation easier.
Scale by factors
m
andn
along x and y directions:x'' = m * x' = x * m + m - 2*i
,y'' = y' * n = y * n + n - 2*j
The tile is now aligned such that it's bottom left corner is (still) at the origin and the upper right center is at (2,2), so just translate it back with
(-1, -1)
so that we end up in the view voulme again:x''' = x'' - 1 = x * m + m - 2*i - 1
,y''' = y'' - 1 = y * n + n - 2*j - 1
This can of coure be represented as simple affine transformation matrix:
( m 0 0 m - 2*i - 1)
( 0 n 0 n - 2*j - 1)
( 0 0 1 0 )
( 0 0 0 1 )
In most cases, you can simply pre-multiply that matrix to the projection-matrix (or whatever matrices you use), and won't have to change anything else during rendering.

- 43,833
- 2
- 57
- 78