Vertex Definitions
Using the "quad" from the Base sample as a starting point, let's expand the vertex definitions for several simple shaders. We again will render a quad:
//a quad
#define NUM_VERTS 4
#define NUM_TRIS 2
Here we will use four different shaders for our quad:
// A structure for vertex shader0 vertex type
struct VERTEXSHADER0VERTEX
{
FLOAT x, y, z; // The untransformed position for the vertex
DWORD color; // The vertex color
};
// Our custom FVF, which describes our vertex shader0 vertex structure
#define D3DFVF_VERTEXSHADER0VERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)
// Initialize vertices for rendering a quad
VERTEXSHADER0VERTEX g_VertexShaderVertices0[] =
{
// x y z diffuse
{ -1.0f,-1.0f, 0.0f, 0xff00ff00, },//bl
{ 1.0f,-1.0f, 0.0f, 0xff00ff00, },//br
{ 1.0f, 1.0f, 0.0f, 0xffff0000, },//tr
{ -1.0f, 1.0f, 0.0f, 0xff0000ff, },//tl
};
// A structure for vertex shader1 vertex type
struct VERTEXSHADER1VERTEX
{
FLOAT x, y, z; // The untransformed position for the vertex
DWORD color; // The vertex color
};
// Our custom FVF, which describes our vertex shader1 vertex structure
#define D3DFVF_VERTEXSHADER1VERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)
// Initialize vertices for rendering a quad
VERTEXSHADER1VERTEX g_VertexShaderVertices1[] =
{
// x y z diffuse
{ -1.0f,-1.0f, 0.0f, 0xff00ff00, },//bl
{ 1.0f,-1.0f, 0.0f, 0xff00ff00, },//br
{ 1.0f, 1.0f, 0.0f, 0xffff0000, },//tr
{ -1.0f, 1.0f, 0.0f, 0xff0000ff, },//tl
};
// A structure for vertex shader2 vertex type
struct VERTEXSHADER2VERTEX
{
FLOAT x, y, z; // The untransformed position for the vertex
DWORD color; // The vertex color
FLOAT tu, tv; // the texture coords
};
// Our custom FVF, which describes our vertex shader2 vertex structure
#define D3DFVF_VERTEXSHADER2VERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)
// Initialize vertices for rendering a quad
VERTEXSHADER2VERTEX g_VertexShaderVertices2[] =
{
// x y z diffuse u1 v1
{ -1.0f,-1.0f, 0.0f, 0xff00ff00, 1.0f, 1.0f,},//bl
{ 1.0f,-1.0f, 0.0f, 0xff00ff00, 0.0f, 1.0f,},//br
{ 1.0f, 1.0f, 0.0f, 0xffff0000, 0.0f, 0.0f,},//tr
{ -1.0f, 1.0f, 0.0f, 0xff0000ff, 1.0f, 0.0f,},//tl
};
// A structure for vertex shader3 vertex type
struct VERTEXSHADER3VERTEX
{
FLOAT x, y, z; // The untransformed position for the vertex
FLOAT nx, ny, nz; // The normal for the vertex
DWORD color; // The vertex color
FLOAT tu, tv; // the texture coords
};
// Our custom FVF, which describes our vertex shader2 vertex structure
#define D3DFVF_VERTEXSHADER3VERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_DIFFUSE|D3DFVF_TEX1)
// Initialize vertices for rendering a quad
VERTEXSHADER3VERTEX g_VertexShaderVertices3[] =
{
// x y z nx ny nz diffuse u1 v1
{ -1.0f,-1.0f, 0.0f, 0.0f,0.0f, 1.0f, 0xff00ff00, 1.0f, 1.0f,},//bl
{ 1.0f,-1.0f, 0.0f, 0.0f,0.0f, 1.0f, 0xff00ff00, 0.0f, 1.0f,},//br
{ 1.0f, 1.0f, 0.0f, 0.0f,0.0f, 1.0f, 0xffff0000, 0.0f, 0.0f,},//tr
{ -1.0f, 1.0f, 0.0f, 0.0f,0.0f, 1.0f, 0xff0000ff, 1.0f, 0.0f,},//tl
};
Note we have defined four vertex types: