[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
GL3.2 Version 4.1 for AIX: Programming Concepts

Control of Z Values

When coordinate data is transformed to screen coordinates by the graphics pipeline, the transformation is done in two steps. First, the data is multiplied by a transformation matrix that transforms all visible vertices so that they lie in the 3-D cube -1.0 <= x, y, z <= 1.0. The clipping hardware eliminates all data outside this cube. The second stage of the transformation scales the coordinate values (now transformed to lie between -1.0 and 1.0) to screen coordinates.

The x and y coordinates undergo scaling to the viewport coordinates before they are drawn, and the z coordinates undergo the same transformation. The x, y scaling is controlled by the viewport subroutine, and the z scaling by the lsetdepth subroutine.

In the default mode with z-buffering turned off, the scaled z coordinates are ignored, and the drawing depends only on the x and y coordinates. When z-buffering is turned on, the z values are compared to determine whether to draw each pixel. The z values for these comparisons are based on the scaled z values.

Note: The preferred programming practice to determine the minimum and maximum z values that a given hardware platform supports is to use the getgdesc subroutine with the GD_ZMIN and GD_ZMAX tokens.

lsetdepth Subroutine

The lsetdepth subroutine controls the scaling of the z coordinates, just as the viewport subroutine controls the scaling of the x and y coordinates. The lsetdepth subroutine takes two parameters of type Int32, corresponding to the near and far planes. By default, the near parameter is set to the minimum value that can be stored in the z-buffer and the far parameter is set to the maximum value. The minimum value is -0x800000, the maximum value is +0x7fffff, the largest and smallest values that can be written into a 24-bit z-buffer. The syntax is as follows:

void lsetdepth(Int32 near, Int32 far)

czclear Subroutine

A very common code sequence in programs that do z-buffering is the following:

color(0);
clear();
zclear();

This sequence clears the color bitplanes to zero and clears the z-buffer bitplanes to the maximum value. Execution of the sequence takes time because the clear subroutine touches each pixel, and then the zclear subroutine touches each pixel. Some hardware implementations can, in certain cases, simultaneously clear the color planes and the z-buffer planes. The czclear subroutine allows you to do this.

The czclear subroutine clears the bitplanes to color and the z-buffer to the value of the zval parameter simultaneously. This subroutine is available only in immediate mode.

To speed up the czclear subroutine by as much as a factor of four for common values of the zval parameter, call the zfunction subroutine in conjunction with it. One of the following conditions must be met:

Conditions
zval zfunction
-0x800000 ZF_GREATER or ZF_GEQUAL
+0x7FFFFF ZF_LESS or ZF_LEQUAL

The syntax is as follows:

void czclear(Int32 cval, Int32 zval)

[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]