< Zurück | Inhalt | Weiter >

9.7 PolygonAttributes








Table 9.5 Capability bits for the PolygonAttributes class





OpenGL Reference: glCullFace, glFrontFace, glPolygonMode

The PolygonAttributes class encapsulates properties for how polygons are rendered (table 9.5). Polygon rendering is controlled by the following properties:

Cull face: Determines which surfaces of the polygon are rendered. Either all surfaces or the backward−facing surfaces or the front−facing surfaces are rendered. Backward−facing surfaces are backward facing by virtue of the direction of their normal vector (calculated from the winding order of the vertices). That is, the vector normal to the surface is currently pointing away from the viewer.

Rendering mode: Renders either the polygon as a filled triangular surface or just the edges of the surface as lines or just the vertices of the surface as points.

Normal vector compensation: Flips the orientation of surface normal vectors. This mode is useful for

geometry that is defined using clockwise winding when counter−clockwise winding should be used for surface normal vector calculation.

Z−value offset: Shifts the geometry attached to the parent Appearance away from the eye (viewer) by the specified amount. By specifying an offset on one Shape3D it can be moved in front of or behind the other Shape3D. Because of differences in OpenGL/DirectX hardware implementation, however, it is very difficult to achieve consistent results using this method.

For example, to allow write access to the CULL_FACE property, use the following:

PolygonAttributes polyAttribs = new PolygonAttributes(); polyAttribs.setCapability(PolygonAttributes.ALLOW_CULL_FACE_WRITE );

Table 9.6 Cull face parameters




Cull face parameters (table 9.6) can be implemented as follows: polyAttribs.setCullFace( PolygonAttributes.CULL_BACK ); Table 9.7 Mode parameters




Polygon fill−mode parameters are shown in table 9.7. For example, to set line−only (wire frame) mode, use the following:

polyAttribs.setPolygonMode( PolygonAttributes.POLYGON_LINE );

Figures 9.12 through 9.15 illustrate how normal vector flipping can influence both the lighting calculations, (compare the shading of the horizontal faces in figure 9.12 with figure 9.13), and surface culling (figure 9.14, 9.15).


Figure 9.12 CULL_NONE, NORMAL_FLIP = false


Figure 9.13 CULL_NONE, NORMAL_FLIP = true


Figure 9.14 CULL_FRONT, NORMAL_FLIP = false


Figure 9.15 CULL_FRONT, NORMAL_FLIP = true