<p>Vertex formats are specified in D3D11 using the <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ff476512(v=vs.85).aspx" rel="nofollow">input layout</a>. An example input layout description for your vertex might look like:</p>

<pre><code>D3D11_INPUT_ELEMENT_DESC aInputDescs[] =
{
    { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, UINT(offsetof(Vertex, p)), D3D11_INPUT_PER_VERTEX_DATA, 0 },
    { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, UINT(offsetof(Vertex, n)), D3D11_INPUT_PER_VERTEX_DATA, 0 },
    { "UV", 0, DXGI_FORMAT_R32G32_FLOAT, 0, UINT(offsetof(Vertex, tu)), D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
</code></pre>

CC BY-SA 3.0
2016-10-15T11:15:50.843Z
Is there a tangible D3D11 book you advice (like the red, blue, orange books for OpenGL)? Or is it just better to stick to Microsoft's webpages?
Matthias
CC BY-SA 3.0
2016-10-15T14:01:46.413Z
@Matthias I learned from the online API docs and other online resources. Maybe someone else can recommend a good book; I'm sure there are some out there.
Nathan Reed
CC BY-SA 3.0
2016-10-14T21:20:46.450Z
2016-10-14T21:20:46.450Z
Nathan Reed
<p>How do you migrate <em>Flexible Vertex Format Constants</em> (or <em><a href="https://msdn.microsoft.com/en-us/library/windows/desktop/bb172559(v=vs.85).aspx" rel="noreferrer">FVF</a> codes</em>) from <em>DirectX 9</em> to <em>Direct3D 11</em>?</p>

<p><strong>Old code</strong>:</p>

<pre><code>#include &lt;d3dx9.h&gt;

struct Vertex {

public:
    Vertex() : p(D3DXVECTOR3(0.0f, 0.0f, 0.0f)), n(D3DXVECTOR3(0.0f, 0.0f, 0.0f)), tu(0.0f), tv(0.0f) {}
    Vertex(D3DXVECTOR3 p, D3DXVECTOR3 n, float tu, float tv) : p(p), n(n), tu(tu), tv(tv) {}

    // Position of the vertex (in world space)
    D3DXVECTOR3 p;
    // Normal of this vertex
    D3DXVECTOR3 n;
    // Texture UV coordinates
    float tu, tv;
};

// D3DFVF_XYZ: Vertex format includes the position of an untransformed vertex.
// D3DFVF_NORMAL: Vertex format includes a vertex normal vector.
// D3DFVF_TEX1: Number of texture coordinate sets for this vertex.
#define VERTEX_FVF ( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 )
#define VERTEX_FVF_SIZE D3DXGetFVFVertexSize( VERTEX_FVF )
</code></pre>

<p><strong>New code</strong> without <a href="https://blogs.msdn.microsoft.com/chuckw/2013/08/20/living-without-d3dx/" rel="noreferrer">D3DX</a>:</p>

<pre><code>#include &lt;DirectXMath.h&gt;
using namespace DirectX;

struct Vertex {

public:
    Vertex() : p(XMFLOAT3(0.0f, 0.0f, 0.0f)), n(XMFLOAT3(0.0f, 0.0f, 0.0f)), tu(0.0f), tv(0.0f) {}
    Vertex(XMFLOAT3 p, XMFLOAT3 n, float tu, float tv) : p(p), n(n), tu(tu), tv(tv) {}

    // Position of the vertex (in world space)
    XMFLOAT3 p;
    // Normal of this vertex
    XMFLOAT3 n;
    // Texture UV coordinates
    float tu, tv;
};

// ??
</code></pre>

<p>P.S.: Can someone with enough reputation points create and add a <code>directx9</code> tag.</p>

<c++><direct3d>
Flexible Vertex Format Constants in Direct3D 11
Matthias
# Flexible Vertex Format Constants in Direct3D 11

(Asked by: username_0 on 2016-10-14)

How do you migrate *Flexible Vertex Format Constants* (or *[FVF](https://msdn.microsoft.com/en-us/library/windows/desktop/bb172559(v=vs.85).aspx) codes*) from *DirectX 9* to *Direct3D 11*?

**Old code**:

```
#include <d3dx9.h>

struct Vertex {

public:
    Vertex() : p(D3DXVECTOR3(0.0f, 0.0f, 0.0f)), n(D3DXVECTOR3(0.0f, 0.0f, 0.0f)), tu(0.0f), tv(0.0f) {}
    Vertex(D3DXVECTOR3 p, D3DXVECTOR3 n, float tu, float tv) : p(p), n(n), tu(tu), tv(tv) {}

    // Position of the vertex (in world space)
    D3DXVECTOR3 p;
    // Normal of this vertex
    D3DXVECTOR3 n;
    // Texture UV coordinates
    float tu, tv;
};

// D3DFVF_XYZ: Vertex format includes the position of an untransformed vertex.
// D3DFVF_NORMAL: Vertex format includes a vertex normal vector.
// D3DFVF_TEX1: Number of texture coordinate sets for this vertex.
#define VERTEX_FVF ( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 )
#define VERTEX_FVF_SIZE D3DXGetFVFVertexSize( VERTEX_FVF )

```

**New code** without [D3DX](https://blogs.msdn.microsoft.com/chuckw/2013/08/20/living-without-d3dx/):

```
#include <DirectXMath.h>
using namespace DirectX;

struct Vertex {

public:
    Vertex() : p(XMFLOAT3(0.0f, 0.0f, 0.0f)), n(XMFLOAT3(0.0f, 0.0f, 0.0f)), tu(0.0f), tv(0.0f) {}
    Vertex(XMFLOAT3 p, XMFLOAT3 n, float tu, float tv) : p(p), n(n), tu(tu), tv(tv) {}

    // Position of the vertex (in world space)
    XMFLOAT3 p;
    // Normal of this vertex
    XMFLOAT3 n;
    // Texture UV coordinates
    float tu, tv;
};

// ??

```

P.S.: Can someone with enough reputation points create and add a `directx9` tag.

**Tags:** c++, direct3d


---

## 1 answers

### Answer by username_1 on 2016-10-14. Score: 2 | Accepted answer

Vertex formats are specified in D3D11 using the [input layout](https://msdn.microsoft.com/en-us/library/windows/desktop/ff476512(v=vs.85).aspx). An example input layout description for your vertex might look like:

```
D3D11_INPUT_ELEMENT_DESC aInputDescs[] =
{
    { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, UINT(offsetof(Vertex, p)), D3D11_INPUT_PER_VERTEX_DATA, 0 },
    { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, UINT(offsetof(Vertex, n)), D3D11_INPUT_PER_VERTEX_DATA, 0 },
    { "UV", 0, DXGI_FORMAT_R32G32_FLOAT, 0, UINT(offsetof(Vertex, tu)), D3D11_INPUT_PER_VERTEX_DATA, 0 },
};

```

> **Comments:**
> **username_0**: Is there a tangible D3D11 book you advice (like the red, blue, orange books for OpenGL)? Or is it just better to stick to Microsoft's webpages?  
> **username_1**: @username_0 I learned from the online API docs and other online resources. Maybe someone else can recommend a good book; I'm sure there are some out there.  

---

