Class TBackground
Unit
CastleBackground
Declaration
type TBackground = class(TObject)
Description
Background rendering sky, ground and such around the camera. Background defined here has the same features as VRML/X3D Background:
a cube with each face textured (textures may have alpha channel)
a ground sphere around this, with color rings for ground colors
a sky sphere around this, with color rings for sky colors
See [http://web3d.org/x3d/specifications/ISO-IEC-19775-1.2-X3D-AbstractSpecification/Part01/components/enveffects.html#Background] for the detailed meaning of constructor parameters.
Conceptually, the background is infinitely far from the camera, regardless of the camera position. So actually, we just ignore camera position, and render like the camera was always in the middle of the background box/sphere. But still we take into acccount camera rotations. This makes convincing sky look.
Hierarchy
Overview
Fields
Methods
Description
Fields
Methods
 |
procedure Render; |
Render background around.
Current modelview matrix should contain only the camera rotation. Uses one OpenGL attrib stack place. Automatically creates and uses a display list. Assumes that the user is standing in the middle of background, so we can use backface culling.
We render without GL_DEPTH_TEST to cover everyhing on the screen (so rendering a background should be a first thing you render, no point in even doing glClear yourself). When possible (we have only one sky color), we even use glClear(GL_COLOR_BUFFER) to set initial color.
|
 |
class function NearFarToSkySphereRadius(const zNear, zFar: Single; const Proposed: Single = 0): Single; |
Calculate (or just confirm that Proposed value is still OK) the sky sphere radius that fits nicely in your projection near/far.
Background spheres (for sky and ground) are rendered at given radius. And inside these spheres, we have a cube (to apply background textures). Both spheres and cube must fit nicely within your projection near/far to avoid any artifacts.
We first check is Proposed a good result value (it satisfies the conditions, with some safety margin). If yes, then we return exactly the Proposed value. Otherwise, we calculate new value as an average in our range. This way, if you already had sky sphere radius calculated (and prepared some OpenGL resources for it), and projection near/far changes very slightly (e.g. because bounding box slightly changed), then you don't have to recreate background — if the old sky sphere radius is still OK, then the old background resources are still OK.
Just pass Proposed = 0 (or anything else that is always outside the range) if you don't need this feature.
|
 |
destructor Destroy; override; |
|
Generated by PasDoc 0.12.1 on 2013-02-04 20:26:49
|