X3DTK::GL::IndexedFaceSet
. GL nodes inherit the scene graph API of which description can be found here.
The GL scene graph is designed to be integrated in a viewer, because of the optimized version of the GL nodes, the interface is not easy to use. It is commonly used in the X3DTK::GL::Renderer
processor.
X3DTK::SimpleX3DGLScene
class which encapsulates basic operations. Check the X3DViewer example for more details.X3DTK::X3D::GLBuilder
. // scene is an X3D scene previously loaded X3DTK::GL::Scene *glscene = X3DTK::Singleton<X3DTK::X3D::GLBuilder>::getInstance()->build(scene);
X3DTK::GL::IndexedFaceSet
which inherits X3DTK::GL::X3DComposedGeometryNode
. We present here the two nodes, the other nodes are less important.There are other attributes that you can find in the description of the node.X3DTK::GL::X3DComposedGeometryNode *N; // Returns the GL format of the vertices. GLenum format = N->getVertexFormat();
Access to the vertex arrays is made:
The faces are indexed enabling the share of vertices. Faces are defined by three vertices. For this reason, the coordinate index array in theX3DTK::GL::IndexedFaceSet *I; // Getting the vertex array if (I->getVertexFormat() == GL_T2F_N3F_V3F) std::vector<T2F_N3F_V3F> &array = I->T2F_N3F_V3F_vertexArray(); // Getting the index array MFInt32 &indexArray = I->indexArray(); // Getting the X3DToGLIndex const std::vector<MFInt32> &x3dglindex = I->getX3DToGLIndex();
X3DTK::X3D::IndexedFaceSet
is different from this one. Nevertheless only some vertices are duplicated in the X3DTK::GL::IndexedFaceSet
node. That is why we can find the relation with the X3DToGLIndex. fig 1 : For one X3D index, there are several GL indexes.
For more details about how to use the X3DTK::GL::IndexedFaceSet
node, you can check the glNormalViewer and simpleAnimationViewer examples.
setX3DReference
and getX3DReference
define the link with the related X3D node. The update
method is used to update the attributes of the node. Here is an example: namespace X3DTK { namespace GL { void Box::update() { if (getX3DReference() == 0) return; X3D::Box *B = static_cast<X3D::Box *>(getX3DReference()); _size = B->getSize(); _boxArray = BoxDrawArray::getInstance(); } } }
namespace X3DTK { namespace GL { void Box::draw() const { glEnable(GL_CULL_FACE); glFrontFace(GL_CW); glCullFace(GL_BACK); glPushMatrix(); glScalef(_size.x, _size.y, _size.z); glInterleavedArrays(GL_N3F_V3F, 0, _boxArray->getBoxVertexArrayAddress()); glDrawElements(GL_TRIANGLES, _boxArray->getBoxSize(), GL_UNSIGNED_INT, _boxArray->getBoxIndexArrayAddress()); glPopMatrix(); glDisable(GL_CULL_FACE); } } }