Game Development Reference
In-Depth Information
HRESULT hr;
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;
hr = DXUTGetD3D11Device()->CreateBuffer( &bd, &InitData, &m_pVertexBuffer );
if( SUCCEEDED ( hr ) )
{
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof( WORD ) * m_numPolys * 3;
bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
bd.CPUAccessFlags = 0;
InitData.pSysMem = pIndices;
hr = DXUTGetD3D11Device()->CreateBuffer( &bd, &InitData, &m_pIndexBuffer );
}
SAFE_DELETE_ARRAY(pVerts);
SAFE_DELETE_ARRAY(pIndices);
return hr;
In the creation of both the vertex buffer and the index buffer, a D3D11_BUFFER_
DESC structure is used to describe what kind of buffer we are creating. ByteWidth
is set to the number of bytes in the entire buffer. BindFlags is set to either
D3D11_BIND_VERTEX_BUFFER or D3D11_BIND_INDEX_BUFFER . In both cases, a
D3D11_SUBRESOURCE_DATA structure is initialized with a pointer to the data. A
successful result will create an ID3D11Buffer , which you
'
ll use during rendering.
Still with Me?
This chapter skimmed the surface of 3D basics like a rock skipping on a pond. 3D
math, transforms, frustums, lighting, textures, and geometry
all in just a few pages.
I know it isn
t nearly enough information, and there is a lot more depth to all those
subjects. I encourage you to go find out more about them, but know you
'
'
ll at least
have a little more knowledge and experience, and maybe you won
'
t feel quite so
lost. You
ll also recognize a lot more code in the Direct3D 11 samples and tutorials.
Next, you
'
'
ll learn how all of the resources you learned about in this chapter get sent
into vertex and pixel shaders. Get ready for another run across the pond.
 
 
Search WWH ::




Custom Search