| 122 | | Declare the variable that will match vertex array elements to color array elements. This vector should have the same number of elements as the number of vertices. This vector serves as a link between vertex arrays and color arrays. Entries in this index array correspond to elements in the vertex array. Their values correspond to the index in the color array. This same scheme would be followed if vertex array elements were matched with normal or texture coordinate arrays.[[BR]] |
| 123 | | Note that in this case, we are assigning 5 vertices to four colors. Vertex array element zero (bottom left) and four (peak) are both assigned to color array element zero (red). |
| 124 | | |
| 125 | | {{{ |
| 126 | | osg::TemplateIndexArray |
| 127 | | <unsigned int, osg::Array::UIntArrayType,4,4> *colorIndexArray; |
| 128 | | colorIndexArray = |
| 129 | | new osg::TemplateIndexArray<unsigned int, osg::Array::UIntArrayType,4,4>; |
| 130 | | colorIndexArray->push_back(0); // vertex 0 assigned color array element 0 |
| 131 | | colorIndexArray->push_back(1); // vertex 1 assigned color array element 1 |
| 132 | | colorIndexArray->push_back(2); // vertex 2 assigned color array element 2 |
| 133 | | colorIndexArray->push_back(3); // vertex 3 assigned color array element 3 |
| 134 | | colorIndexArray->push_back(0); // vertex 4 assigned color array element 0 |
| 135 | | }}} |
| 136 | | |
| 137 | | The next step is to associate the array of colors with the geometry, assign the color indices created above to the geometry and set the binding mode to _PER_VERTEX. |
| | 123 | Declare the variable that will match vertex array elements to color array elements. This vector should have the same number of elements as the number of vertices. This vector serves as a link between vertex arrays and color arrays. The next step is to associate the array of colors with the geometr and set the binding mode to BIND_PER_VERTEX. |
| 143 | | |
| 144 | | osg::Vec2Array* texcoords = new osg::Vec2Array(5); |
| 145 | | (*texcoords)[0].set(0.00f,0.0f); |
| 146 | | (*texcoords)[1].set(0.25f,0.0f); |
| 147 | | (*texcoords)[2].set(0.50f,0.0f); |
| 148 | | (*texcoords)[3].set(0.75f,0.0f); |
| 149 | | (*texcoords)[4].set(0.50f,1.0f); |
| 150 | | pyramidGeometry->setTexCoordArray(0,texcoords); |