Rendering Scenes

  1. QuesaRenderer.h
  2. QuesaSet.h
  3. QuesaShader.h
  4. QuesaStyle.h
A 3D scene is rendered (i.e. drawn) into a TQ3ViewObject using the following steps:
  1. Call Q3View_StartRendering on the view to begin rendering
  2. Submit all the objects that comprise the scene
  3. Call Q3View_EndRendering, and if the result is kQ3ViewStatusRetraverse, go back to step 2
This loop (steps 2 and 3 above) is known as the submit loop, and is necessary because some renderers may need to make multiple passes over your objects for certain scenes (for example, translucent objects often have to be re-rendered after all the opaque objects for proper blending). Typically the renderer will only need one or two passes through the loop, but occasionally even more may be necessary.

(Submit loops are used in other contexts as well, such as when saving data to a file, computing a bounding box or sphere, or picking an object at a given location.)

The following example shows C++ code for rendering a scene. Variables such as mView, mObjects, and so on, are member variables defined elsewhere. Note that while the example shows the styles, background, shader, and objects as being separate, they could just as well be combined into a TQ3DisplayGroup and submitted at once.


Example: Rendering a scene

	if (Q3View_StartRendering( mView ) == kQ3Failure) return kQ3Failure;
	
	do {
		// submit styles (i.e., rendering preferences)
		Q3InterpolationStyle_Submit( mInterpolationStyle, mView );
		Q3BackfacingStyle_Submit( mBackfacingStyle, mView );
		Q3FillStyle_Submit( mFillStyle, mView );
		if (mUseFog) Q3FogStyle_Submit( &mFogStyleData, mView );
		
		// submit things we want to appear with no shading, e.g. the background
		Q3Object_Submit( mBackground, mView );

		// submit shader
		Q3Shader_Submit( mShader, mView );

		// submit scene
		Q3Object_Submit( mObjects, mView ) ;

		// repeat rendering loop while we need to retraverse
	} while (kQ3ViewStatusRetraverse == Q3View_EndRendering( mView ));

Renderer Objects

Transform Methods

To transform local coordinates to the canonical viewing frustum, and then to window coordinates, renderers must register for updates to Quesa's transformation matrices. Renderers should register for matrix updates rather than querying the view's camera, as this will also allow them to automatically support the camera transform object.

Several methods are available, however the most common usage is to watch for changes to either:

    kQ3XMethodTypeRendererUpdateMatrixLocalToFrustum

or:

    kQ3XMethodTypeRendererUpdateMatrixLocalToCamera
    kQ3XMethodTypeRendererUpdateMatrixCameraToFrustum

The second approach may be more useful if the underlying rendering API separates the transformation to camera space from the transformation which carries out the projection to the canonical frustum.

Style Objects

  1. kQ3StyleTypeBackfacing
  2. kQ3StyleTypeInterpolation
  3. kQ3StyleTypeFill
  4. kQ3StyleTypePickID
  5. kQ3StyleTypeReceiveshadows
  6. kQ3StyleTypeHighlight
  7. kQ3StyleTypeSubdivision
  8. kQ3StyleTypeOrientation
  9. kQ3StyleTypePickParts
  10. kQ3StyleTypeAntiAlias
  11. kQ3StyleTypeFog

Orientation Styles

Summary

The orientation style determines which side of a polygonal surface is considered to be "front facing". Both clockwise and counter-clockwise orientations are available.

The default orientation style for a view is kQ3OrientationStyleCounterClockwise, indicating that the front facing side of polygons are those whose vertices are listed in counter-clockwise order.

Behaviour

When a renderer performs backface culling, it must obtain or calculate a normal for each triangle in the scene. If no normal is supplied for a triangle, the current orientation style will determine which direction the calculated normal will point in.

If you supply triangle normals for the objects in your scene, you must ensure that the orientation style at the time they are submitted matches the orientation that those triangle normals were calculated under.

For example, the correct normal for a counter-clockwise triangle can be found with Q3Point3D_CrossProductTri. This calculates the normal as the cross product of the vectors from vertex 1 to vertex 2 and from vertex 2 to vertex 3. Since the normal for a clockwise triangle points in the opposite direction, this vector should be negated if the triangle is to be submitted under a clockwise orientation style.

Notes

The orientation style affects the following geometries:

The orientation style has no effect on the following geometries:

Quesa follows the documented behaviour for QD3D, where the orientation style should only effect explicitly polygonal geometries. This is contrary to QD3D's behaviour in four cases:

Quesa follows the documented behaviour for these four geometries.