Graphics Reference
In-Depth Information
11. Within
D3DApp.Run()
, where we have created our previous renders, insert the
following code to load the mesh file and then create the mesh renderer.
// Create and initialize the mesh renderer
var loadedMesh =
Common.Mesh.LoadFromFile("Male_base_mesh.cmo");
var mesh = ToDispose(new MeshRenderer(loadedMesh.First()));
mesh.Initialize(this);
mesh.World = Matrix.Identity;
For Windows Store apps, use
Common.Mesh.LoadFromFileAsync
.
12. And finally within the render loop, we update the
PerObject
constant buffer, set the
PerMaterialBuffer
property of the mesh renderer, and then tell it to render.
// Update the matrices
perObject.World = mesh.World * worldMatrix;
...
context.UpdateSubresource(ref perObject, perObjectBuffer);
// Provide with material constant buffer
mesh.PerMaterialBuffer = perMaterialBuffer;
// Render the mesh
mesh.Render();
13. Compile and run (
F5
) the previous code, and we should now see something like the
following screenshot (note that you may want to change the default pixel shader to
Blinn-Phong first):
Final output of the mesh renderer