Game Development Reference
In-Depth Information
DXUTGetD3D11DeviceContext()->PSSetShaderResources( 0, 1, pDiffuseRV );
DXUTGetD3D11DeviceContext()->PSSetSamplers( 0, 1, ppSamplers );
return S_OK;
}
The first method uses the resource cache and the texture loader to grab the raw bits
of the texture and create a D3DTextureResourceExtraData11 object, as you saw
in the texture section in this chapter. That class defines both the ID3DShaderRe-
sourceView and the ID3D11SamplerState the pixel shader will use to sample
the texture and set the right color for any textured pixel it draws.
Rendering with the Shader Helper Classes
So far all you
'
ve done is set up everything, but nothing in the code you
'
ve seen in this
or the previous chapter has rendered a single pixel yet. There
s one bit of code you
need to actually engage both shaders and make pretty things appear on your screen.
From the last chapter, you learned how to define a vertex buffer and an index buffer
that holds your geometry. You
'
ll also use an instantiated Game-
Code4_Hlsl_VertexShader object and a GameCode4_Hlsl_PixelShader
object each of which has already had the OnRestore() method called to initialize
it. With those four objects, you render to the screen with this code:
'
ll use those now. You
'
m_VertexShader.SetupRender(pScene, pNode);
m_PixelShader.SetupRender(pScene, pNode);
// Set vertex buffer
UINT stride = sizeof( D3D11Vertex_UnlitTextured );
UINT offset = 0;
DXUTGetD3D11DeviceContext()->
IASetVertexBuffers( 0, 1, &m_pVertexBuffer, &stride, &offset );
// Set index buffer
DXUTGetD3D11DeviceContext()->
IASetIndexBuffer( m_pIndexBuffer, DXGI_FORMAT_R16_UINT, 0 );
// Set primitive topology
DXUTGetD3D11DeviceContext()->
IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
DXUTGetD3D11DeviceContext()->DrawIndexed( m_numPolys * 3, 0, 0 );
Here ' s the cast of characters:
n m_VertexShader is an instantiation of the GameCode4_Hlsl_VertexShader
class.
 
 
Search WWH ::




Custom Search