Beispiel #1
0
        void CALLBACK on_render(ID3D11Device* device, ID3D11DeviceContext* context, double fTime, float fElapsedTime, void* pUserContext)
        {
            if (!enabled)
                return;

            // get FPS
            dune::tstringstream ss;
            ss << DXUTGetFPS() << L"(" << std::setprecision(2) << DXUTGetElapsedTime() * 1000 << L"ms)" << std::endl;
            hud.GetStatic(IDC_FPS_COUNTER)->SetText(ss.str().c_str());

            for (size_t i = 0; i < dlg_manager.m_Dialogs.size(); ++i)
            {
                auto h = dlg_manager.m_Dialogs[i];

                // make sure HUD is rendered last
                if (h != &hud)
                    h->OnRender(fElapsedTime);
            }

            hud.OnRender(fElapsedTime);
        }
//--------------------------------------------------------------------------------------
// Render the scene using the D3D11 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext,
								  double fTime, float fElapsedTime, void* pUserContext )
{
	// Clear render target and the depth stencil 
	float ClearColor[4] = { 0.176f, 0.196f, 0.667f, 0.0f };
	ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView();
	ID3D11DepthStencilView* pDSV = DXUTGetD3D11DepthStencilView();
	pd3dImmediateContext->ClearRenderTargetView( pRTV, ClearColor );
	pd3dImmediateContext->ClearDepthStencilView( pDSV, D3D11_CLEAR_DEPTH, 1.0, 0 );

	vegetationRendering->draw(pd3dDevice, GameTime(fElapsedTime, fTime));

	std::wstringstream ws;

	ws << DXUTGetFPS();
	
	textHelper.Begin();
	textHelper.SetInsertionPos(5, 5);
	textHelper.SetForegroundColor(vegetationRendering->isInCaptureMode() ? D3DXCOLOR(1,0,0,1) : D3DXCOLOR(1, 1, 0, 1));
	textHelper.DrawTextLine(ws.str().c_str());
	textHelper.End();
}
    void DrawText()
    {
        g_pTxtHelper->Begin();

        g_pTxtHelper->SetInsertionPos(5, 5);
        g_pTxtHelper->SetForegroundColor(D3DXCOLOR(0.f, 0.f, 0.f, 1.f));

        g_pTxtHelper->DrawTextLine(DXUTGetDeviceStats());
        g_pTxtHelper->DrawFormattedTextLine(L"FPS: %.1f, VSync: %s" , DXUTGetFPS(), !DXUTIsVsyncEnabled() ? L"On" : L"Off");
        g_pTxtHelper->DrawFormattedTextLine(L"AO Resolution: %d x %d", g_BackBufferWidth, g_BackBufferHeight);
        g_pTxtHelper->DrawFormattedTextLine(L"Allocated Video Memory: %d MB\n", g_AORenderer.GetAllocatedVideoMemoryBytes() / (1024*1024));

        g_pTxtHelper->DrawFormattedTextLine(L"GPU Times Per Frame (ms):");
        g_pTxtHelper->DrawFormattedTextLine(L"  RenderAO: %.2f", g_AORenderer.GetGPUTimeInMS(GPU_TIME_TOTAL));
        g_pTxtHelper->DrawFormattedTextLine(L"    LinearZ: %.2f", g_AORenderer.GetGPUTimeInMS(GPU_TIME_LINEAR_Z));
        g_pTxtHelper->DrawFormattedTextLine(L"    DeinterleaveZ: %.2f", g_AORenderer.GetGPUTimeInMS(GPU_TIME_DEINTERLEAVE_Z));
        g_pTxtHelper->DrawFormattedTextLine(L"    ReconstructN: %.2f", g_AORenderer.GetGPUTimeInMS(GPU_TIME_RECONSTRUCT_NORMAL));
        g_pTxtHelper->DrawFormattedTextLine(L"    GenerateAO: %.2f", g_AORenderer.GetGPUTimeInMS(GPU_TIME_GENERATE_AO));
        g_pTxtHelper->DrawFormattedTextLine(L"    ReinterleaveAO: %.2f", g_AORenderer.GetGPUTimeInMS(GPU_TIME_REINTERLEAVE_AO));
        g_pTxtHelper->DrawFormattedTextLine(L"    BlurX: %.2f", g_AORenderer.GetGPUTimeInMS(GPU_TIME_BLURX));
        g_pTxtHelper->DrawFormattedTextLine(L"    BlurY: %.2f", g_AORenderer.GetGPUTimeInMS(GPU_TIME_BLURY));

        g_pTxtHelper->End();
    }
Beispiel #4
0
void CALLBACK OnD3D11FrameRender(ID3D11Device* d3dDevice, ID3D11DeviceContext* d3dDeviceContext, double time,
                                 float elapsedTime, void* userContext)
{
	D3DXVECTOR3 cubePos;

    if (gZeroNextFrameTime) {
        elapsedTime = 0.0f;
    }
    gZeroNextFrameTime = false;

    if (gD3DSettingsDlg.IsActive()) {
        gD3DSettingsDlg.OnRender(elapsedTime);
        return;
    }

    // Lazily create the application if need be
    if (!gApp) {
        InitApp(d3dDevice);
    }

    // Lazily load scene
	/*!gMeshOpaque.IsLoaded() && !gMeshAlpha.IsLoaded() &&!gMeshOpaque2.IsLoaded()*/
    if (!sceneGraph.IsLoaded()) {
        InitScene(d3dDevice);
    }
	if(PXEngine)
	{
		for(int i = 0; i < cubeList->size(); i++)
		PXEngine->StepPhysX();
		if(cubeList)
		{
			for(int i = 0; i < cubeList->size(); i++)
			{
				if((*cubeList)[i]->id<0)
				{
					sceneGraph.SetInstancePosition(1,(*cubeList)[i]->id, (*cubeList)[i]->x, (*cubeList)[i]->y, (*cubeList)[i]->z);
				}
				else
				{
					sceneGraph.SetMeshPosition(0,(*cubeList)[i]->id, (*cubeList)[i]->x, (*cubeList)[i]->y, (*cubeList)[i]->z);
				}
			}
		}
	}

	//crosshair
	D3DRECT rec2 = {screenCenterX-20, screenCenterY, screenCenterX + 20, screenCenterY + 2};
	D3DRECT rec3 = {screenCenterX, screenCenterY - 20, screenCenterX + 2, screenCenterY + 20};

    ID3D11RenderTargetView* pRTV = DXUTGetD3D11RenderTargetView();
	
    
    D3D11_VIEWPORT viewport;
    viewport.Width    = static_cast<float>(DXUTGetDXGIBackBufferSurfaceDesc()->Width);
    viewport.Height   = static_cast<float>(DXUTGetDXGIBackBufferSurfaceDesc()->Height);
    viewport.MinDepth = 0.0f;
    viewport.MaxDepth = 1.0f;
    viewport.TopLeftX = 0.0f;
    viewport.TopLeftY = 0.0f;
	screenCenterX = viewport.Width / 2;
	screenCenterY = viewport.Height / 2;

	gViewPort.Width = viewport.Width;
	gViewPort.Height = viewport.Height;
	gViewPort.MaxZ = viewport.MaxDepth;
	gViewPort.MinZ = viewport.MinDepth;
	gViewPort.X = viewport.TopLeftX;
	gViewPort.Y = viewport.TopLeftY;


		 gApp->Render(d3dDeviceContext, pRTV, sceneGraph, gSkyboxSRV,
        gWorldMatrix, &gViewerCamera, &viewport, &gUIConstants);
	
		 
		 sceneGraph.SetMeshPosition(0,1, 100000, 100000, 100000);
    if (gDisplayUI) {
        d3dDeviceContext->RSSetViewports(1, &viewport);

        // Render HUDs in reverse order
        d3dDeviceContext->OMSetRenderTargets(1, &pRTV, 0);
        for (int i = HUD_NUM - 1; i >= 0; --i) {
            gHUD[i].OnRender(elapsedTime);
        }

        // Render text
        gTextHelper->Begin();

        gTextHelper->SetInsertionPos(2, 0);
        gTextHelper->SetForegroundColor(D3DXCOLOR(1.0f, 1.0f, 0.0f, 1.0f));
        gTextHelper->DrawTextLine(DXUTGetFrameStats(DXUTIsVsyncEnabled()));
        //gTextHelper->DrawTextLine(DXUTGetDeviceStats());

        // Output frame time
        {
            std::wostringstream oss;
            oss << 1000.0f / DXUTGetFPS() << " ms / frame";
            gTextHelper->DrawTextLine(oss.str().c_str());
        }

        // Output light info
        {
            std::wostringstream oss;
            oss << "Lights: " << gApp->GetActiveLights();
            gTextHelper->DrawTextLine(oss.str().c_str());
        }
        
        gTextHelper->End();
    }
	
}
int RenderWin32DX9Imp::getFPS() {
    return (int) DXUTGetFPS();
}
Beispiel #6
0
//--------------------------------------------------------------------------------------
// Update the view matrix based on user input & elapsed time
//--------------------------------------------------------------------------------------
VOID CDebugCamera::FrameMove( FLOAT fElapsedTime )
{
    D3DXVECTOR3 vPosDeltaWorld(0.0f, 0.0f, 0.0f);

    if( DXUTGetGlobalTimer()->IsStopped() )
        fElapsedTime = 1.0f / DXUTGetFPS();

    if (IsKeyDown(s_aKeys[DEBUG_CAM_ROTATE_LEFT]))
    {
        m_fCameraYawAngle -= fRotateSpeed * fElapsedTime;
    }
    if (IsKeyDown(s_aKeys[DEBUG_CAM_ROTATE_RIGHT]))
    {
        m_fCameraYawAngle += fRotateSpeed * fElapsedTime;
    }
	if (IsKeyDown(s_aKeys[DEBUG_CAM_MOVE_FORWARD]))
	{
        vPosDeltaWorld.x =  sin(m_fCameraYawAngle) * fMoveSpeed * fElapsedTime;
        vPosDeltaWorld.z =  cos(m_fCameraYawAngle) * fMoveSpeed * fElapsedTime;
	}
	if (IsKeyDown(s_aKeys[DEBUG_CAM_MOVE_BACKWARD]))
	{
        vPosDeltaWorld.x = -sin(m_fCameraYawAngle) * fMoveSpeed * fElapsedTime;
        vPosDeltaWorld.z = -cos(m_fCameraYawAngle) * fMoveSpeed * fElapsedTime;
	}
    if (IsKeyDown(s_aKeys[DEBUG_CAM_PITCH_UP]))
    {
        m_fCameraPitchAngle -= fRotateSpeed * fElapsedTime;

        // Limit pitch to straight up 
        m_fCameraPitchAngle = __max( -D3DX_PI/2.0f,  m_fCameraPitchAngle );
    }
    if (IsKeyDown(s_aKeys[DEBUG_CAM_PITCH_DOWN]))
    {
        m_fCameraPitchAngle += fRotateSpeed * fElapsedTime;

        // Limit pitch to straight down 
        m_fCameraPitchAngle = __min( +D3DX_PI/2.0f,  m_fCameraPitchAngle );
    }
    if (IsKeyDown(s_aKeys[DEBUG_CAM_MOVE_UP]))
    {
        vPosDeltaWorld.y += fMoveSpeed * fElapsedTime;
    }
    if (IsKeyDown(s_aKeys[DEBUG_CAM_MOVE_DOWN]))
    {
        vPosDeltaWorld.y -= fMoveSpeed * fElapsedTime;
    }

    // Make a rotation matrix based on the camera's yaw & pitch
    D3DXMATRIX mCameraRot;
    D3DXMatrixRotationYawPitchRoll( &mCameraRot, m_fCameraYawAngle, m_fCameraPitchAngle, 0 );

    // Transform vectors based on camera's rotation matrix
    D3DXVECTOR3 vWorldUp, vWorldAhead;
    D3DXVECTOR3 vLocalUp    = D3DXVECTOR3(0,1,0);
    D3DXVECTOR3 vLocalAhead = D3DXVECTOR3(0,0,1);
    D3DXVec3TransformCoord( &vWorldUp, &vLocalUp, &mCameraRot );
    D3DXVec3TransformCoord( &vWorldAhead, &vLocalAhead, &mCameraRot );

    // Move the eye position 
    m_vEye += vPosDeltaWorld;

    // Update the lookAt position based on the eye position 
    m_vLookAt = m_vEye + vWorldAhead;
    
    // Update the view matrix
    D3DXMatrixLookAtLH( &m_mView, &m_vEye, &m_vLookAt, &vWorldUp );

    D3DXMatrixInverse( &m_mCameraWorld, NULL, &m_mView );
}
void VegetationRendering::update(const GameTime& gameTime)
{
	camera->update(gameTime);
	inputManager->update(gameTime);

	if (captureMode)
	{
		if (currentCaptureView < camera->getCurrentViewCounter())
		{
			outputSum();
			goToNextCaptureFile();
		}

		currentCaptureTime += gameTime.elapsed;
		if(currentCaptureTime > CAPTURE_INIT_TIME)
		{
			double frames = (double)DXUTGetFPS();
			captureFile << frames << std::endl;
			frameSum += frames;
			frameCount++;
		}

		if (camera->getCurrentViewCounter() == -1)
		{
			stopCapturing();
			instancesIndex++;
			if (instancesIndex < instancesCount)
				startCapturing(captureFilename);
			else
			{
				captureSumFile.close();
				trunk->setDrawInstanceCount(50);
			}
		}
	}

	if (Keyboard::isKeyPress('M'))
		toggleCursor();
	else if (Keyboard::isKeyPress('F'))
		toggleWireframe();
	else if (Keyboard::isKeyPress('T'))
		complexGrass->toggleTessellationMode();
	else if (Keyboard::isKeyPress('C'))
		gsCullingEnabled = !gsCullingEnabled;
	else if (Keyboard::isKeyPress('P'))
	{
		showSavedEnabled = !showSavedEnabled;
		if(showSavedEnabled)
		{
			savedViewMatrix = camera->getView();
			savedProjectionMatrix = camera->getProjection(complexGrass->getGrassNearPlane(), complexGrass->getGrassFarPlane());
		}
	}
	/*else if (Keyboard::isKeyPress('L'))
		camera->outputCameraView("CameraViews.txt");
	else if (Keyboard::isKeyPress('V'))
		camera->pauseVisitCameraViews();
	else if (Keyboard::isKeyPress('N'))
		camera->goToNextCameraView();*/
	/*else if (Keyboard::isKeyPress('7'))
	{
		instancesIndex = 0;
		instancesCount = grassTestInstanceCounts.size();
		grassTests = true;
		capturedBorder = complexGrass->getBorder();
		captureSumFile.open("GrassSum.txt", std::ios::out);
		startCapturing("GrassResults");
	}
	else if (Keyboard::isKeyPress('8'))
	{
		instancesIndex = 0;
		instancesCount = treeTestInstanceCounts.size();
		grassTests = false;
		capturedBorder = trunk->getBorder();
		captureSumFile.open("TreeSum.txt", std::ios::out);
		startCapturing("TreeResults");
	}*/
	/*else if (Keyboard::isKeyPress('1'))
		gsGrassEnabled = !gsGrassEnabled;*/
	else if (Keyboard::isKeyPress('2'))
		complexGrassEnabled = !complexGrassEnabled;
	else if (Keyboard::isKeyPress('3'))
		defaultGrassEnabled = !defaultGrassEnabled;
	else if (Keyboard::isKeyPress('4'))
		treeModelsEnabled = !treeModelsEnabled;
	else if (Keyboard::isKeyPress('5'))
		complexTreesEnabled = !complexTreesEnabled;
	else if (Keyboard::isKeyPress('6'))
		defaultTreesEnabled = !defaultTreesEnabled;
	/*else if (Keyboard::isKeyPress('Q'))
		defaultDetailedEnabled = !defaultDetailedEnabled;*/
}