OpenSceneGraph 3.0: Beginner's Guide
上QQ阅读APP看书,第一时间看更新

Vertices and vertex attributes

The Vertex is the atomic element of geometry primitives. It uses several numeric attributes to describe a point in 2D or 3D spaces, including vertex position, color, normal and texture coordinates, fog coordinate, and so on. The position value is always required, and other attributes will help to define the nature of the point. OpenGL accepts up to 16 generic attributes to be specified per vertex, and can create different arrays in which to store each of them. All attribute arrays are supported by the osg::Geometry class with the corresponding set*Array() methods.

A table of built-in vertex attributes in OpenGL is listed below:

A vertex usually contains eight texture coordinates and three general attributes in current OpenGL graphics systems. In principle, each vertex should set all of its attributes to certain values, and form a set of arrays with exactly the same size; otherwise the undefined ones may cause unexpected problems. OSG provides binding methods to make the work more convenient. For instance, developers may call the public method setColorBinding() of an osg::Geometry object geom, and take an enumerate as the parameter:

geom->setColorBinding( osg::Geometry::BIND_PER_VERTEX );

This indicates that the color and the vertex are put into a one-to-one relationship. However, see the following code:

geom->setColorBinding( osg::Geometry::BIND_OVERALL );

It will apply a single color value to the entire geometry. There are setNormalBinding(), setSecondaryColorBinding(), setFogCoordBinding(), and setVertexAttribBinding(), which do the similar work for other attribute types.