//--------------------------------------------------------------------------------------
// Handles the GUI events
//--------------------------------------------------------------------------------------
void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, 
                          void* pUserContext )
{
    if( g_bGuiVisible )
    {
        switch( nControlID )
        {
            case IDC_TOGGLEFULLSCREEN:
                DXUTToggleFullScreen(); break;
            case IDC_TOGGLEREF:
                DXUTToggleREF(); break;
            case IDC_CHANGEDEVICE:
                g_D3DSettingsDlg.SetActive( !g_D3DSettingsDlg.IsActive() ); break;
            case IDC_SUNWIDTH_SLIDER:
                WCHAR temp[64];
                int iVal = g_HUD.GetSlider( IDC_SUNWIDTH_SLIDER )->GetValue();

                g_fSunWidth = ( float( iVal ) / 100.0f ) * 3.0f;
                swprintf_s( temp, L"SunWidth = %2.2f", g_fSunWidth );
                g_HUD.GetStatic( IDC_SUNWIDTH_TEXT )->SetText( temp );

                break;
        }
    }
}
	virtual void onPostUpdate(grp::ISkeleton* skeleton)
	{
		int value = g_SampleUI.GetSlider(IDC_SLIDER_ARM)->GetValue();
		float arm_scale = 0.75f + value / 200.0f;
		value = g_SampleUI.GetSlider(IDC_SLIDER_LEG)->GetValue();
		float leg_scale = 0.75f + value / 200.0f;
		value = g_SampleUI.GetSlider(IDC_SLIDER_BODY)->GetValue();
		float body_scale = 0.75f + value / 200.0f;

		set_bone_scale(skeleton, L"Bip L UpperArm", arm_scale);
		set_bone_scale(skeleton, L"Bip L Forearm", arm_scale);
		set_bone_scale(skeleton, L"Bip R UpperArm", arm_scale);
		set_bone_scale(skeleton, L"Bip R Forearm", arm_scale);
		
		set_bone_scale(skeleton, L"Bip L Thigh", leg_scale);
		set_bone_scale(skeleton, L"Bip R Thigh", leg_scale);
		set_bone_scale(skeleton, L"Bip L Calf", leg_scale);
		set_bone_scale(skeleton, L"Bip R Calf", leg_scale);
		
		set_bone_scale(skeleton, L"Bip Pelvis", body_scale);
		set_bone_scale(skeleton, L"Bip Spine", body_scale);
		set_bone_scale(skeleton, L"Bip Spine1", body_scale);
		set_bone_scale(skeleton, L"Bip Spine2", body_scale);
		set_bone_scale(skeleton, L"Bip Spine3", body_scale);
	}
//--------------------------------------------------------------------------------------
// Create any D3D10 resources that depend on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D10SwapChainResized( ID3D10Device* pd3dDevice, IDXGISwapChain* pSwapChain,
                                          const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
    HRESULT hr = S_OK;

    V_RETURN( g_DialogResourceManager.OnD3D10ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) );
    V_RETURN( g_D3DSettingsDlg.OnD3D10ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) );

    // Setup the camera's projection parameters
    float fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT )pBackBufferSurfaceDesc->Height;
    g_Camera.SetProjParams( 60.0f * ( D3DX_PI / 180.0f ), fAspectRatio, 0.1f, 100.0f );
    g_Camera.SetWindow( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height );
    g_Camera.SetButtonMasks( MOUSE_LEFT_BUTTON, MOUSE_WHEEL, MOUSE_MIDDLE_BUTTON );

    g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 );
    g_HUD.SetSize( 170, 170 );
    g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height - 300 );
    g_SampleUI.SetSize( 170, 300 );

    // Update the sample count
    UpdateMSAASampleCounts( pd3dDevice, pBackBufferSurfaceDesc->Format );

    // Create a render target
    g_BackBufferWidth = pBackBufferSurfaceDesc->Width;
    g_BackBufferHeight = pBackBufferSurfaceDesc->Height;
    V_RETURN( CreateRenderTarget( pd3dDevice, g_BackBufferWidth, g_BackBufferHeight, g_MSAASampleCount, 0 ) );

    return hr;
}
//--------------------------------------------------------------------------------------
// Create any D3D11 resources that depend on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D11ResizedSwapChain(ID3D11Device* pd3dDevice, IDXGISwapChain* /*pSwapChain*/,
    const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* /*pUserContext*/)
{
    HRESULT hr;

    V_RETURN(g_DialogResourceManager.OnD3D11ResizedSwapChain(pd3dDevice, pBackBufferSurfaceDesc));
    V_RETURN(g_D3DSettingsDlg.OnD3D11ResizedSwapChain(pd3dDevice, pBackBufferSurfaceDesc));

    g_nFrameWidth = pBackBufferSurfaceDesc->Width;
    g_nFrameHeight = pBackBufferSurfaceDesc->Height;

    // Setup the camera's projection parameters    
    float fAspectRatio = pBackBufferSurfaceDesc->Width / (FLOAT)pBackBufferSurfaceDesc->Height;
    g_Camera.SetProjParams(XM_PI / 4, fAspectRatio, 0.1f, 5000.0f);
    g_Camera.SetWindow(pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height);

    g_HUD.SetLocation(pBackBufferSurfaceDesc->Width - 170, 0);
    g_HUD.SetSize(170, 170);
    g_SampleUI.SetLocation(pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height - 350);
    g_SampleUI.SetSize(170, 300);

    g_OIT.OnD3D11ResizedSwapChain(pBackBufferSurfaceDesc, pd3dDevice);

    return S_OK;
}
VOID RenderHUD( ID3D11DeviceContext* pd3dImmediateContext, FLOAT fElapsedTime )
{
    DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
    g_HUD.OnRender( fElapsedTime );
    g_SampleUI.OnRender( fElapsedTime );

    static FLOAT InspectionYOffset = 0;
    if( g_pInspectionTexture != NULL )
    {
        const INT ViewportHeight = (INT)g_HalfClientHeightPixels * 2;
        INT TotalHeight = 0;
        INT SliceHeight = 0;
        g_PageDebugRender.Render( pd3dImmediateContext, g_pTitleResidencyManager, g_pInspectionTexture, 10, ViewportHeight - (INT)InspectionYOffset, &TotalHeight, &SliceHeight );

        FLOAT fLerp = min( 1.0f, fElapsedTime * 8.0f );
        FLOAT TargetOffset = (FLOAT)( SliceHeight * ( g_InspectionSliceIndex + 1 ) );
        if( fabsf( TargetOffset - InspectionYOffset ) < 2.0f )
        {
            InspectionYOffset = TargetOffset;
        }
        else
        {
            InspectionYOffset = ( TargetOffset * fLerp + (FLOAT)InspectionYOffset * ( 1.0f - fLerp ) );
        }
    }
    else
    {
        InspectionYOffset = 0;
        g_InspectionSliceIndex = 0;
    }

    if( g_bDrawResidencySampleViews )
    {
        ID3D11ShaderResourceView* pSRViewUVGradientID = NULL;
        ID3D11ShaderResourceView* pSRViewExtendedUVSlice = NULL;

        g_pTitleResidencyManager->GetViewShaderResources( g_LastResidencySampleViewID, &pSRViewUVGradientID, &pSRViewExtendedUVSlice );

        if( pSRViewExtendedUVSlice != NULL && pSRViewUVGradientID != NULL )
        {
            RECT ClientRect;
            GetClientRect( DXUTGetHWND(), &ClientRect );

            UINT Width = 256;
            UINT Height = 144;
            UINT Margin = 10;
            UINT BottomMargin = 60 + Margin;

            RECT Rect2 = { ClientRect.right - ( Width + Margin ), ClientRect.bottom - ( Height + BottomMargin ), ClientRect.right - Margin, ClientRect.bottom - BottomMargin };
            RECT Rect1 = { Rect2.left, Rect2.top - ( Height + Margin ), Rect2.right, Rect2.top - Margin };

            g_PageDebugRender.RenderTexture( pd3dImmediateContext, pSRViewUVGradientID, Rect1 );
            g_PageDebugRender.RenderTexture( pd3dImmediateContext, pSRViewExtendedUVSlice, Rect2 );
        }
    }

    RenderText();

    DXUT_EndPerfEvent();
}
//--------------------------------------------------------------------------------------
// Create any D3D11 resources that depend on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, IDXGISwapChain* pSwapChain,
                                         const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
    HRESULT hr;

    V_RETURN( g_DialogResourceManager.OnD3D11ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) );
    V_RETURN( g_SettingsDlg.OnD3D11ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) );

    FLOAT fAspect = (FLOAT)pBackBufferSurfaceDesc->Width / (FLOAT)pBackBufferSurfaceDesc->Height;

    // Setup the camera's projection parameters
    XMMATRIX matProjection = XMMatrixPerspectiveFovLH( XM_PIDIV4, fAspect, 0.001f, 100.0f );
    XMStoreFloat4x4A( &g_matProjection, matProjection );

    g_pTerrainView->GetCamera()->SetProjParams( XM_PIDIV4, fAspect, 0.01f, 1000.0f );

    g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 );
    g_HUD.SetSize( 170, 170 );

    INT UIWidth = 250;
    INT UIHeight = 110;
    g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - UIWidth, pBackBufferSurfaceDesc->Height - UIHeight );
    g_SampleUI.SetSize( UIWidth, UIHeight );

    g_HalfClientWidthPixels = (FLOAT)pBackBufferSurfaceDesc->Width * 0.5f;
    g_HalfClientHeightPixels = (FLOAT)pBackBufferSurfaceDesc->Height * 0.5f;

    ResidencySampleRender::ResizeRenderView( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height );

    return S_OK;
}
void RenderArrows(float fElapsedTime)
{
    WCHAR strWhite[MAX_PATH] = {26};
    WCHAR strBlack[MAX_PATH] = {27};
    CDXUTStatic* pStatic = NULL;

    pStatic = g_WhiteArrowDialog.GetStatic(IDC_WHITESCORE);
    if(pStatic != NULL)
    {
        pStatic->SetText(strWhite);
    }

    pStatic = g_BlackArrowDialog.GetStatic(IDC_BLACKSCORE);
    if(pStatic != NULL)
    {
        pStatic->SetText(strBlack);
    }

	if(!g_Board.pRenjuGame->bGameIsFinished)
	{
		if(g_Board.pRenjuGame->activeColor == White)
		{
			g_WhiteArrowDialog.OnRender(fElapsedTime);
		}
		if(g_Board.pRenjuGame->activeColor == Black)
		{
			g_BlackArrowDialog.OnRender(fElapsedTime);
		}
	}
}
Exemple #8
0
//--------------------------------------------------------------------------------------
// Handles the GUI events
//--------------------------------------------------------------------------------------
void CALLBACK OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext )
{
    switch( nControlID )
    {
        case IDC_TOGGLEFULLSCREEN:
            DXUTToggleFullScreen(); break;
        case IDC_TOGGLEREF:
            DXUTToggleREF(); break;
        case IDC_CHANGEDEVICE:
            g_D3DSettingsDlg.SetActive( !g_D3DSettingsDlg.IsActive() ); break;
        case IDC_TOGGLEWARP:
            DXUTToggleWARP(); break;
        case IDC_TOGGLESPIN:
        {
            g_bSpinning = g_SampleUI.GetCheckBox( IDC_TOGGLESPIN )->GetChecked();
            break;
        }

        case IDC_EXPLODE_SCALE:
        {
            WCHAR sz[100];
            g_fExplode = ( float )( g_SampleUI.GetSlider( IDC_EXPLODE_SCALE )->GetValue() * 0.01f );
            swprintf_s( sz, 100, L"Explode Amount: %0.2f", g_fExplode );
            g_SampleUI.GetStatic( IDC_EXPLODE_STATIC )->SetText( sz );
            g_pExplodeVariable->SetFloat( g_fExplode );
            break;
        }
    }
}
//--------------------------------------------------------------------------------------
// Render the scene using the D3D11 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime,
                                  FLOAT fElapsedTime, void* pUserContext )
{
  UNREFERENCED_PARAMETER(pUserContext);
  UNREFERENCED_PARAMETER(pd3dDevice);
  UNREFERENCED_PARAMETER(fTime);

  if( g_D3DSettingsDlg.IsActive() )
  {
    g_D3DSettingsDlg.OnRender( fElapsedTime );
    return;
  }
  
  auto pRTV = DXUTGetD3D11RenderTargetView();
  
  // Clear color
  pd3dImmediateContext->ClearRenderTargetView( pRTV, Colors::DimGray );

   // Start the frame
  g_Scene.InitFrame(&g_ViewerCamera, &g_LightCamera);
  
  // Draw Shadows
  g_Scene.RenderShadowCascades( &g_MeshPowerPlant );
  
  // Render the GBuffer
  g_Scene.RenderGBuffer(&g_MeshPowerPlant);
  
  // Process the light linked list
  g_Scene.ProcessLinkedList();
  
  // Composite the scene
  g_Scene.CompositeScene(pRTV);
  
  // Blended elements
  g_Scene.DrawAlpha(&g_TeapotMesh);

  // End the frame
  g_Scene.EndFrame(pRTV);
  
  // Hud
  {
     D3D11_VIEWPORT vp;
     vp.Width    = (FLOAT)DXUTGetDXGIBackBufferSurfaceDesc()->Width;
     vp.Height   = (FLOAT)DXUTGetDXGIBackBufferSurfaceDesc()->Height;
     vp.MinDepth = 0;
     vp.MaxDepth = 1;
     vp.TopLeftX = 0;
     vp.TopLeftY = 0;
  
     pd3dImmediateContext->RSSetViewports( 1, &vp);            
     pd3dImmediateContext->OMSetRenderTargets( 1, &pRTV, nullptr );
  
     DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" );
  
     g_HUD.OnRender( fElapsedTime );
     g_SampleUI.OnRender( fElapsedTime );
     RenderText();
     DXUT_EndPerfEvent();
  }
}
//--------------------------------------------------------------------------------------
// Create any D3D9 resources that won't live through a device reset (D3DPOOL_DEFAULT) 
// or that are tied to the back buffer size 
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D9ResetDevice( IDirect3DDevice9* pd3dDevice,
                                    const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
    HRESULT hr;

    V_RETURN( g_DialogResourceManager.OnD3D9ResetDevice() );
    V_RETURN( g_D3DSettingsDlg.OnD3D9ResetDevice() );

    if( g_pFont9 ) V_RETURN( g_pFont9->OnResetDevice() );
    if( g_pEffect9 ) V_RETURN( g_pEffect9->OnResetDevice() );

    // Create a sprite to help batch calls when drawing many lines of text
    V_RETURN( D3DXCreateSprite( pd3dDevice, &g_pSprite9 ) );
    g_pTxtHelper = new CDXUTTextHelper( g_pFont9, g_pSprite9, 15 );

        g_LightControl.OnD3D9ResetDevice( pBackBufferSurfaceDesc );

    // Setup the camera's projection parameters
    float fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT )pBackBufferSurfaceDesc->Height;
    g_Camera.SetProjParams( D3DX_PI / 4, fAspectRatio, 2.0f, 4000.0f );
    g_Camera.SetWindow( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height );
    g_Camera.SetButtonMasks( MOUSE_LEFT_BUTTON, MOUSE_WHEEL, MOUSE_MIDDLE_BUTTON );

    g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 );
    g_HUD.SetSize( 170, 170 );
    g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height - 300 );
    g_SampleUI.SetSize( 170, 300 );

    return S_OK;
}
Exemple #11
0
//--------------------------------------------------------------------------------------
// Before handling window messages, DXUT passes incoming windows 
// messages to the application through this callback function. If the application sets 
// *pbNoFurtherProcessing to TRUE, then DXUT will not process this message.
//--------------------------------------------------------------------------------------
LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing,
                          void* pUserContext )
{
    // Always allow dialog resource manager calls to handle global messages
    // so GUI state is updated correctly
    *pbNoFurtherProcessing = g_DialogResourceManager.MsgProc( hWnd, uMsg, wParam, lParam );
    if( *pbNoFurtherProcessing )
        return 0;

    if( g_SettingsDlg.IsActive() )
    {
        g_SettingsDlg.MsgProc( hWnd, uMsg, wParam, lParam );
        return 0;
    }

    // Give the dialogs a chance to handle the message first
    *pbNoFurtherProcessing = g_HUD.MsgProc( hWnd, uMsg, wParam, lParam );
    if( *pbNoFurtherProcessing )
        return 0;
    *pbNoFurtherProcessing = g_SampleUI.MsgProc( hWnd, uMsg, wParam, lParam );
    if( *pbNoFurtherProcessing )
        return 0;

    // Pass all remaining windows messages to camera so it can respond to user input
    g_Camera.HandleMessages( hWnd, uMsg, wParam, lParam );
    g_LightControl.HandleMessages( hWnd, uMsg, wParam, lParam );

    return 0;
}
Exemple #12
0
//--------------------------------------------------------------------------------------
// This callback function will be called immediately after the Direct3D device has been 
// reset, which will happen after a lost device scenario. This is the best location to 
// create D3DPOOL_DEFAULT resources since these resources need to be reloaded whenever 
// the device is lost. Resources created here should be released in the OnLostDevice 
// callback. 
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnResetDevice( IDirect3DDevice9* pd3dDevice,
                                const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
    HRESULT hr;

    V_RETURN( g_DialogResourceManager.OnD3D9ResetDevice() );
    V_RETURN( g_SettingsDlg.OnD3D9ResetDevice() );

    if( g_pFont )
        V_RETURN( g_pFont->OnResetDevice() );
    if( g_pEffect )
        V_RETURN( g_pEffect->OnResetDevice() );

    g_LightControl.OnD3D9ResetDevice( pBackBufferSurfaceDesc );
    g_Skybox.OnResetDevice( pBackBufferSurfaceDesc );

    // Create a sprite to help batch calls when drawing many lines of text
    V_RETURN( D3DXCreateSprite( pd3dDevice, &g_pTextSprite ) );

    // Setup the camera's projection parameters
    float fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT )pBackBufferSurfaceDesc->Height;
    g_Camera.SetProjParams( D3DX_PI / 4, fAspectRatio, 0.001f, 1000.0f );
    g_Camera.SetWindow( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height );
    g_Camera.SetButtonMasks( MOUSE_LEFT_BUTTON, MOUSE_WHEEL, MOUSE_RIGHT_BUTTON );
    g_Camera.SetAttachCameraToModel( true );
    g_Camera.SetRadius( 5.0f, 0.1f, 20.0f );

    g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 );
    g_HUD.SetSize( 170, 170 );
    g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 300, pBackBufferSurfaceDesc->Height - 245 );
    g_SampleUI.SetSize( 300, 300 );

    return S_OK;
}
//--------------------------------------------------------------------------------------
// Create any D3D10 resources that depend on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D10ResizedSwapChain(ID3D10Device* pd3dDevice,
		IDXGISwapChain* pSwapChain,
		const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext)
{
	HRESULT hr;
	V_RETURN(g_DialogResourceManager.OnD3D10ResizedSwapChain(pd3dDevice,
			 pBackBufferSurfaceDesc));
	V_RETURN(g_D3DSettingsDlg.OnD3D10ResizedSwapChain(pd3dDevice,
			 pBackBufferSurfaceDesc));
	// Setup the camera's projection parameters
	float fAspectRatio =
		1.0;//pBackBufferSurfaceDesc->Width / (FLOAT)pBackBufferSurfaceDesc->Height;
	g_Camera.SetProjParams(D3DX_PI / 4, fAspectRatio, 0.1f, 10.0f);
	g_Camera.SetWindow(pBackBufferSurfaceDesc->Width,
					   pBackBufferSurfaceDesc->Height);
	g_Camera.SetButtonMasks(MOUSE_RIGHT_BUTTON, MOUSE_WHEEL, MOUSE_MIDDLE_BUTTON);
	g_HUD.SetLocation(pBackBufferSurfaceDesc->Width - 170, 0);
	g_HUD.SetSize(170, 170);
	g_SampleUI.SetLocation(pBackBufferSurfaceDesc->Width - 170,
						   pBackBufferSurfaceDesc->Height - 300);
	g_SampleUI.SetSize(170, 300);
	// resize the texture so that it fits to the current screen size
	UINT width = (DXUTIsAppRenderingWithD3D9()) ?
				 DXUTGetD3D9BackBufferSurfaceDesc()->Width :
				 DXUTGetDXGIBackBufferSurfaceDesc()->Width;
	UINT height = (DXUTIsAppRenderingWithD3D9()) ?
				  DXUTGetD3D9BackBufferSurfaceDesc()->Height :
				  DXUTGetDXGIBackBufferSurfaceDesc()->Height;
	g_vsObj->SetupTextures(pd3dDevice, g_pEffect10, width, height);
	return S_OK;
}
Exemple #14
0
//--------------------------------------------------------------------------------------
// Handle messages to the application
//--------------------------------------------------------------------------------------
LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing,
                          void* pUserContext )
{
  UNREFERENCED_PARAMETER(pUserContext);

  // Pass messages to dialog resource manager calls so GUI state is updated correctly
  *pbNoFurtherProcessing = g_DialogResourceManager.MsgProc( hWnd, uMsg, wParam, lParam );
  if( *pbNoFurtherProcessing )
      return 0;
  
  // Pass messages to settings dialog if its active
  if( g_D3DSettingsDlg.IsActive() )
  {
      g_D3DSettingsDlg.MsgProc( hWnd, uMsg, wParam, lParam );
      return 0;
  }
  
  // Give the dialogs a chance to handle the message first
  *pbNoFurtherProcessing = g_HUD.MsgProc( hWnd, uMsg, wParam, lParam );
  if( *pbNoFurtherProcessing )
      return 0;
  *pbNoFurtherProcessing = g_SampleUI.MsgProc( hWnd, uMsg, wParam, lParam );
  if( *pbNoFurtherProcessing )
      return 0;
  
  // Pass all remaining windows messages to camera so it can respond to user input
  g_ViewerCamera.HandleMessages( hWnd, uMsg, wParam, lParam );
  
  return 0;
}
//--------------------------------------------------------------------------------------
// Initialize the app 
//--------------------------------------------------------------------------------------
void InitApp()
{
    g_SettingsDlg.Init( &g_DialogResourceManager );
    g_HUD.Init( &g_DialogResourceManager );
    g_SampleUI.Init( &g_DialogResourceManager );

    g_HUD.SetCallback( OnGUIEvent );
    int iY = 30;
    int iYo = 26;
    g_HUD.AddButton( IDC_TOGGLEFULLSCREEN, L"Toggle full screen", 0, iY, 170, 22 );
    g_HUD.AddButton( IDC_CHANGEDEVICE, L"Change device (F2)", 0, iY += iYo, 170, 22, VK_F2 );
    g_HUD.AddButton( IDC_TOGGLEREF, L"Toggle REF (F3)", 0, iY += iYo, 170, 22, VK_F3 );
    g_HUD.AddButton( IDC_TOGGLEWARP, L"Toggle WARP (F4)", 0, iY += iYo, 170, 22, VK_F4 );

    g_SampleUI.SetCallback( OnGUIEvent );

    CDXUTComboBox* pComboBox = nullptr;
    g_SampleUI.AddStatic( IDC_STATIC, L"(G)roup", 10, 0, 170, 25 );
    g_SampleUI.AddComboBox( IDC_GROUP, 0, 25, 170, 24, 'G', false, &pComboBox );
    if( pComboBox )
        pComboBox->SetDropHeight( 50 );

    pComboBox->AddItem( L"Frustum", IntToPtr( 0 ) );
    pComboBox->AddItem( L"Axis-aligned Box", IntToPtr( 1 ) );
    pComboBox->AddItem( L"Oriented Box", IntToPtr( 2 ) );
    pComboBox->AddItem( L"Ray", IntToPtr( 3 ) );

    InitializeObjects();
}
Exemple #16
0
//--------------------------------------------------------------------------------------
// Create any D3D11 resources that depend on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, IDXGISwapChain* pSwapChain,
                                          const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
  UNREFERENCED_PARAMETER(pSwapChain);
  UNREFERENCED_PARAMETER(pUserContext);

  HRESULT hr;
  XMVECTOR vMeshExtents = g_Scene.GetSceneAABBMax() - g_Scene.GetSceneAABBMin();
  XMVECTOR vMeshLength = XMVector3Length( vMeshExtents );
  FLOAT    fMeshLength = XMVectorGetByIndex( vMeshLength, 0);
  
  V_RETURN( g_DialogResourceManager.OnD3D11ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) );
  V_RETURN( g_D3DSettingsDlg.OnD3D11ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) );
  
  g_fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT ) pBackBufferSurfaceDesc->Height;
  
  g_ViewerCamera.SetProjParams( XM_PI / 4, g_fAspectRatio, 0.05f, fMeshLength);
  
  g_Scene.OnResize(pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height);
     
  g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 );
  g_HUD.SetSize( 170, 170 );
  g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height - 300 );
  g_SampleUI.SetSize( 170, 300 );
  
  return S_OK;
}
Exemple #17
0
// Handle key presses
void CALLBACK OnKeyboard( UINT nChar, bool bKeyDown, bool bAltDown, void* pUserContext )
{
    if( bKeyDown )
    {
        switch( nChar )
        {
            case VK_F1:
                gShowHelp = !gShowHelp; break;
			case VK_TAB:
				{
					CDXUTComboBox *comboBox = gSampleUI.GetComboBox(IDC_IMAGEVIEW);
					if (eImageView_Uncompressed == (intptr_t)comboBox->GetSelectedData())
					{
						comboBox->SetSelectedByData((void*)eImageView_Compressed);
					} 
					else if (eImageView_Compressed == (intptr_t)comboBox->GetSelectedData())
					{
						comboBox->SetSelectedByData((void*)eImageView_Uncompressed);
					}
					gSampleUI.SendEvent(IDC_IMAGEVIEW, true, comboBox);
					break;
				}
        }
    }
}
Exemple #18
0
// Handle messages to the application
LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing,
                          void* pUserContext )
{
    // Pass messages to dialog resource manager calls so GUI state is updated correctly
    *pbNoFurtherProcessing = gDialogResourceManager.MsgProc( hWnd, uMsg, wParam, lParam );
    if( *pbNoFurtherProcessing )
        return 0;

    // Pass messages to settings dialog if its active
    if( gD3DSettingsDlg.IsActive() )
    {
        gD3DSettingsDlg.MsgProc( hWnd, uMsg, wParam, lParam );
        return 0;
    }

    // Give the dialogs a chance to handle the message first
    *pbNoFurtherProcessing = gHUD.MsgProc( hWnd, uMsg, wParam, lParam );
    if( *pbNoFurtherProcessing )
        return 0;
    *pbNoFurtherProcessing = gSampleUI.MsgProc( hWnd, uMsg, wParam, lParam );
    if( *pbNoFurtherProcessing )
        return 0;

    return 0;
}
Exemple #19
0
//--------------------------------------------------------------------------------------
// Create any D3D9 resources that won't live through a device reset (D3DPOOL_DEFAULT) 
// or that are tied to the back buffer size 
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D9ResetDevice( IDirect3DDevice9* pd3dDevice,
                                    const D3DSURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
    HRESULT hr;

    V_RETURN( g_DialogResourceManager.OnD3D9ResetDevice() );
    V_RETURN( g_SettingsDlg.OnD3D9ResetDevice() );

    if( g_pFont9 ) V_RETURN( g_pFont9->OnResetDevice() );

    V_RETURN( D3DXCreateSprite( pd3dDevice, &g_pSprite9 ) );
    g_pTxtHelper = new CDXUTTextHelper( g_pFont9, g_pSprite9, NULL, NULL, 15 );

    // Setup the camera's projection parameters
    float fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT )pBackBufferSurfaceDesc->Height;

	g_Camera.SetProjParams( D3DX_PI / 4, fAspectRatio, 0.1f, 1000.0f );
    g_Camera.SetWindow( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height );

    g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 );
    g_HUD.SetSize( 170, 170 );
    g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height - 350 );
    g_SampleUI.SetSize( 170, 300 );

	SCEMAN->SetActiveDevice( pd3dDevice );
	SCEMAN->OnDeviceReset();

    return S_OK;
}
Exemple #20
0
//--------------------------------------------------------------------------------------
// This callback function will be called at the end of every frame to perform all the 
// rendering calls for the scene, and it will also be called if the window needs to be 
// repainted. After this function has returned, DXUT will call 
// IDirect3DDevice9::Present to display the contents of the next buffer in the swap chain
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    // If the settings dialog is being shown, then
    // render it instead of rendering the app's scene
    if( g_SettingsDlg.IsActive() )
    {
        g_SettingsDlg.OnRender( fElapsedTime );
        return;
    }

    HRESULT hr;
    D3DXMATRIXA16 mWorld;
    D3DXMATRIXA16 mView;
    D3DXMATRIXA16 mProj;
    D3DXMATRIXA16 mWorldViewProjection;


    // Clear the render target and the zbuffer 
    V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 141, 153, 191 ), 1.0f, 0 ) );

    // Render the scene
    if( SUCCEEDED( pd3dDevice->BeginScene() ) )
    {
        // Get the projection & view matrix from the camera class
        mWorld = *g_Camera.GetWorldMatrix();
        mView = *g_Camera.GetViewMatrix();
        mProj = *g_Camera.GetProjMatrix();

        mWorldViewProjection = mWorld * mView * mProj;

        // Update the effect's variables. 
        V( g_pEffect->SetMatrix( g_hWorldViewProjection, &mWorldViewProjection ) );
        V( g_pEffect->SetMatrix( g_hWorld, &mWorld ) );
        V( g_pEffect->SetFloat( g_hTime, ( float )fTime ) );
        V( g_pEffect->SetValue( g_hCameraPosition, g_Camera.GetEyePt(), sizeof( D3DXVECTOR3 ) ) );

        UINT iCurSubset = ( UINT )( INT_PTR )g_SampleUI.GetComboBox( IDC_SUBSET )->GetSelectedData();

        // A subset of -1 was arbitrarily chosen to represent all subsets
        if( iCurSubset == -1 )
        {
            // Iterate through subsets, changing material properties for each
            for( UINT iSubset = 0; iSubset < g_MeshLoader.GetNumMaterials(); iSubset++ )
            {
                RenderSubset( iSubset );
            }
        }
        else
        {
            RenderSubset( iCurSubset );
        }

        RenderText();
        V( g_HUD.OnRender( fElapsedTime ) );
        V( g_SampleUI.OnRender( fElapsedTime ) );

        V( pd3dDevice->EndScene() );
    }
}
Exemple #21
0
//--------------------------------------------------------------------------------------
// Render the scene using the D3D9 device
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    if( g_SettingsDlg.IsActive() )
    {
        g_SettingsDlg.OnRender( fElapsedTime );
        return;
    }

    HRESULT hr;
    D3DXMATRIXA16 mWorld;
    D3DXMATRIXA16 mView;
    D3DXMATRIXA16 mProj;
    D3DXMATRIXA16 mWorldViewProjection;

    // Clear the render target and the zbuffer 
    V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 45, 50, 170 ), 1.0f, 0 ) );

    // Render the scene
    if( SUCCEEDED( pd3dDevice->BeginScene() ) )
    {
        // Get the projection & view matrix from the camera class
        mWorld = *g_Camera.GetWorldMatrix();
        mProj = *g_Camera.GetProjMatrix();
        mView = g_mView;

        mWorldViewProjection = mWorld * mView * mProj;

        // Update the effect's variables.  Instead of using strings, it would 
        // be more efficient to cache a handle to the parameter by calling 
        // ID3DXEffect::GetParameterByName
        V( g_pEffect->SetMatrix( "g_mWorldViewProjection", &mWorldViewProjection ) );
        V( g_pEffect->SetMatrix( "g_mWorld", &mWorld ) );
        V( g_pEffect->SetFloat( "g_fTime", ( float )fTime ) );

        g_pEffect->SetTechnique( "RenderScene" );
        UINT cPasses;
        g_pEffect->Begin( &cPasses, 0 );
        ID3DXMesh* pMesh = g_Mesh.GetMesh();
        for( UINT p = 0; p < cPasses; ++p )
        {
            g_pEffect->BeginPass( p );
            for( UINT m = 0; m < g_Mesh.m_dwNumMaterials; ++m )
            {
                g_pEffect->SetTexture( "g_txScene", g_Mesh.m_pTextures[m] );
                g_pEffect->CommitChanges();
                pMesh->DrawSubset( m );
            }
            g_pEffect->EndPass();
        }
        g_pEffect->End();

        RenderText();
        V( g_HUD.OnRender( fElapsedTime ) );
        V( g_SampleUI.OnRender( fElapsedTime ) );

        V( pd3dDevice->EndScene() );
    }
}
Exemple #22
0
//--------------------------------------------------------------------------------------
// Render the scene using the D3D9 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    HRESULT hr = S_OK;

    float ClearColor[4] = { 0,0,0,0 };
    ID3D10RenderTargetView* pRTV = DXUTGetD3D10RenderTargetView();
    pd3dDevice->ClearRenderTargetView( pRTV, ClearColor );
    ID3D10DepthStencilView* pDSV = DXUTGetD3D10DepthStencilView();
    pd3dDevice->ClearDepthStencilView( pDSV, D3D10_CLEAR_DEPTH, 1.0, 0 );

    // If the settings dialog is being shown, then render it instead of rendering the app's scene
    if( g_SettingsDlg.IsActive() )
    {
        g_SettingsDlg.OnRender( fElapsedTime );
        return;
    }

    // Render the scene
    {
        D3DXVECTOR4 vLightDir( -1,1,-1,1 );
        D3DXVec4Normalize( &vLightDir, &vLightDir );
        g_pvWorldLightDir->SetFloatVector( ( float* )&vLightDir );
        g_pfTime->SetFloat( ( float )fTime );
        g_pfElapsedTime->SetFloat( fElapsedTime );

        VisibilityCullTiles();

        DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"Render Sky" );
        RenderSky( pd3dDevice );
        DXUT_EndPerfEvent();

        DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"Render Terrain" );
        RenderTerrain( pd3dDevice );
        DXUT_EndPerfEvent();

        if( g_bRenderBalls )
        {
            DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"Render Balls" );
            RenderBalls( pd3dDevice );
            DXUT_EndPerfEvent();
        }

        if( g_bRenderGrass )
        {
            DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"Render Grass" );
            RenderGrass( pd3dDevice );
            DXUT_EndPerfEvent();
        }
		
        DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); // These events are to help PIX identify what the code is doing
        RenderText();
        V( g_HUD.OnRender( fElapsedTime ) );
        V( g_SampleUI.OnRender( fElapsedTime ) );
        DXUT_EndPerfEvent();
    }
}
Exemple #23
0
//--------------------------------------------------------------------------------------
// This callback function will be called at the end of every frame to perform all the 
// rendering calls for the scene, and it will also be called if the window needs to be 
// repainted. After this function has returned, DXUT will call 
// IDirect3DDevice9::Present to display the contents of the next buffer in the swap chain
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
{
    // If the settings dialog is being shown, then
    // render it instead of rendering the app's scene
    if( g_SettingsDlg.IsActive() )
    {
        g_SettingsDlg.OnRender( fElapsedTime );
        return;
    }

    HRESULT hr;

    // Clear the render target and the zbuffer 
    V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 50, 50, 50 ), 1.0f, 0 ) );

    // Render the scene
    if( SUCCEEDED( pd3dDevice->BeginScene() ) )
    {
        // Get the projection & view matrix from the camera class
        D3DXMATRIXA16 mViewProjection = ( *g_Camera.GetViewMatrix() ) * ( *g_Camera.GetProjMatrix() );

        g_Skybox.SetDrawSH( false );
        g_Skybox.Render( &mViewProjection, 1.0f, 1.0f );

        V( g_pEffect->SetMatrix( "g_mViewProjection", &mViewProjection ) );
        V( g_pEffect->SetFloat( "g_fTime", ( float )fTime ) );

        // Set the amount of transmitted light per color channel
        D3DXVECTOR3 vColorTransmit;
        vColorTransmit.x = g_SampleUI.GetSlider( IDC_RED_TRANSMIT_SLIDER )->GetValue() / 1000.0f;
        vColorTransmit.y = g_SampleUI.GetSlider( IDC_GREEN_TRANSMIT_SLIDER )->GetValue() / 1000.0f;
        vColorTransmit.z = g_SampleUI.GetSlider( IDC_BLUE_TRANSMIT_SLIDER )->GetValue() / 1000.0f;
        V( g_pEffect->SetFloatArray( "g_vColorTransmit", vColorTransmit, 3 ) );

        // for Cubic degree rendering
        V( g_pEffect->SetFloat( "g_fLightIntensity", g_fLightIntensity ) );
        V( g_pEffect->SetFloatArray( "g_vLightDirection", g_vLightDirection, 3 * sizeof( float ) ) );
        V( g_pEffect->SetFloatArray( "g_vLightCoeffsR", m_fRLC, 4 * sizeof( float ) ) );
        V( g_pEffect->SetFloatArray( "g_vLightCoeffsG", m_fGLC, 4 * sizeof( float ) ) );
        V( g_pEffect->SetFloatArray( "g_vLightCoeffsB", m_fBLC, 4 * sizeof( float ) ) );

        pd3dDevice->SetRenderState( D3DRS_FILLMODE, g_bWireFrame ? D3DFILL_WIREFRAME : D3DFILL_SOLID );

        DrawFrame( pd3dDevice, g_pFrameRoot );

        DXUT_BeginPerfEvent( DXUT_PERFEVENTCOLOR, L"HUD / Stats" ); // These events are to help PIX identify what the code is doing
        RenderText();
        V( g_HUD.OnRender( fElapsedTime ) );
        V( g_SampleUI.OnRender( fElapsedTime ) );
        V( g_LightControl.OnRender9( D3DXCOLOR( 1, 1, 1, 1 ), ( D3DXMATRIX* )g_Camera.GetViewMatrix(),
                                     ( D3DXMATRIX* )g_Camera.GetProjMatrix(), g_Camera.GetEyePt() ) );
        DXUT_EndPerfEvent();

        V( pd3dDevice->EndScene() );
    }
}
Exemple #24
0
//--------------------------------------------------------------------------------------
// Initialize the app 
//--------------------------------------------------------------------------------------
void InitApp()
{ 
  // Initialize dialogs
  g_D3DSettingsDlg.Init( &g_DialogResourceManager );
  g_SampleUI.Init( &g_DialogResourceManager );
  g_HUD.Init( &g_DialogResourceManager );
  
  g_HUD.SetCallback( OnGUIEvent ); INT iY = 10;
  
  // Add tons of GUI stuff
  g_HUD.AddButton( IDC_TOGGLEFULLSCREEN, L"Toggle full screen", 0, iY, 170, 23 );
  g_HUD.AddButton( IDC_CHANGEDEVICE, L"Change device (F2)", 0, iY += 26, 170, 23, VK_F2 );
  g_HUD.AddButton( IDC_TOGGLEWARP, L"Toggle WARP (F4)", 0, iY += 26, 170, 23, VK_F4 );
  
  g_HUD.AddCheckBox( IDC_TOGGLEDYNAMICLIGHTS, L"Dynamic Lights", 0, iY+=26, 170, 23, true, VK_F8 );

  g_HUD.AddComboBox( IDC_DEBUGRENDERING, 0, iY +=26,  170, 23, VK_F9, false, &g_DebugRenderingCombo );

  g_DebugRenderingCombo->AddItem( L"Scene",     ULongToPtr( DEBUG_RENDERING_NONE     ) );
  g_DebugRenderingCombo->AddItem( L"Normals",   ULongToPtr( DEBUG_RENDERING_NORMALS  ) );
  g_DebugRenderingCombo->AddItem( L"Colors",    ULongToPtr( DEBUG_RENDERING_COLORS   ) );
  g_DebugRenderingCombo->AddItem( L"LLL",       ULongToPtr( DEBUG_RENDERING_LLL      ) );

  g_SampleUI.SetCallback( OnGUIEvent ); iY = 10;
}
Exemple #25
0
Slider::Slider( CDXUTDialog& dialog, int id, int& y, const wchar_t* label, int min, int max, int& value ) :
	m_Value( value ),
	m_szLabel( label )
{
	dialog.AddStatic( id + 1000000, L"", AMD::HUD::iElementOffset, y += AMD::HUD::iElementDelta, AMD::HUD::iElementWidth, AMD::HUD::iElementHeight, false, &m_pLabel );
	dialog.AddSlider( id, AMD::HUD::iElementOffset, y += AMD::HUD::iElementDelta, AMD::HUD::iElementWidth, AMD::HUD::iElementHeight, min, max, m_Value, false, &m_pSlider );

	dialog.AddControl( this );

	OnGuiEvent();
}
Exemple #26
0
//--------------------------------------------------------------------------------------
// Initialize the app 
//--------------------------------------------------------------------------------------
void InitApp()
{
    // Initialize dialogs
    g_SettingsDlg.Init( &g_DialogResourceManager );
    g_HUD.Init( &g_DialogResourceManager );

    g_HUD.SetCallback( OnGUIEvent ); int iY = 10;
    g_HUD.AddButton( IDC_TOGGLEFULLSCREEN, L"Toggle full screen", 35, iY, 125, 22 );
    g_HUD.AddButton( IDC_TOGGLEREF, L"Toggle REF (F3)", 35, iY += 24, 125, 22 );
    g_HUD.AddButton( IDC_CHANGEDEVICE, L"Change device (F2)", 35, iY += 24, 125, 22, VK_F2 );
}
LRESULT CALLBACK MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing, void* pUserContext)
{
    *pbNoFurtherProcessing = g_HUD.MsgProc(hWnd, uMsg, wParam, lParam);
    if(*pbNoFurtherProcessing)
        return 0;
    *pbNoFurtherProcessing = g_SampleUI.MsgProc(hWnd, uMsg, wParam, lParam);
    if(*pbNoFurtherProcessing)
        return 0;

    g_Camera.HandleMessages(hWnd, uMsg, wParam, lParam);

    return 0;
}
void InitApp() {   
    dprintf("rawr\n");    

    srand(UINT(time(NULL)));

    g_pGameRoot = new CGameRoot();

    g_pGameRoot->AssignWorldFile(LEVEL_TO_LOAD);
    g_pGameRoot->AssignModelSetFile(MODEL_SET_TO_LOAD);
    g_pGameRoot->AssignCharacterSetFile(CHAR_SET_TO_LOAD);
    g_pGameRoot->AssignSpriteAnimationSetFile(SPRITE_SET_TO_LOAD);

    g_pGameRoot->LoadMasterServersFile(MASTER_SERVERS_TO_LOAD);

    // Initialize dialogs
    g_SettingsDlg.Init( &g_DialogResourceManager );
    g_HUD.Init( &g_DialogResourceManager );
    g_UI.Init( &g_DialogResourceManager );

    // Set up HUD
    g_HUD.SetCallback( OnGUIEvent ); int iY = 0; 
    g_HUD.AddButton( IDC_TOGGLEFULLSCREEN, L"Toggle full screen", 0, iY, 125, 22 );    
    g_HUD.AddButton( IDC_CHANGEDEVICE, L"Change device (F2)", 0, iY += 24, 125, 22, VK_F2 );

    // Set up UI
    g_UI.SetCallback( OnGUIEvent ); iY = 0;
    CDXUTEditBox *pEditBox;
    g_UI.AddEditBox( IDC_FILEHEIGHTMAP, L"rawr", 5, iY, 210, 20, false, &pEditBox );
    if( pEditBox )
    {
        pEditBox->SetBorderWidth( 1 );
        pEditBox->SetSpacing( 2 );        
    }
    g_UI.AddButton( IDC_LOADHEIGHTMAP, L"Load HeightMap", 0, iY += 24, 100, 22 );    
}
Exemple #29
0
//--------------------------------------------------------------------------------------
// Handle messages to the application
//--------------------------------------------------------------------------------------
LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing,
                          void* pUserContext )
{
    // Pass messages to dialog resource manager calls so GUI state is updated correctly
    *pbNoFurtherProcessing = g_DialogResourceManager.MsgProc( hWnd, uMsg, wParam, lParam );
    if( *pbNoFurtherProcessing )
        return 0;

    // Pass messages to settings dialog if its active
    if( g_SettingsDlg.IsActive() )
    {
        g_SettingsDlg.MsgProc( hWnd, uMsg, wParam, lParam );
        return 0;
    }

    // Give the dialogs a chance to handle the message first
    *pbNoFurtherProcessing = g_HUD.MsgProc( hWnd, uMsg, wParam, lParam );
    if( *pbNoFurtherProcessing )
        return 0;
    *pbNoFurtherProcessing = g_SampleUI.MsgProc( hWnd, uMsg, wParam, lParam );
    if( *pbNoFurtherProcessing )
        return 0;


	// mouse handles
	switch( uMsg )
    {
		// pick
        case WM_LBUTTONDOWN:
        {
            // Capture the mouse, so if the mouse button is 
            // released outside the window, we'll get the WM_LBUTTONUP message
            
            return TRUE;
        }
		case WM_LBUTTONDBLCLK:
        {
			SetCapture( hWnd );
            break;
        }
		default:
		{
			ReleaseCapture();
			break;
		}
	}

    return 0;
}
//--------------------------------------------------------------------------------------
// Create any D3D11 resources that depend on the back buffer
//--------------------------------------------------------------------------------------
HRESULT CALLBACK OnD3D11ResizedSwapChain( ID3D11Device* pd3dDevice, IDXGISwapChain* pSwapChain,
                                          const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext )
{
    HRESULT hr;

    V_RETURN( g_DialogResourceManager.OnD3D11ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) );
    V_RETURN( g_D3DSettingsDlg.OnD3D11ResizedSwapChain( pd3dDevice, pBackBufferSurfaceDesc ) );

    // Setup the camera's projection parameters
    float fAspectRatio = pBackBufferSurfaceDesc->Width / ( FLOAT )pBackBufferSurfaceDesc->Height;
    g_Camera.SetProjParams( D3DX_PI / 4, fAspectRatio, 2.0f, 4000.0f );
	//    g_Camera.SetWindow( pBackBufferSurfaceDesc->Width, pBackBufferSurfaceDesc->Height );
	//    g_Camera.SetButtonMasks( MOUSE_MIDDLE_BUTTON, MOUSE_WHEEL, MOUSE_LEFT_BUTTON );


	D3DXVECTOR3 vMin = D3DXVECTOR3( -1000.0f, -1000.0f, -1000.0f );
    D3DXVECTOR3 vMax = D3DXVECTOR3( 1000.0f, 1000.0f, 1000.0f );
    g_Camera.SetRotateButtons(TRUE, FALSE, FALSE);
	
	
    g_Camera.SetScalers( 0.01f, 30.0f );
    g_Camera.SetDrag( true );
    g_Camera.SetEnableYAxisMovement( true );
    g_Camera.SetClipToBoundary( TRUE, &vMin, &vMax );
    g_Camera.FrameMove( 0 );


    g_HUD.SetLocation( pBackBufferSurfaceDesc->Width - 170, 0 );
    g_HUD.SetSize( 170, 170 );
    g_SampleUI.SetLocation( pBackBufferSurfaceDesc->Width - 170, pBackBufferSurfaceDesc->Height - 300 );
    g_SampleUI.SetSize( 170, 300 );

	//Turn off backface culling
	D3D11_RASTERIZER_DESC rsDesc;
	ZeroMemory(&rsDesc,sizeof(D3D11_RASTERIZER_DESC) );
	rsDesc.CullMode = D3D11_CULL_NONE;
	rsDesc.FillMode = D3D11_FILL_SOLID;
	//rsDesc.FillMode = D3D11_FILL_WIREFRAME;
	
	
	ID3D11RasterizerState *pRasterizerState = NULL;
	pd3dDevice->CreateRasterizerState(&rsDesc, &pRasterizerState);
	
	DXUTGetD3D11DeviceContext()->RSSetState(pRasterizerState);

	SAFE_RELEASE(pRasterizerState);

    return S_OK;
}