[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.9.3 Render Priorities and Objects in Sectors

Renderpriorities give the map creator some extra control over when objects have to be rendered. In this section the basic rendering algorithm is explained. This is a more theoretical explanation. Later some examples are given of some commonly used configurations.

Meshes and Sectors

One of the most fundamental concepts in Crystal Space is a sector (interface iSector). A sector is basically empty space which needs to be filled with geometry.

To put geometry in a sector you use one or more mesh objects (see section Mesh Object Plug-In System). Note that a mesh object can also be in several sectors at once. This happens when some object is busy traversing some portal from one sector to another. The list of sectors that a mesh object is in and also the position (i.e. transform) is kept by an instance of iMovable (see section Mesh Movement).

Render Priorities

The engine supports the notion of render priorities. There is usually a limited set of render priority slots available. By default these are:

  1. `init'
  2. `sky'
  3. `sky2'
  4. `portal'
  5. `wall'
  6. `wall2'
  7. `object'
  8. `object2'
  9. `transp'
  10. `alpha'
  11. `final'

But you can setup your own render priorities by calling the engine API. Objects which are in a lower render priority (i.e. `sky' is lower than `wall') will be rendered before objects with a higher priority. So using the render priority system you can choose in which order to render objects.

The `alpha' render priority is a bit special. Objects in that render priority will be rendered from back to front. This is needed for objects that use alpha transparency and also if you need a mix of different kinds of transparencies. If you use a single other kind of transparency like add or mult (but not both) then you can use the `transp' render priority. That one is not sorted from back to front so it is only usable for transparencies that are correct even if rendered in other order.

For keycolor objects (see section Alpha and Keycolor in Textures) you can use the normal `object' render priority with `ZUSE' z-buffer mode. This is also true for objects that have textures using binary alpha.

To set up render priorities from within your application you can use the engine->RegisterRenderPriority() function.

To set the render priority for an object you can use the following in a map file:

 
<meshobj name="myObject">
  <plugin>...</plugin>
  <params>
    ...
  </params>
  <priority>object</priority>
</meshobj>

To set the render priority from within the code you can do:

 
iMeshWrapper* mesh;
mesh->SetRenderPriority (engine->GetRenderPriority ("object"));

By default objects will be put in the `object' render queue.

Z-Buffer Render Mode

In addition to render priorities you can also choose how the object will be rendered with regards to the Z-buffer. There are four possibilities:

To set the Z-buffer mode from a map file you can do the following:

 
<meshobj name="myObject">
  <plugin>...</plugin>
  <params>
    ...
  </params>
  <priority>object</priority>
  <zuse />
</meshobj>

To set the Z-buffer mode from the code you can use the following example:

 
  iMeshWrapper* mesh;
  mesh->SetZBufMode (CS_ZBUF_USE);

`ZUSE' is the default Z-buffer mode for objects created from within an application.

By using the z-buffer mode in combination with the render priorities we now have a very powerful system to control object rendering in a sector. In the following sections we will show some popular examples. But first we show in a table what the common usage is of the render priorities in combination with the Z-buffer modes:

Note that sky objects are usually created with the `CAMERA' keyword (in map file) or the CS_ENTITY_CAMERA flag (in iMeshWrapper::GetFlags()). The camera keyword makes sure that the camera will always be in the center of that object. So you can move forever in some direction without ever reaching the bounds of the sky.

Include Files

The include files useful for this section are:

 
#include <iengine/mesh.h>
#include <iengine/sector.h>
#include <iengine/engine.h>
#include <ivideo/graph3d.h>

[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated using texi2html 1.76.