9 Rendering
9.1 Rendering Optimization
Returns a
Pict3D with identical shapes and lights, which, when first rendered, is optimized
for streaming to the graphics card.
Nonempty groups are
ungrouped.
Empty groups are retained.
The optimization takes more time than rendering the original pict, so use freeze to
optimize unchanging, frequently drawn sub-scenes.
For static scenes with tens of thousands of shapes, order-of-magnitude speedups are typical.
The results of transformations, and of combiners such as combine and pin, which do
not alter shapes or their attributes, retain the optimized streaming data.
The results of attribute-altering functions such as set-color do not.
9.2 Rendering Parameters
The parameters in this section are read when a
Pict3D is
displayed, not when it’s
created.
In other words, don’t expect this to result in a 512x512 display:
By the time the sphere is displayed, the parameters have returned to their original values.
This is correct behavior.
A Pict3D represents the contents of 3D space, which has nothing to do with how those
contents are viewed.
For the parameters to have an effect on interactive displays, they should be mutated:
See the set-pict3d method of pict3d-canvas%, and
pict3d->bitmap,
for how these parameters are used when rendering on a canvas or to a bitmap.
Determine whether directional lights, indicators, the grid, and wireframes are initially added to
interactive
Pict3D displays.
See
Quick Start.
The width and height of new interactive
Pict3D displays, and the default size arguments to
pict3d->bitmap.
The color of a rendered
Pict3D wherever shapes aren’t drawn.
While pict3d-canvas% respects this parameter, be aware that it draws Pict3D
instances over a black background.
The alpha component of background thus only appears to darken the background color.
It’s not generally possible to combine lighting effects with a non-default background in a plausible
way.
Light should always brighten, never darken, but the rendering engine is doing as well as it can.
In fact, the rendering is correct when the image is alpha-composited over a black background.
The color and intensity of ambient light.
Generally, prefer to use other forms of lighting such as
light and
sunlight for
illumination.
Too much ambient light easily “washes out” or “flattens” a scene.
Use it subtly, for mood, or to suggest environment such as indoor or outdoor.
The minimum field of view, in degrees.
The effects are best understood by flying around in an interactive display.
The distance to the near and far view clipping planes.
The defaults are sufficient for nearly every use, allowing both microscopic and planetary scales, and
are orders of magnitude smaller and larger than most 3D engines allow.
The only feasible reason to change these is to set the far plane as a speed optimization.
(Pict3D’s rendering engine won’t process anything for drawing that it can prove is outside the
view frustum.)
Determines the value sent to the
set-legacy? method of
gl-config% when
creating an OpenGL rendering context.
In general, you should only try setting (current-pict3d-legacy? #t) if you’re getting
strange OpenGL errors.
On Mac OS X, this parameter must be #f.
If #t, only OpenGL 2.1 is available.
If #f, OpenGL 3.2 or higher is available.
Pict3D requires at least OpenGL 3.0.
On Linux, this parameter may be (or may have to be) either #t or #f, depending on
the graphics driver.
On Windows, this parameter is currently ignored.
Determines whether Pict3D checks the OpenGL version.
When current-pict3d-check-version? is #t, Pict3D raises an error when the OpenGL
version is less than 3.0.
Otherwise, it doesn’t check, and counts on hardware and drivers implementing equivalent extensions.
Use this at your own risk.
Pict3D will work on standards-compliant implementations of OpenGL 3.0 or higher, but there is
no such guarantee for lower versions, even when they implement all the required extensions.
Further, if Pict3D works on a lower version, don’t expect it to keep doing so.
In the future, Pict3D might use a 3.0 feature that your hardware or driver doesn’t implement an
extension for.
If Pict3D doesn’t work when current-pict3d-check-version? is #f, it may raise
errors, render garbage, or cause segfaults.
Currently, Mesa 3D’s software rendering implements all the
required extensions.
On Linux, if your graphics driver uses Mesa’s infrastructure, you can use its software renderer by
starting DrRacket with
LIBGL_ALWAYS_SOFTWARE=TRUE <racket-binary-path>/drracket
and putting (current-pict3d-check-version? #f) at the top of your programs.
Nontrivial rendering parameter default values.
9.3 Rendering Targets
Extra directional lights and indicators added to interactive displays are not drawn.
See Quick Start.
Instances of pict3d-canvas% have type (Instance Pict3D-Canvas%).
Instances represent a window whose purpose is to render
Pict3D instances in an OpenGL
context.
Rendering on a
pict3d-canvas% is faster than rendering a bitmap using
pict3d->bitmap and drawing the bitmap on a
canvas%.
One of the smallest interesting programs that uses
pict3d-canvas% is this:
In Typed Racket, remember to use
(require typed/racket/gui) instead of
(require racket/gui).
To animate a canvas, simply use
set-pict3d to change the rendered
Pict3D.
Or use
big-bang3d, which is intended for games and animations.