Setting the Render StateFastgraph's 3D polygon and 3D line drawing functions all have default render states that control the drawing. For example, fg_3Dpolygon() and fg_3Dpolygonobject() draw a single-color filled polygon by default, and fg_3Dtexturemap() and fg_3Dtexturemapobject() draw a texture-mapped polygon using linear (affine) texture mapping. The fg_3Drenderstate() function lets us change how the 3D polygon functions behave. It expects a single parameter specifying a combination of the flags shown here:
For example, to make fg_3Dtexturemap() and fg_3Dtexturemapobject() use perspective corrected texture mapping with z-buffering, we would specify:
C/C++:
Delphi:
Visual Basic:
We'll now discuss the meanings of each fg_3Drenderstate() flag in detail. The FG_WIREFRAME flag specifies if fg_3Dpolygon() and fg_3Dpolygonobject() draw filled or wire frame (unfilled) polygons. If FG_WIREFRAME is not specified, these functions draw filled polygons. The FG_LINEAR_TM and FG_PERSPECTIVE_TM flags are mutually exclusive and specify whether fg_3Dtexturemap() and fg_3Dtexturemapobject() use linear texture mapping or perspective texture mapping. Perspective texture mapping considers a polygon's 3D properties when applying a texture map, while linear texture mapping applies a texture map based solely on the projected 2D polygon. Linear texture mapping is faster, but perspective texture mapping produces a more visually appealing result. This is especially true for large polygons and polygons close to the viewer. If neither flag is specified, fg_3Dtexturemap() and fg_3Dtexturemapobject() use linear texture mapping. Technically, Fastgraph's perspective texture mapping function performs perspective corrected texture mapping. This means we interpolate the true (u,v) texture coordinates at a predefined horizontal pixel interval. Perspective corrected texture mapping differs from perspective correct texture mapping, where we perform this interpolation at every pixel. As you might guess, perspective corrected texture mapping is much faster than perspective correct texture mapping, with little or no perceived degradation in texture quality (and certainly better than linear texture mapping). The fg_tmspan() function defines the span size in pixels for perspective texture mapping. The span size is the pixel interval at which the perspective texture mapping functions calculate the true (u,v) texture coordinates when drawing horizontal polygon rows. Smaller span sizes result in texture mapping that is more perspectively correct, but larger span sizes are faster. The default span size of 32 pixels is a good choice for most textures. Note that calling fg_tmspan(1) results in perspective correct texture mapping. The FG_ZBUFFER flag specifies if we are using a z-buffer, which enables Fastgraph's 3D drawing functions to determine which parts of a 3D object should be visible. When using a z-buffer, the 3D drawing functions will draw a given pixel only if it is closer than any pixel drawn so far at that position in the current animation frame. This lets us accurately render a series of 3D polygons or 3D objects comprising a scene, regardless of the order in which we draw them. By default, Fastgraph's 3D drawing functions do not perform z-buffering. If we use the FG_ZBUFFER render state, we must create a z-buffer with fg_zballoc() and open it with fg_zbopen() before calling any of Fastgraph's 3D drawing functions. The FG_ZCLIP flag specifies if Fastgraph's 3D drawing functions perform 3D clipping against the clipping planes defined by fg_3Dsetzclip(). 3D clipping is required when displaying 3D objects that are completely or partially behind the POV. If FG_ZCLIP is not specified, Fastgraph's 3D drawing functions do not perform 3D clipping. In this case, your application is responsible for guaranteeing that all 3D objects lie in front of the POV.
|
 
copyright 2001 Ted Gruber Software, Inc.