Exemple #1
0
void Material::LoadEffect(void)
{
	//Compile effect
	m_pEffect = MyServiceLocator::GetInstance()->GetService<ResourceService>()->Load<ID3D10Effect>(m_EffectFileName);

	//Get effect info
	D3D10_EFFECT_DESC desc;
	m_pEffect->GetDesc(&desc);

	//Load techniques
	for(unsigned int i=0; i < desc.Techniques; ++i)
		m_Techniques.push_back( new EffectTechnique(m_pEffect->GetTechniqueByIndex(i), i) );
	
	//Load effect variables
	for(unsigned int i=0; i < desc.GlobalVariables; ++i){
		ID3D10EffectVariable* pVariable = m_pEffect->GetVariableByIndex(i);

		D3D10_EFFECT_VARIABLE_DESC varDesc;
		pVariable->GetDesc(&varDesc);
		if(varDesc.Semantic != nullptr)
			m_EffectVariables.insert(make_pair(StringToTstring(varDesc.Semantic), pVariable));
	}

	//Set default active technique
	SetActiveTechnique(0);
}
Exemple #2
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 #3
0
VectorConstant EffectTechnique::GetVectorConstant(const char* name)
{
	VectorConstant result;

	if( IsValid() )
	{
		ID3D10EffectVariable* var =  m_parent->m_effect->GetVariableByName(name);
		if( var )
		{
			result.m_variable = var->AsVector();
		}
	}

	return result;
}
Exemple #4
0
TextureSampler EffectTechnique::GetSamplerByName(const char* name)
{
	TextureSampler result;

	ID3D10EffectVariable* var = m_parent->m_effect->GetVariableByName(name);
	if( var && var->IsValid() )
	{
		result.m_sampler = var->AsShaderResource();
		result.m_effect = this;
	}
	else
	{
		printf("Unknown shader sampler '%s\n", name);
	}

	return result;
}
Exemple #5
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);
}
Exemple #6
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);
}
	bool DirectX10Renderer::RenderSprites(SpriteType type, SpriteVector* sprites)
	{
		if(!sprites)
		{
			return true;
		}

		int numSprites = sprites->size();
		if(numSprites == 0)
		{
			return true;
		}


		//draw sprites
		switch(type)
		{
		case SPRITE_TYPE_TILE:
			pColorMap->SetResource(m_SpriteTexture);
			break;

		case SPRITE_TYPE_TEXT:
			pColorMap->SetResource(m_FontTexture);
			break;

		default:
			pColorMap->SetResource(m_SpriteTexture);
			break;

		}

		// make sure the shader knows the screen-size so it can scale the sprites correctly
		ID3D10EffectVariable* em = m_SpriteEffect->GetVariableByName("screenDimensions");
		int dims[2];
		dims[0] = m_ScreenWidth;
		dims[1] = m_ScreenHeight;
		em->SetRawValue(&dims, 0, sizeof(dims));

		// clear the current sprite buffer
		int remainingSprites = sprites->size();
		SpriteVector spritesToRender;
		SpriteIterator startSprite;
		SpriteIterator endSprite;
		startSprite = sprites->begin();
		while(remainingSprites > 0)
		{
			// get the first batch of sprites
			endSprite = sprites->end();
			if(remainingSprites > SPRITE_BUFFER_SIZE)
			{
				endSprite = startSprite + SPRITE_BUFFER_SIZE;
			}

			std::copy(startSprite, endSprite, std::back_inserter(spritesToRender));

			// draw this batch of sprites
			RenderSpriteRange(&spritesToRender);

			// get ready for the next iteration
			startSprite = endSprite;
			remainingSprites -= SPRITE_BUFFER_SIZE;
			spritesToRender.clear();
		}
		
		return true;
	}
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 #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));

	//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 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);
}
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());
    }
}
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 #14
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);
}