DX11Starter/Game.cpp
// --------------------------------------------------------
// Clear the screen, redraw everything, present to the user
// --------------------------------------------------------
Clear the screen, redraw everything, present to the user
Clear the screen redraw everything present to the user
void Game::Draw(float deltaTime, float totalTime)
{
	const float color[4] = {0.4f, 0.6f, 0.75f, 0.0f};
	context->ClearRenderTargetView(backBufferRTV, color);
	context->ClearDepthStencilView(
		depthStencilView, 
		D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL,
		1.0f,
		0);
	std::vector<Entity*>::iterator it;
	for (it = entities.begin(); it < entities.end(); it++) {
		baseMaterial->GetPixelShader()->SetData("light", &lights[0], sizeof(DirectionalLight));
		baseMaterial->GetPixelShader()->SetData("light2", &lights[1], sizeof(DirectionalLight));
		(*it)->PrepareMaterial(camera->getViewMatrix(), camera->getProjectionMatrix(), sampler);
		UINT stride = sizeof(Vertex);
		UINT offset = 0;
		Mesh* mesh = (*it)->GetMesh();
		ID3D11Buffer* vertexBuffer = mesh->GetVertexBuffer();
		context->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset);
		context->IASetIndexBuffer(mesh->GetIndexBuffer(), DXGI_FORMAT_R32_UINT, 0);
		context->DrawIndexed(
			mesh->GetIndexCount(),     
			0,     
			0);    
	}
	swapChain->Present(0, 0);
}
void Game :: Draw ( float deltaTime , float totalTime ) { const float color [ 4 ] = { 0.4f , 0.6f , 0.75f , 0.0f } ; context -> ClearRenderTargetView ( backBufferRTV , color ) ; context -> ClearDepthStencilView ( depthStencilView , D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL , 1.0f , 0 ) ; std :: vector < Entity * > :: iterator it ; for ( it = entities . begin ( ) ; it < entities . end ( ) ; it ++ ) { baseMaterial -> GetPixelShader ( ) -> SetData ( " " , & lights [ 0 ] , sizeof ( DirectionalLight ) ) ; baseMaterial -> GetPixelShader ( ) -> SetData ( " " , & lights [ 1 ] , sizeof ( DirectionalLight ) ) ; ( * it ) -> PrepareMaterial ( camera -> getViewMatrix ( ) , camera -> getProjectionMatrix ( ) , sampler ) ; UINT stride = sizeof ( Vertex ) ; UINT offset = 0 ; Mesh * mesh = ( * it ) -> GetMesh ( ) ; ID3D11Buffer * vertexBuffer = mesh -> GetVertexBuffer ( ) ; context -> IASetVertexBuffers ( 0 , 1 , & vertexBuffer , & stride , & offset ) ; context -> IASetIndexBuffer ( mesh -> GetIndexBuffer ( ) , DXGI_FORMAT_R32_UINT , 0 ) ; context -> DrawIndexed ( mesh -> GetIndexCount ( ) , 0 , 0 ) ; } swapChain -> Present ( 0 , 0 ) ; }
Clear the screen, redraw everything, present to the user
Clear the screen redraw everything present to the user
// Background color (Cornflower Blue in this case) for clearing // Clear the render target and depth buffer (erases what's on the screen) //  - Do this ONCE PER FRAME //  - At the beginning of Draw (before drawing *anything*) // Set buffers in the input assembler //  - Do this ONCE PER OBJECT you're drawing, since each object might //    have different geometry. // Finally do the actual drawing //  - Do this ONCE PER OBJECT you intend to draw //  - This will use all of the currently set DirectX "stuff" (shaders, buffers, etc) //  - DrawIndexed() uses the currently set INDEX BUFFER to look up corresponding //     vertices in the currently set VERTEX BUFFER // The number of indices to use (we could draw a subset if we wanted) // Offset to the first index we want to use // Offset to add to each index when looking up vertices // Present the back buffer to the user //  - Puts the final frame we're drawing into the window so the user can see it //  - Do this exactly ONCE PER FRAME (always at the very end of the frame)