Game Development Reference
In-Depth Information
'
you to avoid serious vertex duplication and save tons of memory. Here
s the code
that created the grid verts and indices in the teapot example:
// Create the vertex buffer − we'll need enough verts
// to populate the grid. If we want a 2x2 grid, we'll
// need 3x3 set of verts.
m_numVerts = (m_squares+1)*(m_squares+1);
// Create vertex buffer
// Fill the vertex buffer. We are setting the tu and tv texture
// coordinates, which range from 0.0 to 1.0
D3D11Vertex_UnlitTextured *pVerts =
GCC_NEW D3D11Vertex_UnlitTextured[m_numVerts];
GCC_ASSERT(pVerts &&
Out of memory
);
for( int j=0; j<(m_squares+1); j++ )
{
for (int i=0; i<(m_squares+1); i++)
{
// Which vertex are we setting?
int index =i+(j*(m_squares+1) );
D3D11Vertex_UnlitTextured *vert = &pVerts[index];
// Default position of the grid is centered on the origin, flat on
// the XZ plane.
float x = (float)i - (m_squares/2.0f);
float y = (float)j - (m_squares/2.0f);
vert->Pos = Vec3(x,0.f,y);
vert->Normal = Vec3(0.0f, 1.0f, 0.0f);
// The texture coordinates are set to x,y to make the
// texture tile along with units - 1.0, 2.0, 3.0, etc.
vert->Uv.x
= x;
vert->Uv.y
= y;
}
}
D3D11_BUFFER_DESC bd;
ZeroMemory( &bd, sizeof(bd) );
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof( D3D11Vertex_UnlitTextured ) * m_numVerts;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;
D3D11_SUBRESOURCE_DATA InitData;
ZeroMemory( &InitData, sizeof(InitData) );
InitData.pSysMem = pVerts;
Search WWH ::




Custom Search