For high-quality prints you need high-quality screenshots. This means very high resolution, and nice anti-aliasing. Just grabbing the screen produces rather unpleasant results (screenshot, 80 KB, 800x600 pixels). With normal OpenGL rendering you get rarely more than screen resolution, and anti-aliasing quality very much depends on your graphics board. So what to do?
Tiled Rendering comes to the rescue. Instead of rendering the whole image at once, we render smaller portions of the scene, and then arrange the tiles into a large picture. However, just pointing the camera at each tile will not work as intended, the perspective would change from tile to tile. What is needed instead is to construct partial viewing frustums that together exactly recreate the whole frustum. This sounds like a lot of math, but actually it is quite simple:
gluPerspective: fov aspect: aspect zNear: near zFar: far tile: rect
| cotangent radians w h |
radians := (fov/2.0) degreesToRadians.
cotangent := radians cos / radians sin.
h := near / cotangent.
w := h * aspect.
self glFrustum(rect left*w, rect right*w, rect bottom*h, rect top*h, near, far).
So I just extended the existing gluPerspective:aspect:zNear:zFar: method with a tile argument that gives the sub-rectangle in the viewing plane, where the whole picture ranges from -1 to 1. The only problem is to hand down that extra argument into the method. I ended up copying all the methods in the call chain, adding a tile: parameter. With the methods in place and a utility method to construct the right sub-rectangles, I could render the image from the first screenshot again:
| m c f | m := CroquetGlobals theTeapotMorph. c := m activeCamera. f := c root snapShot: m ogl camera: c tiled: 12. f := f magnify: f boundingBox by: 0.5 smoothing: 4. JPEGReadWriter2 putForm: f quality: 90 progressiveJPEG: false onFileNamed: 'croquet-bf-4800.jpg'.Instead of 800x600, this renders 12x12 tiles, creating a 9600x7200 pixels image. The result is scaled down with smoothing to yield an anti-aliased 4800x3600 image, finally compressing as JPEG gives a 1.5 MB hires screenshot. Beauty, eh? Never noticed that guy on the bridge before ;-)
Comments
I'd love to be able to take hi-res shots.
TSpace snapShot:camera:tile: for each rectangle. Then it goes down like this:
TSpace doRender:camera:tile:
TCamera initFrustum:tile:
OpenGL initFrustum:bounds:zNear:zFar:tile:
OpenGL gluPerspective:aspect:zNear:zFar:tile:
And because that is so ugly and boring I didn't want to post it. The only slightly interesting part is the construction of the sub rectangles from the integer tiles parameter:
ext := (2.0@2.0) / tiles.
0 to: tiles - 1 do: [ :x |
0 to: tiles - 1 do: [ :y |
pos := (x@y) * ext - (1.0@1.0).
snapshot := self snapShot: ogl camera: cam tile: (pos * (1@-1) extent: ext * (1@-1)).
...]].
Hope that helps?
Many thanks.
Many thanks.