예제 #1
0
    RenderTargetTexture2D::RenderTargetTexture2D(GraphicsDevice* graphicsDevice, int width, int height)
        : Texture2D(graphicsDevice, width, height, width, height, A8R8G8B8Pixels),
          d3dSurface(nullptr)
    {
        BBAssert(GetGraphicsDevice()->GetD3DDevice() != nullptr);

        IDirect3DTexture9* newD3DTexture = nullptr;
        HRESULT result = D3DXCreateTexture(GetGraphicsDevice()->GetD3DDevice(), width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &newD3DTexture);
        if (result == D3D_OK)
        {
            D3DSURFACE_DESC surfaceDesc;
            if (newD3DTexture->GetLevelDesc(0, &surfaceDesc) == D3D_OK)
                Setup(newD3DTexture, width, height, static_cast<int>(surfaceDesc.Width), static_cast<int>(surfaceDesc.Height), A8R8G8B8Pixels);
            else
                Setup(newD3DTexture, width, height, width, height, A8R8G8B8Pixels);

            newD3DTexture->GetSurfaceLevel(0, &d3dSurface);
            
            IncreaseRevision();
            SetStatus(CompletedStatus);
        }
        else
        {
            IncreaseRevision();
            SetStatus(FaultStatus);
        }
    }
