Game Development Reference
In-Depth Information
amount in radians, which is in our
m_CubeRotation
member variable. And finally
we update the cube's world matrix with the new rotation matrix we just created.
Rendering the scene
We have one last thing to change and we should be ready to run the program. We
need to change the code in our
RenderScene()
method to draw the cube. After the
line that clears the screen, we add the following line:
m_DeviceContext.ClearDepthStencilView(m_DepthStencilView,DepthStencilClearFlags.Depth,1.0f,0);
This line clears the depth stencil texture, so it is empty before we start rendering this
frame. Then below this, we need to add the following block of code:
m_DeviceContext.PixelShader.SetShaderResource(m_CubeTexture,
0);
m_DeviceContext.PixelShader.SetSampler(m_CubeTexSamplerState,
0);
// Send the cube's world matrix to the changes
per object constant buffer.
m_DataStream.Position = 0;
m_DataStream.Write(Matrix.Transpose(m_CubeWorldMatrix));
m_DataStream.Position = 0;
m_Device.ImmediateContext.UpdateSubresource(new
DataBox(0, 0,
m_DataStream),m_CbChangesPerObject,0);
The first two lines set our cube texture as a resource on the pixel shader so that it
can use it. The second line sets the sampler state to use with it. Then the next block
of code uses our
DataStream
to send the updated information for our cube into the
m_CbChangesPerObject
constant buffer.
Now we need to change the line that calls the
Draw()
method on the
DeviceCon-
text
: