Share via


CustomVertex Class (Microsoft.DirectX.Direct3D)

How Do I...?

  • Create a Mesh Object
  • Generate a Scene

Defines various custom fixed-format vertex types. This class is a container of structures. See the individual structures for more information.

Definition

Visual Basic NotInheritable Public Class CustomVertex
    Inherits ObjectLeave Site
C# public sealed class CustomVertex : ObjectLeave Site
C++ public ref class CustomVertex sealed : ObjectLeave Site
JScript public final class CustomVertex extends ObjectLeave Site

Members Table

The following table lists the members exposed by the object.

Structures

Structure Description
CustomVertex.PositionColored Describes a custom vertex format structure that contains position and color information.
CustomVertex.PositionColoredTextured Describes a custom vertex format structure that contains position, color, and one set of texture coordinates.
CustomVertex.PositionNormal Describes a custom vertex format structure that contains position and normal data.
CustomVertex.PositionNormalColored Describes a custom vertex format structure that contains position, color, and normal data.
CustomVertex.PositionNormalTextured Describes a custom vertex format structure that contains position, normal data, and one set of texture coordinates.
CustomVertex.PositionOnly Describes a custom vertex format structure that contains only position data.
CustomVertex.PositionTextured Describes a custom vertex format structure that contains position and one set of texture coordinates.
CustomVertex.Transformed Describes a custom vertex format structure that contains transformed vertices.
CustomVertex.TransformedColored Describes a custom vertex format structure that contains transformed vertices and color information.
CustomVertex.TransformedColoredTextured Describes a custom vertex format structure that contains transformed vertices, color, and one set of texture coordinates.
CustomVertex.TransformedTextured Describes a custom vertex format structure that contains transformed vertices and one set of texture coordinates.

Inheritance Hierarchy

ObjectLeave Site

CustomVertex

How Do I...?

Create a Mesh Object

This example shows how to create a Mesh object.

In the following C# code example, device is assumed to be the rendering Device.

              [C#]
              
int numberVerts = 8;
short[] indices = {
    0,1,2, // Front Face 
    1,3,2, // Front Face 
    4,5,6, // Back Face 
    6,5,7, // Back Face 
    0,5,4, // Top Face 
    0,2,5, // Top Face 
    1,6,7, // Bottom Face 
    1,7,3, // Bottom Face 
    0,6,1, // Left Face 
    4,6,0, // Left Face 
    2,3,7, // Right Face 
    5,2,7 // Right Face 
};

Mesh mesh = new Mesh(numberVerts * 3, numberVerts, MeshFlags.Managed,
                     CustomVertex.PositionColored.Format, device);

using(VertexBuffer vb = mesh.VertexBuffer)
{
    GraphicsStream data = vb.Lock(0, 0, LockFlags.None);

    data.Write(new CustomVertex.PositionColored(-1.0f, 1.0f, 1.0f, 0x00ff00ff));
    data.Write(new CustomVertex.PositionColored(-1.0f, -1.0f, 1.0f, 0x00ff00ff));
    data.Write(new CustomVertex.PositionColored(1.0f, 1.0f, 1.0f, 0x00ff00ff));
    data.Write(new CustomVertex.PositionColored(1.0f, -1.0f, 1.0f, 0x00ff00ff));
    data.Write(new CustomVertex.PositionColored(-1.0f, 1.0f, -1.0f, 0x00ff00ff));
    data.Write(new CustomVertex.PositionColored(1.0f, 1.0f, -1.0f, 0x00ff00ff));
    data.Write(new CustomVertex.PositionColored(-1.0f, -1.0f, -1.0f, 0x00ff00ff));
    data.Write(new CustomVertex.PositionColored(1.0f, -1.0f, -1.0f, 0x00ff00ff));

    vb.Unlock();
}

using (IndexBuffer ib = mesh.IndexBuffer)
{
    ib.SetData(indices, 0, LockFlags.None);
}

Generate a Scene

This example shows how to begin scene generation and draw primitives.

The SetStreamSource method binds a vertex buffer to a device data stream to create an association between the vertex data and one of several data stream ports that feed the primitive processing functions. The parameters for this method are the number of the data stream, the name of the VertexBuffer object, and the stream vertex stride.

In the following C# code example, it is assumed that the device is the rendering Device, and vBuffer is a vertex buffer filled with CustomVertex.PositionNormal data.

              [C#]
              
device.BeginScene();

device.SetStreamSource(0, vBuffer, 0);
device.VertexFormat = CustomVertex.PositionNormal.Format;
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);

device.EndScene();

Class Information

Namespace Microsoft.DirectX.Direct3D
Assembly Microsoft.DirectX.Direct3D (microsoft.directx.direct3d.dll)
Strong Name Microsoft.DirectX.Direct3D,  Version=1.0.900.0,  Culture=neutral,  PublicKeyToken=d3231b57b74a1492