예제 #2
0
void GameManager::LoadDebugComponents()
{
	Font* debugFont = _resourceManager.GetFont("../data/fonts/SourceSansPro-Bold.otf");
	debugFont->SetFontSize(12);
	_resourceManager.StoreAndInitMaterial("FontMaterial", 
										new FontMaterial(_resourceManager.GetShaderProgram("Font2D", "../data/FontMaterial.vert", "../data/FontMaterial.frag"),
										Color::Yellow()));

	GameObject* FPS = new GameObject();
	FPS->GetTransform().SetPosition(Vector3(10,16,0));
	FPS->AddComponent(new FontRenderer(FPS,_resourceManager.GetMaterial("FontMaterial"), debugFont, "FPS:", GetGraphicsDevice()));
	FPS->AddComponent(new PrintFPS(FPS));
	AddGameObject(FPS);


	GameObject* avgFPS = new GameObject();
	avgFPS->GetTransform().SetPosition(Vector3(10,32,0));
	avgFPS->AddComponent(new FontRenderer(avgFPS,_resourceManager.GetMaterial("FontMaterial"), debugFont, "Avg FPS:", GetGraphicsDevice()));
	avgFPS->AddComponent(new PrintAvgFPS(avgFPS));
	AddGameObject(avgFPS);

    GameObject* drawCall3D = new GameObject();
	drawCall3D->GetTransform().SetPosition(Vector3(10,48,0));
	drawCall3D->AddComponent(new FontRenderer(drawCall3D,_resourceManager.GetMaterial("FontMaterial"), debugFont, "Draw Calls(3D):", GetGraphicsDevice()));
	drawCall3D->AddComponent(new Print3DDrawCalls(drawCall3D, &_renderEngine));
	AddGameObject(drawCall3D);

	GameObject* drawCall2D = new GameObject();
	drawCall2D->GetTransform().SetPosition(Vector3(10,64,0));
	drawCall2D->AddComponent(new FontRenderer(drawCall2D,_resourceManager.GetMaterial("FontMaterial"), debugFont, "Draw Calls(2D):", GetGraphicsDevice()));
	drawCall2D->AddComponent(new Print2DDrawCalls(drawCall2D, &_renderEngine2D));
	AddGameObject(drawCall2D);

	GameObject* triCount3D = new GameObject();
	triCount3D->GetTransform().SetPosition(Vector3(10,80,0));
	triCount3D->AddComponent(new FontRenderer(triCount3D,_resourceManager.GetMaterial("FontMaterial"), debugFont, "Triangles(3D):", GetGraphicsDevice()));
	triCount3D->AddComponent(new Print3DTriangles(triCount3D, &_renderEngine));
	AddGameObject(triCount3D);

	GameObject* triCount2D = new GameObject();
	triCount2D->GetTransform().SetPosition(Vector3(10,96,0));
	triCount2D->AddComponent(new FontRenderer(triCount2D,_resourceManager.GetMaterial("FontMaterial"), debugFont, "Triangles(2D):", GetGraphicsDevice()));
	triCount2D->AddComponent(new Print2DTriangles(triCount2D, &_renderEngine2D));
	AddGameObject(triCount2D);

	GameObject* drawDebugObjects = new GameObject();
	drawDebugObjects->GetTransform().SetPosition(Vector3(10,704,0));
	drawDebugObjects->AddComponent(new FontRenderer(drawDebugObjects,_resourceManager.GetMaterial("FontMaterial"), debugFont, 
		"Press 'B' to toggle bounding boxes", GetGraphicsDevice()));
	AddGameObject(drawDebugObjects);

	GameObject* drawWireframe = new GameObject();
	drawWireframe->GetTransform().SetPosition(Vector3(10,688,0));
	drawWireframe->AddComponent(new FontRenderer(drawWireframe,_resourceManager.GetMaterial("FontMaterial"), debugFont, 
		"Press 'N' to toggle wireframe", GetGraphicsDevice()));
	AddGameObject(drawWireframe);
}
예제 #3
0
파일: Game1.cpp 프로젝트: iamcsharper/nxna
void Game1::Update(const Nxna::GameTime& time)
{
	pos += vel * time.ElapsedGameTime;

	Nxna::Graphics::Viewport vp = GetGraphicsDevice()->GetViewport();
    
    /*Nxna::Rectangle vp;
    vp.X = 0;
    vp.Y = 0;
    vp.Width = 100;
    vp.Height = 100;*/
    
	if (pos.X - width * 0.5f < 0)
	{
		pos.X = width * 0.5f;
		vel.X = -vel.X;
	}
	else if (pos.X + width * 0.5f > vp.Width)
	{
		pos.X = vp.Width - width * 0.5f;
		vel.X = -vel.X;
	}
	if (pos.Y - height * 0.5f < 0)
	{
		pos.Y = height * 0.5f;
		vel.Y = -vel.Y;
	}
	else if (pos.Y + height * 0.5f > vp.Height)
	{
		pos.Y = vp.Height - height * 0.5f;
		vel.Y = -vel.Y;
	}
}
예제 #4
0
파일: Game1.cpp 프로젝트: iamcsharper/nxna
void Game1::LoadContent()
{
	// create the sprite batch
	sb = new Nxna::Graphics::SpriteBatch(GetGraphicsDevice());

	// create a dummy texturel
    
	byte pixels[] = { 128, 128, 128, 128 };

	tex = new Nxna::Graphics::Texture2D(GetGraphicsDevice(), 1, 1, false, Nxna::Graphics::SurfaceFormat::Color);
	tex->SetData(0, pixels, 4);

	vel.X = 50.0f;
	vel.Y = 50.0f;

	pos.X = 10;
	pos.Y = 40;
}
예제 #5
0
파일: Game1.cpp 프로젝트: iamcsharper/nxna
void Game1::Draw(const Nxna::GameTime& time)
{
	GetGraphicsDevice()->Clear(Nxna::Color::CornflowerBlue);

	Nxna::Rectangle r;
	r.X = pos.X - width * 0.5f;
	r.Y = pos.Y - height *0.5f;
	r.Width = width;
	r.Height = height;
    
    Nxna::Rectangle r2;
    r2.X = 0;
    r2.Y = 0;
    r2.Width = 100;
    r2.Height = 10;
    
    Nxna::Rectangle r3;
    r3.X = 100;
    r3.Y = 100;
    r3.Width = 100;
    r3.Height = 100;
    
    Nxna::Rectangle r4;
    r4.X = 150;
    r4.Y = 150;
    r4.Width = 100;
    r4.Height = 100;
    
    Nxna::Color red(255, 0, 0);
    Nxna::Color blue(0, 0, 255);
    Nxna::Color halfred = red * 0.5f;
    Nxna::Color halfblue = blue * 0.5f;

	sb->Begin();
	sb->Draw(tex, r, nullptr, red);
    sb->Draw(tex, r2, nullptr, red);
    sb->Draw(tex, r3, nullptr, halfblue);
    sb->Draw(tex, r4, nullptr, halfred);
	sb->End();
}
예제 #6
0
void GameScene::DrawScene(const tt::GameContext& context)
{
	auto pGfxService = MyServiceLocator::GetInstance()->GetService<IGraphicsService>();
	
	pGfxService->PrepareShadowGeneration();
	for(auto pObj : m_Objects)
		pObj->GenerateShadows(context);
	
	pGfxService->GetGraphicsDevice()->ResetRenderTarget();
	
	pGfxService->PrepareDeferredShading();
	
	for(auto pObj : m_Objects){
		pObj->Draw(context);
		//pObj->DrawObject(context);
	}
	
	pGfxService->CompositeDeferredShading(context);
	
	//Render FPS
	m_pDefaultFont->DrawText(std::tstring(_T("FPS: ")) + to_tstring(context.FramesPerSecond) + _T("\nSPF: ") + to_tstring(context.GameTimer.GetElapsedSeconds() ), 
							tt::Vector2(5,0), 
							tt::Vector4(1,1,0,1) );
		
	pGfxService->GetSpriteBatch()->Flush(context);

	auto particlesSprite = ParticleEmitterComponent::RenderDeferred(context);
	//pGfxService->GetSpriteBatch()->Draw(particlesSprite);
	//pGfxService->GetSpriteBatch()->Flush(context);
	
	if(!m_PostProEffects.empty() ){
		auto postProSprite = pGfxService->RenderPostProcessing(context, m_PostProEffects);

		pGfxService->GetSpriteBatch()->Draw(postProSprite);
		pGfxService->GetSpriteBatch()->Flush(context);
	}
}