# Creating the GeomPrimitive objects¶

Now that you have a GeomVertexData with a set of vertices, you can create one or more GeomPrimitive objects that use the vertices in your GeomVertexData.

In general, you do this by first creating a GeomPrimitive of the appropriate type, and then calling addVertex() for each vertex in your primitive, followed by closePrimitive() after each primitive is complete.

Different GeomPrimitive types have different requirements for the number of vertices per primitive. Some always have a fixed amount of vertices, like GeomTriangles, GeomLines and GeomPoints. You should simply add all of the vertices for these primitives. Some people call close_primitive after adding every primitive, but this is not strictly necessary. Other GeomPrimitive types have a variable number of vertices, like GeomTristrips, GeomTrifans and GeomLinestrips. Because you need to tell Panda3D how many vertices are in every primitive, you should call close_primitive() after adding every primitive.

For example:

// In order for this to work you need to have included "geomTriangles.h"

PT(GeomTriangles) prim;
prim = new GeomTriangles(Geom::UH_static);

// thats the first triangle

// you can also add a few at once



Note that the GeomPrimitive constructor requires one parameter, which is a usage hint, similar to the usage hint required for the GeomVertexData constructor. Like that usage hint, this tells Panda whether you will frequently adjust the vertex indices on this primitive after it has been created. Since it is very unusual to adjust the vertex indices on a primitive (usually, if you intend to animate the vertices, you would operate on the vertices, not these indices), this is almost always Geom.UH_static, even if the primitive is associated with a dynamic GeomVertexData. However, there may be special rendering effects in which you actually do manipulate this vertex index table in-place every few frames, in which case you should use Geom.UHDynamic. As with the GeomVertexData, this is only a performance hint; you’re not required to adhere to the usage you specify.

If you are unsure about this parameter, you should use Geom.UH_static.

The above sample code defines a GeomTriangles object that looks like this:

 0 1 2 2 1 3 0 5 6

The actual positions of the vertices depends on the values of the vertices numbered 0, 1, 2, 3, and 5 in the associated GeomVertexData (you will associate your GeomPrimitives with a GeomVertexData in the next step, when you attach the GeomPrimitives to a Geom).

Finally, there are a few handy shortcuts for adding multiple vertices at once:

# Add 2, 3, or 4 vertices in a single call.

None of the above shortcut methods calls close_primitive() for you; it is still your responsibility to call close_primitive() each time you add the appropriate number of vertices to a primitive that requires it.