Graphics Reference
In-Depth Information
6.
Within our Direct3D application class ( D3DApp ), change the vertex layout initialization
to include the texture coordinate:
vertexLayout = ToDispose(new InputLayout(device,
ShaderSignature.GetInputSignature(vertexShaderBytecode),
new[] {
// input semantic SV_Position=vertex coord in object space
new InputElement("SV_Position",0,Format.R32G32B32A32_Float, 0, 0),
// input semantic TEXTCOORD = vertex texture coordinate
new InputElement(" TEXCOORD ", 0, Format.R32G32_Float , 16, 0)
}));
7.
In each of the renderers, add the following private member fields:
// Shader texture resource
ShaderResourceView textureView;
// Control sampling behavior with this state
SamplerState samplerState;
8. And then, initialize member fields within the CreateDeviceDependentResources
method, changing Texture.png to Texture2.png in the TriangleRenderer
class.
// Load texture
textureView = ToDispose(
ShaderResourceView.FromFile(device, "Texture.png"));
// Create our sampler state
samplerState = ToDispose(
new SamplerState(device, new SamplerStateDescription() {
AddressU = TextureAddressMode.Wrap,
AddressV = TextureAddressMode.Wrap,
AddressW = TextureAddressMode.Wrap,
Filter = Filter.MinMagMipLinear,
}));
9.
Within the DoRender method of each primitive renderer, add the following code:
// Set the shader resource
context.PixelShader.SetShaderResource(0, textureView);
// Set the sampler state
context.PixelShader.SetSampler(0, samplerState);
 
Search WWH ::




Custom Search