What is an element? Primitive
To put it bluntly, it is a set of vertices. These vertices describe a three-dimensional graph. A model produced by 3D Max is actually a set of graphic elements, which are composed of related lighting, materials, and other attributes.
Generally, in d3d and OpenGL, elements are represented by two arrays (or buffer). One is vertex buffer and the other is index buffer ).
Vertex buffer: used to store the original data of vertex coordinates;
Index Buffer: used to store index numbers of vertices of each element. Index Numbers match vertex buffer.
Why is there a vertex array, but we can create another index array ?? This is mainly because many elements may overlap. In this case, if vertices are used for representation, it is a waste of space. However, the index array is clear and efficient. You know, it's very time-consuming to transfer large elements .... You can draw another 3D object by replacing the index array with ease, instead of updating a large fixed-point array at any time.
In d3d, how are elements drawn?
1 first, create the vertex and index Buffer:
Device-> createvertexbuffer ()
Device-> createindexbuffer ()
2. Set the drawing status:
Device-> setrenderstate ()
3. Set the data stream:
Device-> setstreamsource ()
4. Set the vertex format
Device-> setfvf () // the so-called fvf refers to the vertex format, which includes coordinates, materials, and textures.
5. SET index Buffering
Device-> setindices ()
6. Draw Elements
Device-> beginsceen ()
Device-> drawprimitive9 ()
Or
Device-> drqwindexedprimitive ()
Device-> endscene ()