Castle Game Engine: CastleBackground: Class TBackground

# Class TBackground
Description | Hierarchy | Fields | Methods | Properties
## 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 TObject TBackground ## Overview ### Fields
| `Transform: TMatrix4Single;`
### Methods
| `procedure Render;`
| `class function NearFarToSkySphereRadius(const zNear, zFar: Single; const Proposed: Single = 0): Single;`
| `constructor Create( GroundAngle: PArray_Single; GroundAngleCount: Integer; GroundColor: PArray_Vector3Single; GroundColorCount: Integer; const Imgs: TBackgroundTextures; SkyAngle: PArray_Single; SkyAngleCount: Integer; SkyColor: PArray_Vector3Single; SkyColorCount: Integer; SkySphereRadius: Single);`
| `destructor Destroy; override;`
## Description ### Fields
| `Transform: TMatrix4Single;`
### 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.
| `constructor Create( GroundAngle: PArray_Single; GroundAngleCount: Integer; GroundColor: PArray_Vector3Single; GroundColorCount: Integer; const Imgs: TBackgroundTextures; SkyAngle: PArray_Single; SkyAngleCount: Integer; SkyColor: PArray_Vector3Single; SkyColorCount: Integer; SkySphereRadius: Single);`
Construct background. Prepares OpenGL resources for rendering. Parameters correspond to VRML/X3D Background node, see [http://web3d.org/x3d/specifications/ISO-IEC-19775-1.2-X3D-AbstractSpecification/Part01/components/enveffects.html#Background]. For example SkyColorCount > 0 and GroundColorCount > GroundAngleCount. Any of the TBackgroundTextures passed here may be `Nil`, or of a class that can be rendered as OpenGL textures (TextureImageClasses).
| `destructor Destroy; override;`
Generated by PasDoc 0.13.0 on 2013-08-17 21:27:12