// Render the model using the given matrix list as a hierarchy (must be one matrix per node)
void CMesh::Render(	CMatrix4x4* matrices )
{
	if (!m_HasGeometry) return;

	for (TUInt32 subMesh = 0; subMesh < m_NumSubMeshes; ++subMesh)
	{
		// Get a reference to the submesh and its material to reduce code clutter
		SSubMeshDX& subMeshDX = m_SubMeshesDX[subMesh];
		SMeshMaterialDX& material = m_Materials[subMeshDX.material];

		// Set up render method passing material colours & textures and the sub-mesh's world matrix, also get back the fx file technique to use
		SetRenderMethod( material.renderMethod, &material.diffuseColour, &material.specularColour, material.specularPower, material.textures, &matrices[subMeshDX.node] );
		ID3D10EffectTechnique* technique = GetRenderMethodTechnique( material.renderMethod );

		// Select vertex and index buffer for sub-mesh - assuming all geometry data is triangle lists
		UINT offset = 0;
		g_pd3dDevice->IASetVertexBuffers( 0, 1, &subMeshDX.vertexBuffer, &subMeshDX.vertexSize, &offset );
		g_pd3dDevice->IASetInputLayout(subMeshDX.vertexLayout );
		g_pd3dDevice->IASetIndexBuffer(subMeshDX.indexBuffer, DXGI_FORMAT_R16_UINT, 0 );
		g_pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

		// Render the sub-mesh. Geometry buffers and shader variables, just select the technique for this method and draw.
		D3D10_TECHNIQUE_DESC techDesc;
		technique->GetDesc( &techDesc );
		for( UINT p = 0; p < techDesc.Passes; ++p )
		{
			technique->GetPassByIndex( p )->Apply( 0 );
			g_pd3dDevice->DrawIndexed( subMeshDX.numIndices, 0, 0 );
		}
		g_pd3dDevice->DrawIndexed( subMeshDX.numIndices, 0, 0 );
	}
}
Exemple #2
0
void ColoredCubeApp::drawScene()
{
    D3DApp::drawScene();

    // Restore default states, input layout and primitive topology
    // because mFont->DrawText changes them.  Note that we can
    // restore the default states by passing null.
    md3dDevice->OMSetDepthStencilState(0, 0);
    float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
    md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
    md3dDevice->IASetInputLayout(mVertexLayout);
    md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINELIST);

    // set constants
    mWVP = mView*mProj;
    mfxWVPVar->SetMatrix((float*)&mWVP);

    D3D10_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );
    for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        mTech->GetPassByIndex( p )->Apply(0);

        //mBox.draw();
        mLine1.draw();
        mLine2.draw();
        mLine3.draw();
    }

    // We specify DT_NOCLIP, so we do not care about width/height of the rect.
    RECT R = {5, 5, 0, 0};
    mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK);

    mSwapChain->Present(0, 0);
}
Exemple #3
0
void CubeMapApp::drawScene()
{
	D3DApp::drawScene();
	
	
	// Restore default states, input layout and primitive topology 
	// because mFont->DrawText changes them.  Note that we can 
	// restore the default states by passing null.
	md3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactor, 0xffffffff);
	
	md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
	md3dDevice->IASetInputLayout(InputLayout::PosNormalTex);

	// Set per frame constants.
	mfxEyePosVar->SetRawValue(&GetCamera().position(), 0, sizeof(D3DXVECTOR3));
	mfxLightVar->SetRawValue(&mParallelLight, 0, sizeof(Light));
	
	mfxCubeMapVar->SetResource(mEnvMapRV);
	

	D3DXMATRIX view = GetCamera().view();
	D3DXMATRIX proj = GetCamera().proj();

    D3D10_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );

    for(UINT i = 0; i < techDesc.Passes; ++i)
    {
        ID3D10EffectPass* pass = mTech->GetPassByIndex(i);

		//
		// draw center ball
		//
		D3DXMATRIX centerBallWVP = mCenterBallWorld*view*proj;
		mfxWVPVar->SetMatrix((float*)&centerBallWVP);
		mfxWorldVar->SetMatrix((float*)&mCenterBallWorld);
		mfxTexMtxVar->SetMatrix((float*)&mIdentityTexMtx);
		mfxDiffuseMapVar->SetResource(mBallMapRV);
		mfxSpecMapVar->SetResource(mDefaultSpecMapRV);
		mfxCubeMapEnabledVar->SetBool(true);
		mfxReflectMtrlVar->SetFloatVector((float*)&mReflectAll);
		pass->Apply(0);
		mBall.draw();		
    }

	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	md3dDevice->RSSetState(0);
	mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, WHITE);

	mSwapChain->Present(0, 0);
}
Exemple #4
0
//--------------------------------------------------------------------------------------
// RenderGrass
//--------------------------------------------------------------------------------------
void RenderGrass( ID3D10Device* pd3dDevice )
{
    D3DXMATRIX mWorld;
    D3DXMatrixIdentity( &mWorld );

    D3DXVECTOR3 vEye;
    D3DXVECTOR3 vDir;
    D3DXMATRIX mCamWorld;
    D3DXMATRIX mView;
    D3DXMATRIX mProj;
    GetCameraData( &mCamWorld, &mView, &mProj, &vEye, &vDir );
    D3DXMATRIX mWVP = mCamWorld * mView * mProj;

    // set vb streams
    ID3D10Buffer* pBuffers[1];
    pBuffers[0] = g_pGrassDataVB10;
    UINT strides[1];
    strides[0] = sizeof( D3DXVECTOR3 );
    UINT offsets[1] = {0};
    pd3dDevice->IASetVertexBuffers( 1, 1, pBuffers, strides, offsets );

    SetNumVisibleGrassTiles( g_NumGrassTiles );

    // set effect variables
    g_pmWorldViewProj->SetMatrix( ( float* )&mWVP );
    g_pfWorldScale->SetFloat( g_fWorldScale );
    g_pfHeightScale->SetFloat( g_fHeightScale );
    D3DXVECTOR4 vEye4( vEye, 1 );
    g_pvEyePt->SetFloatVector( ( float* )&vEye4 );
    g_pfFadeStart->SetFloat( g_fFadeStart );
    g_pfFadeEnd->SetFloat( g_fFadeEnd );

    g_ptxDiffuse->SetResource( g_pGrassTexRV );
    g_ptxHeight->SetResource( g_pHeightTexRV );
    g_ptxMask->SetResource( g_pMaskTexRV );
    g_ptxShadeNormals->SetResource( g_pShadeNormalTexRV );

    ID3D10EffectTechnique* pTechnique = g_pRenderGrass;

    pd3dDevice->IASetInputLayout( g_pGrassDecl10 );

    D3D10_TECHNIQUE_DESC techDesc;
    pTechnique->GetDesc( &techDesc );

    for( UINT p = 0; p < techDesc.Passes; p++ )
    {
        pTechnique->GetPassByIndex( p )->Apply( 0 );

        g_Terrain.RenderGrass( &vDir, g_NumGrassTiles );
    }

    pBuffers[0] = NULL;
    pd3dDevice->IASetVertexBuffers( 1, 1, pBuffers, strides, offsets );
}
void TestApplication1::OnFrameRender(ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext)
{
	HRESULT hr;

	//Render
	ID3D10EffectTechnique* pRenderTechnique;
	D3D10_TECHNIQUE_DESC techDesc;
	pRenderTechnique = _shaderutil.GetTechnique();
	pRenderTechnique->GetDesc(&techDesc);
	SDKMESH_SUBSET* pSubset = NULL;
	ID3D10ShaderResourceView* pDiffuseRV = NULL;
	D3D10_PRIMITIVE_TOPOLOGY PrimType;

	D3DXMATRIX mWorldViewProjection;
	//D3DXVECTOR3 vLightDir[MAX_LIGHTS];
	//D3DXVECTOR4 vLightDiffuse[MAX_LIGHTS];
	D3DXMATRIX mWorld;
	D3DXMATRIX mView;
	D3DXMATRIX mProj;

	// Get the projection & view matrix from the camera class
	mWorld = _mCenterMesh * *_camera.GetWorldMatrix();
	mProj = *_camera.GetProjMatrix();
	mView = *_camera.GetViewMatrix();

	mWorldViewProjection = mWorld * mView * mProj;

	_shaderutil.SetWorldMatrix(mWorld);
	_shaderutil.SetViewMatrix(mView);
	_shaderutil.SetProjectionMatrix(mProj);

	for (UINT p = 0; p < techDesc.Passes; ++p)
	{
		for (UINT subset = 0; subset < _Mesh.GetNumSubsets(0); ++subset)
		{
			// Get the subset
			pSubset = _Mesh.GetSubset(0, subset);

			PrimType = CDXUTSDKMesh::GetPrimitiveType10((SDKMESH_PRIMITIVE_TYPE)pSubset->PrimitiveType);
			pd3dDevice->IASetPrimitiveTopology(PrimType);

			//pDiffuseRV = _Mesh.GetMaterial(pSubset->MaterialID)->pDiffuseRV10;
			//g_ptxDiffuse->SetResource(pDiffuseRV);

			pRenderTechnique->GetPassByIndex(p)->Apply(0);
			pd3dDevice->DrawIndexed((UINT)pSubset->IndexCount, 0, (UINT)pSubset->VertexStart);
		}
	}
}
Exemple #6
0
void Model3D::Draw(D3DXMATRIX WorldMatrix,D3DXMATRIX ViewMatrix,D3DXMATRIX ProjectionMatrix,float DeltaTime,Light lights[],Vector3 CurrentCam)
{
	D3DXMATRIX transMatrix;
	if(ChangedOrigin == true)
		D3DXMatrixTranslation(&transMatrix, newOrigin.X, newOrigin.Y, newOrigin.Z);
	else
		D3DXMatrixTranslation(&transMatrix, m_Position.X, m_Position.Y, m_Position.Z);


	D3DXMATRIX rot;
	D3DXMatrixRotationYawPitchRoll(&rot,m_Rotation.X, m_Rotation.Y, m_Rotation.Z);

	D3DXMATRIX scale;
	D3DXMatrixIdentity(&scale);

	D3DXMATRIX World = scale * rot * transMatrix;
	World = World * WorldMatrix;

	D3DXMATRIX WVP = World * ViewMatrix * ProjectionMatrix;

	m_Shader->SetWorld(World);
	m_Shader->SetWVP(WVP);
	m_Shader->SetLight(lights);
	m_Shader->SetCurrentCamera(CurrentCam);

	m_ShaderTexture = m_Shader->m_Texture;

	if(m_Texture != NULL)
	{
		m_ShaderTexture->SetResource(m_Texture);
	}

	ID3D10EffectTechnique* tech = m_Shader->GetTech();
	ID3D10InputLayout* layout = m_Shader->GetVertexLayout();

	D3D10_TECHNIQUE_DESC techDesc;
	tech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
	{
		tech->GetPassByIndex( p )->Apply(0);   
		UINT stride = sizeof(Vertex);
		UINT offset = 0;
		m_Device->IASetVertexBuffers(0, 1, &m_VertexBuffer, &stride, &offset);
		m_Device->Draw(m_VertexCount,0);
	}

	if(m_Child != NULL)
		m_Child->Draw(World,ViewMatrix,ProjectionMatrix,DeltaTime,lights,CurrentCam);
}
Exemple #7
0
void Cube::Draw(ID3D10Effect* effects, D3DXMATRIX& view_matrix, D3DXMATRIX& proj_matrix, D3DXVECTOR3& eye_pos)
{
	 // Obtain shader variables
	texture_id_        = effects->GetVariableByName("TextureId")->AsScalar();
 	wvp_matrix_ = effects->GetVariableByName("WVPMatrix")->AsMatrix();

	// Set world view projection matrix
	D3DXMATRIX wvp_matrix = world_matrix_ * view_matrix * proj_matrix;
	wvp_matrix_->SetMatrix((float*)wvp_matrix);

	// Set vertex buffer
	UINT stride = sizeof(Vertex);
	UINT offset = 0;
	d3d_device_->IASetVertexBuffers(0, 1, &vertex_buffer_, &stride, &offset);

	// Set geometry type
	d3d_device_->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);

	// Obtain the technique
    ID3D10EffectTechnique* technique = effects->GetTechniqueByName("Render");
	if (technique == NULL)
	{
		MessageBox(NULL, L"Get technique failed", L"Error", 0);
	}

	// Apply each pass in technique and draw triangle.
	D3D10_TECHNIQUE_DESC techDesc;
	technique->GetDesc(&techDesc);
	for (unsigned int i = 0; i < techDesc.Passes; ++i)
	{
		ID3D10EffectPass* pass = technique->GetPassByIndex(i);
		pass->Apply(0);
		
		// Draw cube by draw every face of the cube
		for(int i = 0; i < kNumFaces_; ++i)
		{
			// Set texture id
			texture_id_->SetInt(textureId[i]);

			// Set index buffer
			d3d_device_->IASetIndexBuffer(pIB[i], DXGI_FORMAT_R16_UINT, 0);

			pass->Apply(0);
			
			d3d_device_->DrawIndexed(4, 0, 0);
		}
	}
}
Exemple #8
0
void D10State::draw() {
	clock_t t = clock();
	float elapsed = static_cast<float>(t - timeT) / CLOCKS_PER_SEC;
	++frameCount;
	if (elapsed > OVERLAY_FPS_INTERVAL) {
		OverlayMsg om;
		om.omh.uiMagic = OVERLAY_MAGIC_NUMBER;
		om.omh.uiType = OVERLAY_MSGTYPE_FPS;
		om.omh.iLength = sizeof(OverlayMsgFps);
		om.omf.fps = frameCount / elapsed;

		sendMessage(om);

		frameCount = 0;
		timeT = t;
	}

	dwMyThread = GetCurrentThreadId();

	checkMessage(vp.Width, vp.Height);

	if (a_ucTexture && pSRView && (uiLeft != uiRight)) {
		HRESULT hr;
		pOrigStateBlock->Capture();
		pMyStateBlock->Apply();

		D3D10_TECHNIQUE_DESC techDesc;
		pTechnique->GetDesc(&techDesc);

		// Set vertex buffer
		UINT stride = sizeof(SimpleVertex);
		UINT offset = 0;
		pDevice->IASetVertexBuffers(0, 1, &pVertexBuffer, &stride, &offset);

		hr = pDiffuseTexture->SetResource(pSRView);
		if (! SUCCEEDED(hr))
			ods("D3D10: Failed to set resource");

		for (UINT p = 0; p < techDesc.Passes; ++p) {
			pTechnique->GetPassByIndex(p)->Apply(0);
			pDevice->DrawIndexed(6, 0, 0);
		}
		pOrigStateBlock->Apply();
	}

	dwMyThread = 0;
}
Exemple #9
0
void ColoredCubeApp::drawScene()
{
	D3DApp::drawScene();

	// Restore default states, input layout and primitive topology 
	// because mFont->DrawText changes them.  Note that we can 
	// restore the default states by passing null.
	md3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
    md3dDevice->IASetInputLayout(mVertexLayout);

	// set some variables for the shader
	int foo[1];
	foo[0] = 0;
	// set the point to the shader technique
	D3D10_TECHNIQUE_DESC techDesc;
	mTech->GetDesc(&techDesc);

	//setting the color flip variable in the shader
	mfxFLIPVar->SetRawValue(&foo[0], 0, sizeof(int));
	
	rightWall.draw(mView, mProj, mTech);
	//floor.draw(mView, mProj, mTech);
	leftWall.draw(mView, mProj, mTech);
	//ceiling.draw(mView, mProj, mTech);

	shootCube.draw(mView, mProj, mTech);

	hitCubes->draw(mView,mProj,mTech);

	avoidCubes->draw(mView,mProj,mTech);

	//for(int i = 0; i < 20; i++)
	//{
	//	tiles[i].draw(mView, mProj, mTech);
	//	//wall[i].draw(mView,mProj,mTech);
	//}

	//draw the origin
	origin.draw(mView, mProj, mTech);
     
	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	mFont->DrawText(0, mTimer.c_str(), -1, &R, DT_NOCLIP, BLUE);
	mSwapChain->Present(0, 0);
}
Exemple #10
0
void CrateApp::drawScene()
{
	D3DApp::drawScene();

	// Restore default states, input layout and primitive topology 
	// because mFont->DrawText changes them.  Note that we can 
	// restore the default states by passing null.
	md3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
    md3dDevice->IASetInputLayout(mVertexLayout);
    md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

 
	// set constants
	mfxEyePosVar->SetRawValue(&mEyePos, 0, sizeof(D3DXVECTOR3));
	mfxLightVar->SetRawValue(&mParallelLight, 0, sizeof(Light));
	mWVP = mCrateWorld*mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
	mfxWorldVar->SetMatrix((float*)&mCrateWorld);
	mfxDiffuseMapVar->SetResource(mDiffuseMapRV);
	mfxSpecMapVar->SetResource(mSpecMapRV);
 
	// Don't transform texture coordinates, so just use identity transformation.
	D3DXMATRIX texMtx;
	D3DXMatrixIdentity(&texMtx);
	mfxTexMtxVar->SetMatrix((float*)&texMtx);

    D3D10_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );
    for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        mTech->GetPassByIndex( p )->Apply(0);
        
		mCrateMesh.draw();
    }

	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK);

	mSwapChain->Present(0, 0);
}
void ColoredTriangleApp::drawScene()
{
	D3DApp::drawScene();
	// Restore default states, input layout and primitive topology 
	// because mFont->DrawText changes them.  Note that we can 
	// restore the default states by passing null.
	md3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->RSSetState(pRasterizer);
	md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
	md3dDevice->IASetInputLayout(mVertexLayout);
    md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);   

	// set constants
	mWVP = mView*mProj;
	
	D3D10_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );

	obj1.theta += D3DXVECTOR3(0,0.001f,0);
	obj1.setTrans(mWVP);	

	mfxWVPVar->SetMatrix((float*)&obj1.objMatrix);
    DrawTriangle(techDesc);

	/*D3DXMatrixTranslation(&obj2.worldMatrix,obj2.pos.x,obj2.pos.y,obj2.pos.z);	

	D3DXMatrixRotationY(&obj2.worldMatrix,rotAngle);

	rotAngle+= 0.001f;

	obj2.worldMatrix = obj2.worldMatrix*mWVP;

	mfxWVPVar->SetMatrix((float*)&obj2.worldMatrix);
	DrawTriangle(techDesc);*/

	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	md3dDevice->RSSetState(0);
	mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK);
	mSwapChain->Present(0, 0);
}
bool BufferObject::render()
{
	if(TransformObject::render())
	{
		ID3D10Buffer *buffers[2];
		buffers[0] = mpVertexBufferStatic;
		buffers[1] = mpVertexBufferDynamic;
		unsigned int stride[2];
		stride[0] = getEffect()->getInputLayoutHandler().getInputLayout(getEffectTechIndex())->getLayoutSizeStatic();
		stride[1] = getEffect()->getInputLayoutHandler().getInputLayout(getEffectTechIndex())->getLayoutSizeDynamic();
		unsigned int offset[2];
		offset[0] = 0;
		offset[1] = 0;
		getDevice()->IASetVertexBuffers(0, 2, buffers, stride, offset);
		getDevice()->IASetIndexBuffer(mpIndexBuffer, DXGI_FORMAT_R32_UINT, 0);
		getDevice()->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST_ADJ);
		getDevice()->IASetInputLayout(getEffect()->getInputLayoutHandler().getInputLayout(getEffectTechIndex())->getDXInputLayout());

		ID3D10EffectTechnique *pEffectTechnique = getEffect()->getEffect()->GetTechniqueByIndex(getEffectTechIndex());
		
		if(getRenderPass() == -1)
		{
			D3D10_TECHNIQUE_DESC techDesc;
			pEffectTechnique->GetDesc(&techDesc);
			for(unsigned int n = 0; n < techDesc.Passes; ++n)
			{
				pEffectTechnique->GetPassByIndex(n)->Apply(0);
				getDevice()->DrawIndexed(mIndexCount, 0, 0);
			}
			return true;
		}
		else
		{
			// To render a single pass decided with setRenderPass()
			pEffectTechnique->GetPassByIndex(getRenderPass())->Apply(0);
			getDevice()->DrawIndexed(mIndexCount, 0, 0);

			return true;
		}
	}
	return false;
}
Exemple #13
0
void LineModel::Draw(D3DXMATRIX WorldMatrix,D3DXMATRIX ViewMatrix,D3DXMATRIX ProjectionMatrix,float DeltaTime)
{
	D3DXMATRIX transMatrix;
	if(ChangedOrigin == true)
		D3DXMatrixTranslation(&transMatrix, newOrigin.X, newOrigin.Y, newOrigin.Z);
	else
		D3DXMatrixTranslation(&transMatrix, m_Position.X, m_Position.Y, m_Position.Z);

	D3DXMATRIX rot;
	D3DXMatrixRotationYawPitchRoll(&rot,m_Rotation.X, m_Rotation.Y, m_Rotation.Z);

	D3DXMATRIX scale;
	D3DXMatrixIdentity(&scale);

	D3DXMATRIX World = scale * rot * transMatrix;
	World = World * WorldMatrix;

	D3DXMATRIX WVP = World * ViewMatrix * ProjectionMatrix;

	m_Shader->SetWorld(World);
	m_Shader->SetWVP(WVP);

	ID3D10EffectTechnique* tech = m_Shader->GetTech();
	ID3D10InputLayout* layout = m_Shader->GetVertexLayout();

	D3D10_TECHNIQUE_DESC techDesc;
	tech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
	{
		tech->GetPassByIndex( p )->Apply(0);   
		UINT stride = sizeof(Vector3);
		UINT offset = 0;
		m_Device->IASetVertexBuffers(0, 1, &m_VertexBuffer, &stride, &offset);
		m_Device->Draw(m_VertexCount, 0);
	}
}
void ColoredCubeApp::drawScene()
{
	D3DApp::drawScene();

	//Step through animation frame
	animationTimeElapsed += mTimer.getGameTime() - animationTimePrev;
	animationTimePrev = mTimer.getGameTime();
	if(animationTimeElapsed > 0.0666f)
	{
		animationTimeElapsed = 0.0f;
		frameOfAnimation++;
		if(frameOfAnimation > fireFrameCount-1)
		{
			frameOfAnimation = 0;
		}
	}

	// Restore default states, input layout and primitive topology 
	// because mFont->DrawText changes them.  Note that we can 
	// restore the default states by passing null.
	md3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
    md3dDevice->IASetInputLayout(mVertexLayout);
    md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	// Set per frame constants
	mfxEyePosVar->SetRawValue(&mCameraPos, 0, sizeof(D3DXVECTOR3));
	mfxLightVar->SetRawValue(&mLights[0], 0, sizeof(Light));
	mfxLightVar2->SetRawValue(&mLights[1], 0, sizeof(Light));

	mfxCubeMapVR->SetResource(mCubeMapRV);
   
	// set constants
	mWVP = mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP); //set gWVP in color.fx to mWVP

	mTree.setEyePos(mCameraPos);
	mTree.setLights(mLights, 2);
	mTree.draw(mView, mProj);
	mObjBox.setEyePos(mCameraPos);
	mObjBox.setLights(mLights, 2);
	mObjBox.draw(mView, mProj);

    D3D10_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );
    for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        ID3D10EffectPass* pass = mTech->GetPassByIndex( p ); //zero is always used in D3D10
		D3DXMATRIX texMtx;
        
		mWVP = mBoxWorld*mView*mProj;
		mfxWVPVar->SetMatrix((float*)&mWVP);
		mfxWorldVar->SetMatrix((float*)&mBoxWorld);
		mfxDiffuseMapVar->SetResource(mCrateMapRV);
		//mfxDiffuseMapVar->SetResource(mFireAnimationMapRVs[frameOfAnimation]);
		mfxSpecularMapVar->SetResource(mSpecularMapRV);
		mfxNormalMapVR->SetResource(mDefaultNormalMapRV);
		mfxReflectEnabledVar->SetBool(false);
		D3DXMatrixIdentity(&texMtx);
		mfxTexMtxVar->SetMatrix((float*)&texMtx);
		pass->Apply(0);
		mBox.draw();

		mWVP = mPlaneWorld*mView*mProj;
		mfxWVPVar->SetMatrix((float*)&mWVP);
		mfxWorldVar->SetMatrix((float*)&mPlaneWorld);
		mfxDiffuseMapVar->SetResource(mGrassMapRV);
		mfxNormalMapVR->SetResource(mBrickNormalMapRV);
		mfxReflectEnabledVar->SetBool(true);
		D3DXMATRIX s;
		D3DXMatrixScaling(&s, 5.0f, 5.0f, 1.0f);
		texMtx = s;
		D3DXMatrixIdentity(&texMtx);
		mfxTexMtxVar->SetMatrix((float*)&texMtx);
		pass->Apply(0);
		mPlane.draw();
    }

	mSky.draw(mWVP);

	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	md3dDevice->RSSetState(0);
	mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK);

	mSwapChain->Present(0, 0);
}
Exemple #15
0
void ColoredCubeApp::drawScene()
{
	D3DApp::drawScene();

	// Restore default states, input layout and primitive topology 
	// because mFont->DrawText changes them.  Note that we can 
	// restore the default states by passing null.
	md3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
    md3dDevice->IASetInputLayout(mVertexLayout);

	mfxEyePosVar->SetRawValue(&player.getPosition(), 0, sizeof(D3DXVECTOR3));

	//set the number of lights to use
	mfxNumLights->SetInt(numLights);

	// set the light array
	lights[0] = flashLightObject.lightSource;
	//lights[2] = lightObject1.getLight();
	if(gamestate == level2)
	{
		for(int i = 0; i < ghosts.getNumEnemies(); i++)
		{
			lights[2+i] = ghosts.getEnemies()[i].getLight();
		}
	}
	for(int i = 0; i < numLightObjects; i++)
	{
		lights[2+ghosts.getNumEnemies()+i] = lamps[i].getLight();
	}
	lights[numLights-1] = endLight;

	mfxLightVar->SetRawValue(&lights[0], 0, numLights*sizeof(Light));
 
	// Don't transform texture coordinates, so just use identity transformation.
	D3DXMATRIX texMtx;
	D3DXMatrixIdentity(&texMtx);
	mfxTexMtxVar->SetMatrix((float*)&texMtx);

	// set the point to the shader technique
	D3D10_TECHNIQUE_DESC techDesc;
	mTech->GetDesc(&techDesc);

	//draw the maze
	maze.draw(mTech,mView,mProj);
	
	//draw the keys
	if(gamestate == level1)
	{
		for(int i = 0; i < totalKeys; i++)
		{
			keyObject[i].draw(mView,mProj,mTech);
		}
	}

	//draw the end cube
	endCube.draw(mView,mProj,mTech);

	//draw the origin
	origin.draw(mView, mProj, mTech);
	
	for(int i = 0; i < numLightObjects; i++)
	{
		lamps[i].draw(mView,mProj,mTech);
	}

	for(int i = 0; i < numBatteries; i++)
	{
		batteries[i].draw(mView,mProj,mTechColor2);
	}

	//flashLightObject.draw(mView,mProj,mTechColor2);
	//flashLightObject.hitBox.draw(mView,mProj,mTechColor2);
	
	//batteryObject.draw(mView,mProj,mTechColor2);
	//player.draw(mView,mProj,mTechColor2);
	ghosts.draw(mView,mProj,mTech);

	/*floor.draw(mView, mProj, mTech);
	wall1.draw(mView, mProj, mTech);
	wall2.draw(mView, mProj, mTech);
	wall3.draw(mView, mProj, mTech);
	wall4.draw(mView, mProj, mTech);*/
	//lightObject1.draw(mView,mProj,mTech);

	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	mFont->DrawText(0, mTimer.c_str(), -1, &R, DT_NOCLIP, BLUE);
	mSwapChain->Present(0, 0);
}
void ColoredCubeApp::drawScene()
{
	D3DApp::drawScene();
	incrementedYMargin = 5;
	int lineHeight = 20;
	if(!startScreen && !endScreen)
	{
		// Restore default states, input layout and primitive topology 
		// because mFont->DrawText changes them.  Note that we can 
		// restore the default states by passing null.
		md3dDevice->OMSetDepthStencilState(0, 0);
		float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
		md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
		md3dDevice->IASetInputLayout(mVertexLayout);

		// set some variables for the shader
		int foo[1];
		foo[0] = 0;
		// set the point to the shader technique
		D3D10_TECHNIQUE_DESC techDesc;
		mTech->GetDesc(&techDesc);

		//Set mVP to be view*projection, so we can pass that into GO::draw(..)
		mVP = mView*mProj;
		for (int i = 0; i < ragePickups.size(); i++)
			ragePickups[i].draw(mfxWVPVar, mTech, &mVP);

		//setting the color flip variable in the shader
		mfxFLIPVar->SetRawValue(&foo[0], 0, sizeof(int));

		//draw the lines
		//drawLine(&xLine);
		//drawLine(&yLine);
		//drawLine(&zLine);

	
		/*****************************************
		Walls!
		*******************************************/
		for(int i=0; i<gameNS::NUM_WALLS; i++)walls[i].draw(mfxWVPVar, mTech, &mVP);
		for(int i=0; i<gameNS::NUM_MONEY; i++) money[i].draw(mfxWVPVar, mTech, &mVP);
	
		////draw the boxes
		//test.draw(mfxWVPVar, mTech, &mVP);
		floor.draw(mfxWVPVar, mTech, &mVP);
		player.draw(mfxWVPVar, mTech, &mVP);
		//pBullet.draw(mfxWVPVar, mTech, &mVP);
		//Player & bullet classes implemented
		//gravball.draw(mfxWVPVar, mTech, &mVP);
		//gameObject1.draw(mfxWVPVar, mTech, &mVP);	

		/*****************************************
		Enemy Cameras
		*******************************************/
		for(int i=0; i<gameNS::NUM_CAMS; i++){
			enemyCam[i].draw(mfxWVPVar, mTech, &mVP);
	//		enBullet[i].draw(mfxWVPVar, mTech, &mVP);
			for(int j=0; j<enBullets[i].size(); j++)
			{
				enBullets[i][j]->draw(mfxWVPVar, mTech, &mVP);
			}
		}

		// We specify DT_NOCLIP, so we do not care about width/height of the rect.
		RECT R = {5, 5, 0, 0};
		//mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK);
		for (int i = 0; i < debugText.getSize(); i++)
		{
			int xMargin = debugText.lines[i].x;
			int yMargin = debugText.lines[i].y;

			if (xMargin == -1)
				xMargin = 5;
			if (yMargin == -1) {
				yMargin = incrementedYMargin;
				incrementedYMargin += lineHeight;
			}

			
		}
		//RECT POS = {xMargin, yMargin, 0, 0};
		RECT POS = {5, 5, 0, 0};

		std::wostringstream outs;   
		outs.precision(6);
		//outs << debugText.lines[i].s.c_str();
		outs << L"Score: " << score;
		std::wstring sc = outs.str();

		mFont->DrawText(0, sc.c_str(), -1, &POS, DT_NOCLIP, WHITE);
	}
	else if(startScreen)
	{		
		for (int i = 0; i < sText.getSize(); i++)
		{
			int xMargin = sText.lines[i].x;
			int yMargin = sText.lines[i].y;

			if (xMargin == -1)
				xMargin = 5;
			if (yMargin == -1) {
				yMargin = incrementedYMargin;
				incrementedYMargin += lineHeight;
			}

			RECT POS = {xMargin, yMargin, 0, 0};

			std::wostringstream outs;   
			outs.precision(6);
			outs << sText.lines[i].s.c_str();

			mFont->DrawText(0, outs.str().c_str(), -1, &POS, DT_NOCLIP, WHITE);
		}
	}
	else
	{
		for (int i = 0; i < eText.getSize(); i++)
		{
			int xMargin = eText.lines[i].x;
			int yMargin = eText.lines[i].y;

			if (xMargin == -1)
				xMargin = 5;
			if (yMargin == -1) {
				yMargin = incrementedYMargin;
				incrementedYMargin += lineHeight;
			}

			RECT POS = {xMargin, yMargin, 0, 0};

			std::wostringstream outs;   
			outs.precision(6);
			outs << eText.lines[i].s.c_str();

			mFont->DrawText(0, outs.str().c_str(), -1, &POS, DT_NOCLIP, WHITE);
		}
		//RECT POS = {xMargin, yMargin, 0, 0};
		RECT POS = {300, 350, 0, 0};

		std::wostringstream outs;
		outs.precision(6);
		//outs << debugText.lines[i].s.c_str();
		outs << L"Score: " << score;
		std::wstring sc = outs.str();

		mFont->DrawText(0, sc.c_str(), -1, &POS, DT_NOCLIP, WHITE);
	}
	mSwapChain->Present(0, 0);
}
Exemple #17
0
void ColoredCubeApp::drawScene()
{
	D3DApp::drawScene();

	// Restore default states, input layout and primitive topology 
	// because mFont->DrawText changes them.  Note that we can 
	// restore the default states by passing null.
	md3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
    md3dDevice->IASetInputLayout(mVertexLayout);

	// set some variables for the shader
	int foo[1];
	foo[0] = 0;
	// set the point to the shader technique
	D3D10_TECHNIQUE_DESC techDesc;
	mTech->GetDesc(&techDesc);

	//setting the color flip variable in the shader
	mfxFLIPVar->SetRawValue(&foo[0], 0, sizeof(int));

	//draw the lines
	mWVP = xLine.getWorldMatrix()*mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
	xLine.setMTech(mTech);
	xLine.draw();
	
	mWVP = yLine.getWorldMatrix() *mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
	yLine.setMTech(mTech);
	yLine.draw();

	mWVP = zLine.getWorldMatrix() *mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
	zLine.setMTech(mTech);
	zLine.draw();

	//draw the quad using the "old" method
	//compare how messy this is compared to the objectified geometry classes
	mWVP = quad1.getWorld()*mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
    mTech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        mTech->GetPassByIndex( p )->Apply(0);
       quad1.draw();
    }

	mWVP = quad2.getWorld()*mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
    mTech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        mTech->GetPassByIndex( p )->Apply(0);
       quad2.draw();
    }

	mWVP = quad3.getWorld()*mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
    mTech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        mTech->GetPassByIndex( p )->Apply(0);
       quad3.draw();
    }

	mWVP = quad4.getWorld()*mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
    mTech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        mTech->GetPassByIndex( p )->Apply(0);
       quad4.draw();
    }

	mWVP = quad5.getWorld()*mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
    mTech->GetDesc( &techDesc );
	for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        mTech->GetPassByIndex( p )->Apply(0);
       quad5.draw();
    }

	for(int i = 0; i < WALL_SIZE; ++i) {
		mWVP = wall[i].getWorld()*mView*mProj;
		mfxWVPVar->SetMatrix((float*)&mWVP);
		mTech->GetDesc( &techDesc );
		for(UINT p = 0; p < techDesc.Passes; ++p)
		{
			mTech->GetPassByIndex( p )->Apply(0);
		   wall[i].draw();
		}
	}

	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK);
	mSwapChain->Present(0, 0);
}
void ColoredCubeApp::drawScene()
{
	D3DApp::drawScene();

	// Restore default states, input layout and primitive topology 
	// because mFont->DrawText changes them.  Note that we can 
	// restore the default states by passing null.
	md3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
    md3dDevice->IASetInputLayout(mVertexLayout);
	
	D3DXVECTOR3 pos(0.0f,45.0f,-50.0f);
	// set lighting shader variables
	mfxEyePosVar->SetRawValue(&pos, 0, sizeof(Vector3));
	mfxLightVar->SetRawValue(&lights[0], 0, sizeof(Light));
	mfxLightType->SetInt(lightType);

	// set some variables for the shader
	// set the point to the shader technique
	D3D10_TECHNIQUE_DESC techDesc;
	mTech->GetDesc(&techDesc);


	//setting the color flip variable in the shader

	//draw the floor
	floor.draw(mView, mProj, mfxWVPVar, mfxWorldVar, mTech);

	////// New Stuff added by Steve //////
	mWVP = player.getWorldMatrix()  *mView*mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
	mfxWorldVar->SetMatrix((float*)&player.getWorldMatrix());
	player.setMTech(mTech);
	player.draw();

	for (int i = 0; i < numberOfObstacles; i++) {
		mWVP = obstacles[i].getWorldMatrix() * mView * mProj;
		mfxWVPVar->SetMatrix((float*)&mWVP);
		mfxWorldVar->SetMatrix((float*)&obstacles[i].getWorldMatrix());
		obstacles[i].setMTech(mTech);
		obstacles[i].draw();
	}

	//Spectrum HUD
	for(int i = 0; i < 6; i++) {
		D3DXMATRIX a;
		D3DXMatrixRotationY(&a, 1.573f);
		mWVP = a * spectrum[i].getWorldMatrix() * mView * mProj;
		mfxWVPVar->SetMatrix((float*)&mWVP);
		mfxWorldVar->SetMatrix((float*)&spectrum[i].getWorldMatrix());
		spectrum[i].setMTech(mTech);
		spectrum[i].draw();
	}
	mWVP = cursor.getWorldMatrix() * mView * mProj;
	mfxWVPVar->SetMatrix((float*)&mWVP);
	mfxWorldVar->SetMatrix((float*)&cursor.getWorldMatrix());
	cursor.setMTech(mTech);
	cursor.draw();


	
	//////////////////////////////////////

	/////Text Drawing Section
	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	RECT R1 = {0, 0, 800, 600};
	RECT R2 = {0, 540, 800, 600};

	std::wostringstream outs;  
	
	outs.precision(6);
	string Hud = score.getString();

	/*outs << score.getString() << L"\n";
	outs << L"Blobs Available: " << ammo << L"\n";
	outs << L"Gallons Left: " << lives;
	std::wstring text = outs.str();
	mFont->DrawText(0, text.c_str(), -1, &R, DT_NOCLIP, BLACK);*/
	timesNew.draw(Hud, Vector2(5, 5));
	if (gameOver)
	{
		mFont->DrawText(0, L"Game Over!", -1, &R1, DT_CENTER | DT_VCENTER, BLACK);
	}
	float gameTime = mTimer.getGameTime();
	if (gameTime < 3.0f)
	{
		mFont->DrawText(0, L"Move your Box LEFT and RIGHT with A & D to avoid hitting the obstacles", -1, &R2, DT_CENTER | DT_VCENTER, BLACK);
	}
	else if (gameTime < 6.0f)
	{
		mFont->DrawText(0, L"Change the color of your Box by pressing the J and L keys.", -1, &R2, DT_CENTER | DT_VCENTER, BLACK);
	}
	else if (gameTime < 9.0f)
	{
		mFont->DrawText(0, L"The closer the color of your cube is to the floor, the higher the score multiplier!", -1, &R2, DT_CENTER | DT_VCENTER, BLACK);
	}
	if (activeMessage)
	{
		mFont->DrawText(0, message.c_str(), -1, &R2, DT_CENTER | DT_VCENTER, BLACK);
	}
	

	mSwapChain->Present(0, 0);
}
void WaterLandscapeDemoScene::OnRender(DXRenderer& dx, TimeT currentTime, TimeT deltaTime) const
{
    // Set the device up for rendering our landscape mesh.
    dx.GetDevice()->IASetInputLayout(mVertexLayout.Get());
    dx.GetDevice()->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    D3DXMATRIX projectionMatrix = mCamera->GetProjectionMatrix();
    
    // Load the landscape technique.
    ID3D10EffectTechnique * pTechnique = mLandscapeEffect->GetTechniqueByName("LandscapeTechnique");

    // Grab the shader variables we'll need.
    ID3D10EffectMatrixVariable * pWVP = mLandscapeEffect->GetVariableByName("gWVP")->AsMatrix();
    ID3D10EffectMatrixVariable * pWorldVar = mLandscapeEffect->GetVariableByName("gWorld")->AsMatrix();
    ID3D10EffectVariable * pFxEyePosVar = mLandscapeEffect->GetVariableByName("gEyePosW");
    ID3D10EffectVariable * pFxLightVar = mLandscapeEffect->GetVariableByName("gLight");
    ID3D10EffectScalarVariable * pFxLightType = mLandscapeEffect->GetVariableByName("gLightType")->AsScalar();

    // Set per frame constants
    D3DXVECTOR3 eyePos = mCamera->Position();
    D3DMATRIX view = mCamera->GetViewMatrix();
    Light selectedLight = mLights[mLightType];

    pFxEyePosVar->SetRawValue(&eyePos, 0, sizeof(D3DXVECTOR3));
    pFxLightVar->SetRawValue(&selectedLight, 0, sizeof(Light));
    pFxLightType->SetInt(mLightType);

    // Load the effect technique for cube
    D3D10_TECHNIQUE_DESC technique;
    pTechnique->GetDesc(&technique);

    // Apply the landscape technique.
    D3DXMATRIX landTransform;
    D3DXMATRIX waterTransform;

    D3DXMatrixIdentity(&landTransform);
    D3DXMatrixIdentity(&waterTransform);

    for (unsigned int passIndex = 0; passIndex < technique.Passes; ++passIndex)
    {
        ID3D10EffectPass * pPass = pTechnique->GetPassByIndex(passIndex);
        dx.SetDefaultRendering();

        // Draw the landscape mesh first
        D3DXMATRIX wvp = landTransform * view * projectionMatrix;

        pWVP->SetMatrix((float*)&wvp);
        pWorldVar->SetMatrix((float*)&landTransform);

        pPass->Apply(0);
        mTerrainMesh->Draw(dx.GetDevice());

        // Draw the water mesh
        wvp = waterTransform * view * projectionMatrix;

        pWVP->SetMatrix((float*)&wvp);
        pWorldVar->SetMatrix((float*)&waterTransform);

        pPass->Apply(0);
        mWaterMesh->Draw(dx.GetDevice());
    }
}
Exemple #20
0
//--------------------------------------------------------------------------------------
// RenderBalls
//--------------------------------------------------------------------------------------
void RenderBalls( ID3D10Device* pd3dDevice )
{
    D3DXMATRIX mWorld;
    D3DXMatrixIdentity( &mWorld );

    D3DXVECTOR3 vEye;
    D3DXVECTOR3 vDir;
    D3DXMATRIX mCamWorld;
    D3DXMATRIX mView;
    D3DXMATRIX mProj;
    GetCameraData( &mCamWorld, &mView, &mProj, &vEye, &vDir );
    D3DXMATRIX mWVP = mCamWorld * mView * mProj;

    g_pmWorldViewProj->SetMatrix( ( float* )&mWVP );
    g_pmWorld->SetMatrix( ( float* )&mWorld );

    pd3dDevice->IASetInputLayout( g_pBallDecl10 );

    ID3D10EffectTechnique* pTechnique = g_pRenderBall;
	
    // set vb streams
    ID3D10Buffer* pBuffers[2];
    pBuffers[0] = g_BallMesh.GetVB10( 0, 0 );
    pBuffers[1] = g_pStreamDataVB10;
    UINT strides[2];
    strides[0] = g_BallMesh.GetVertexStride( 0, 0 );
    strides[1] = sizeof( D3DXVECTOR3 );
    UINT offsets[2] = {0,0};
    pd3dDevice->IASetVertexBuffers( 0, 2, pBuffers, strides, offsets );

    SetNumVisibleBalls( g_NumVisibleBalls );

    // Set our index buffer as well
    pd3dDevice->IASetIndexBuffer( g_BallMesh.GetIB10( 0 ), g_BallMesh.GetIBFormat10( 0 ), 0 );

    SDKMESH_SUBSET* pSubset = NULL;
    D3D10_PRIMITIVE_TOPOLOGY PrimType;
    D3D10_TECHNIQUE_DESC techDesc;
    pTechnique->GetDesc( &techDesc );

    for( UINT p = 0; p < techDesc.Passes; ++p )
    {
        for( UINT subset = 0; subset < g_BallMesh.GetNumSubsets( 0 ); subset++ )
        {
            pSubset = g_BallMesh.GetSubset( 0, subset );

            PrimType = g_BallMesh.GetPrimitiveType10( ( SDKMESH_PRIMITIVE_TYPE )pSubset->PrimitiveType );
            pd3dDevice->IASetPrimitiveTopology( PrimType );

            pTechnique->GetPassByIndex( p )->Apply( 0 );

            UINT IndexCount = ( UINT )pSubset->IndexCount;
            UINT IndexStart = ( UINT )pSubset->IndexStart;
            UINT VertexStart = ( UINT )pSubset->VertexStart;
            //UINT VertexCount = (UINT)pSubset->VertexCount;

            pd3dDevice->DrawIndexedInstanced( IndexCount, g_NumVisibleBalls, IndexStart, VertexStart, 0 );
        }
    }

    pBuffers[0] = NULL;
    pBuffers[1] = NULL;
    pd3dDevice->IASetVertexBuffers( 0, 2, pBuffers, strides, offsets );
}
//--------------------------------------------------------------------------------------
void RenderSkinnedMesh( ID3D10Device* pd3dDevice, CDXUTSDKMesh* pAnimMesh, double fTime, bool bMotionBlur )
{
    ID3D10Buffer* pBuffers[1];
    UINT stride[1];
    UINT offset[1] = { 0 };

    g_pfFadeDist->SetFloat( g_fWarriorFade );
    // Set vertex Layout
    pd3dDevice->IASetInputLayout( g_pSkinnedVertexLayout );

    // Render the meshes
    for( UINT m = 0; m < pAnimMesh->GetNumMeshes(); m++ )
    {
        pBuffers[0] = pAnimMesh->GetVB10( m, 0 );
        stride[0] = ( UINT )pAnimMesh->GetVertexStride( m, 0 );
        offset[0] = 0;

        pd3dDevice->IASetVertexBuffers( 0, 1, pBuffers, stride, offset );
        pd3dDevice->IASetIndexBuffer( pAnimMesh->GetIB10( m ), pAnimMesh->GetIBFormat10( m ), 0 );

        SDKMESH_SUBSET* pSubset = NULL;
        SDKMESH_MATERIAL* pMat = NULL;
        D3D10_PRIMITIVE_TOPOLOGY PrimType;

        // Set the bone matrices
        double fStepSize = 1.0f / 60.0f;
        double fTimeShift = fTime - MAX_TIME_STEPS * fStepSize;
        for( int s = 0; s < MAX_TIME_STEPS; s++ )
        {
            fTimeShift += fStepSize;

            D3DXMATRIX mIdentity;
            D3DXMatrixIdentity( &mIdentity );
            pAnimMesh->TransformMesh( &mIdentity, fTimeShift );

            for( UINT i = 0; i < pAnimMesh->GetNumInfluences( m ); i++ )
            {
                const D3DXMATRIX* pMatrix = pAnimMesh->GetMeshInfluenceMatrix( m, i );
                g_pmBoneWorld->SetMatrixArray( ( float* )pMatrix, MAX_BONE_MATRICES * s + i, 1 );
            }
        }

        D3D10_TECHNIQUE_DESC techDesc;
        ID3D10EffectTechnique* pTech;
        if( !bMotionBlur )
        {
            pTech = g_pRenderSkinnedScene;
            pTech->GetDesc( &techDesc );
            for( UINT p = 0; p < techDesc.Passes; ++p )
            {
                for( UINT subset = 0; subset < pAnimMesh->GetNumSubsets( m ); subset++ )
                {
                    pSubset = pAnimMesh->GetSubset( m, subset );

                    PrimType = pAnimMesh->GetPrimitiveType10( ( SDKMESH_PRIMITIVE_TYPE )pSubset->PrimitiveType );
                    pd3dDevice->IASetPrimitiveTopology( PrimType );

                    pMat = pAnimMesh->GetMaterial( pSubset->MaterialID );
                    if( pMat )
                    {
                        g_ptxDiffuse->SetResource( pMat->pDiffuseRV10 );
                    }

                    pTech->GetPassByIndex( p )->Apply( 0 );
                    pd3dDevice->DrawIndexed( ( UINT )pSubset->IndexCount, ( UINT )pSubset->IndexStart,
                                             ( UINT )pSubset->VertexStart );
                }
            }
        }
        else
        {
            pTech = g_pRenderSkinnedMotionBlur;
            pTech->GetDesc( &techDesc );
            for( UINT p = 0; p < techDesc.Passes; ++p )
            {
                for( UINT subset = 0; subset < pAnimMesh->GetNumSubsets( m ); subset++ )
                {
                    pSubset = pAnimMesh->GetSubset( m, subset );

                    PrimType = pAnimMesh->GetPrimitiveType10( ( SDKMESH_PRIMITIVE_TYPE )pSubset->PrimitiveType );
                    pd3dDevice->IASetPrimitiveTopology( PrimType );

                    pMat = pAnimMesh->GetMaterial( pSubset->MaterialID );
                    if( pMat )
                    {
                        g_ptxDiffuse->SetResource( pMat->pDiffuseRV10 );
                    }

                    pTech->GetPassByIndex( p )->Apply( 0 );
                    pd3dDevice->DrawIndexed( ( UINT )pSubset->IndexCount, ( UINT )pSubset->IndexStart,
                                             ( UINT )pSubset->VertexStart );
                }
            }
        }
    }//nummeshes
}
void ColoredCubeApp::drawScene()
{
    int foo[1] = {0};
    switch (gsm->getGameState()) {
    case GameStateManager::START_GAME:
    {
        foo[0] = 1;
        break;
    }
    case GameStateManager::IN_GAME:
    {
        foo[0] = 0;
        break;
    }
    case GameStateManager::END_GAME:
    {
        foo[0] = 1;
        break;
    }
    default:
        foo[0] = 0;
        break;
    }

    mfxBlack_WhiteVar->SetRawValue(&foo[0], 0, sizeof(int));

    D3DApp::drawScene();

    // Restore default states, input layout and primitive topology
    // because mFont->DrawText changes them.  Note that we can
    // restore the default states by passing null.
    md3dDevice->OMSetDepthStencilState(0, 0);
    float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
    md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
    md3dDevice->IASetInputLayout(mVertexLayout);
    md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    //Get Camera viewMatrix
    mView = camera.getViewMatrix();
    mProj = camera.getProjectionMatrix();

    // set constants
    mWVP = mView*mProj;
    mfxWVPVar->SetMatrix((float*)&mWVP);

    D3D10_TECHNIQUE_DESC techDesc;
    mTech->GetDesc( &techDesc );
    for(UINT p = 0; p < techDesc.Passes; ++p)
    {
        mTech->GetPassByIndex( p )->Apply(0);

        //mBox.draw();
        //mAxes.draw();
        //mLine.draw();
        //mTriangle.draw();
        mQuad.draw();
        //particleBox.draw();
    }

    mWVP = gameObject1.getWorldMatrix()  *mView*mProj;
    mfxWVPVar->SetMatrix((float*)&mWVP);
    gameObject1.setMTech(mTech);
    gameObject1.draw();

    for (int i = 0; i < MAX_NUM_ENEMIES; i++)
    {
        mWVP = enemyObjects[i].getWorldMatrix()  *mView*mProj;
        mfxWVPVar->SetMatrix((float*)&mWVP);
        enemyObjects[i].setMTech(mTech);
        enemyObjects[i].draw();
    }


    for (int i = 0; i < MAX_NUM_BULLETS; i++)
    {
        mWVP = playerBullets[i].getWorldMatrix()  *mView*mProj;
        mfxWVPVar->SetMatrix((float*)&mWVP);
        playerBullets[i].setMTech(mTech);
        playerBullets[i].draw();
    }

    for (int i = 0; i < MAX_NUM_EXP_PARTICLES; i++)
    {
        mWVP = particles[i].getWorldMatrix()  *mView*mProj;
        mfxWVPVar->SetMatrix((float*)&mWVP);
        particles[i].setMTech(mTech);
        particles[i].draw();
    }

    for (int i = 0; i < MAX_NUM_STARS; i++)
    {
        mWVP = stars[i].getWorldMatrix()  *mView*mProj;
        mfxWVPVar->SetMatrix((float*)&mWVP);
        stars[i].setMTech(mTech);
        stars[i].draw();
    }

    if(gsm->getGameState() == GameStateManager::END_GAME && score > 0) {
        std::wostringstream gameOverString;
        gameOverString.precision(6);
        gameOverString << "YOU WIN!\n";
        gameOverString << "Score: " << score;
        gameOverString << "\nSpacebar to\nplay again.";
        finalScore = gameOverString.str();
        RECT R2 = {GAME_WIDTH/2 - 100, GAME_HEIGHT/2 - 100, 0, 0};
        endFont->DrawText(0, finalScore.c_str(), -1, &R2, DT_NOCLIP, GREEN);
    }
    else if(gsm->getGameState() == GameStateManager::END_GAME) {
        std::wostringstream gameOverString;
        gameOverString.precision(6);
        gameOverString << "YOU DIED!\n";
        gameOverString << "Score: " << score;
        gameOverString << "\nSpacebar to\nplay again.";
        finalScore = gameOverString.str();
        RECT R2 = {GAME_WIDTH/2 - 100, GAME_HEIGHT/2 - 100, 0, 0};
        endFont->DrawText(0, finalScore.c_str(), -1, &R2, DT_NOCLIP, GREEN);
    }
    if(gsm->getGameState() == GameStateManager::START_GAME) {
        std::wostringstream gameOverString;
        gameOverString.precision(6);
        gameOverString << "Controls:\n";
        gameOverString << "Move: A and D.\n";
        gameOverString << "Shoot: Enter \n";
        gameOverString << "Hit the spacebar to begin.";
        finalScore = gameOverString.str();
        RECT R2 = {50, GAME_HEIGHT/2 - 100, 0, 0};
        scoreFont->DrawText(0, finalScore.c_str(), -1, &R2, DT_NOCLIP, GREEN);
    }
    else {
        if (gsm->getGameState() == GameStateManager::IN_GAME) {
            std::wostringstream scoreString;
            scoreString.precision(6);
            scoreString << score;
            finalScore = scoreString.str();
            RECT R2 = {GAME_WIDTH/2 + 50, GAME_HEIGHT + 65, 0, 0};
            scoreFont->DrawText(0, finalScore.c_str(), -1, &R2, DT_NOCLIP, GREEN);
        }
    }


    std::wostringstream ts;
    ts.precision(6);
    ts << secondsRemaining;
    timeString = ts.str();
    RECT R3 = {GAME_WIDTH/2 + 50, 20, 0, 0};
    scoreFont->DrawText(0, timeString.c_str(), -1, &R3, DT_NOCLIP, GREEN);

    // We specify DT_NOCLIP, so we do not care about width/height of the rect.
    RECT R = {5, 5, 0, 0};
    //mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, BLACK);




    mSwapChain->Present(0, 0);
}