Example #1
0
int Renderer::startEngine(HWND hwnd, Model& model) {
	HRESULT r = 0;//return values

	pD3D_ = Direct3DCreate9(D3D_SDK_VERSION);//COM object
	if (pD3D_ == NULL) {
		Errors::SetError(TEXT("Could not create IDirect3D9 object"));
		return E_FAIL;
	}

	//4th argument is TRUE or FALSE, where FALSE means fullscreen.
	r = InitDirect3DDevice(hwnd, model.getWidth(), model.getHeight(), WINDOWED_MODE, D3DFMT_X8R8G8B8, pD3D_, &pDevice_);
	if (FAILED(r)) {//FAILED is a macro that returns false if return value is a failure - safer than using value itself
		Errors::SetError(TEXT("Initialization of the device failed"));
		return E_FAIL;
	}

	r = pDevice_->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer_);
	if (FAILED(r)) {
		Errors::SetError(TEXT("Couldn't get backbuffer"));
	}

	return S_OK;
}
Example #2
0
//-----------------------------------------------------------------------------
// Desc: 初始化Direct3D
//-----------------------------------------------------------------------------
HRESULT InitD3D( HWND hWnd )
{
	//创建Direct3D对象, 该对象用于创建Direct3D设备对象
	if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
		return E_FAIL;

	//设置D3DPRESENT_PARAMETERS结构, 准备创建Direct3D设备对象
	D3DPRESENT_PARAMETERS d3dpp; 
	ZeroMemory( &d3dpp, sizeof(d3dpp) );
	d3dpp.Windowed = TRUE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
	d3dpp.EnableAutoDepthStencil = TRUE;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

	//创建Direct3D设备对象
	if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
		&d3dpp, &g_pd3dDevice ) ) )
	{
		return E_FAIL;
	}

	//设置纹理过滤状态
	g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
	g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
	g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );

	//设置观察矩阵和投影矩阵
	SetViewAndProjMatrix();

	ZeroMemory( m_bKey, 256 );
	D3DXMatrixIdentity(&g_matWorld);

	return S_OK;
}
Example #3
0
	int D3DDevice::Init(HWND hWnd, bool bWindowed)
	{
		m_hWnd = hWnd;
		if( NULL == ( m_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
			return -1;

		memset(&m_kCaps, 0, sizeof(D3DCAPS9));
		m_pD3D->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &m_kCaps);
		
		int vp = m_kCaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ? D3DCREATE_HARDWARE_VERTEXPROCESSING : D3DCREATE_SOFTWARE_VERTEXPROCESSING;
		
		memset( &m_kD3Dpp, 0, sizeof( m_kD3Dpp ) );
		m_kD3Dpp.Windowed = bWindowed;
		m_kD3Dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
		m_kD3Dpp.BackBufferFormat = D3DFMT_UNKNOWN;
		m_kD3Dpp.EnableAutoDepthStencil = TRUE;
		m_kD3Dpp.AutoDepthStencilFormat = D3DFMT_D16;

		// Create the D3DDevice
		if( FAILED( m_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWnd,
										  vp,
										  &m_kD3Dpp, &m_pd3dDevice ) ) )
		{
			return -1;
		}

		// Turn off culling
		m_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );

		// Turn off D3D lighting
		m_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );

		// Turn on the zbuffer
		m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );

		return 0;
	}
Example #4
0
//-----------------------------------------------------------------------------
// Desc: 初始化Direct3D
//-----------------------------------------------------------------------------
HRESULT InitD3D( HWND hWnd )
{
    HRESULT hr = S_OK;

    //创建Direct3D对象, 该对象用来创建Direct3D设备对象
    if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
        return E_FAIL;

    //设置D3DPRESENT_PARAMETERS结构, 准备创建Direct3D设备对象
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory( &d3dpp, sizeof(d3dpp) );
    d3dpp.Windowed         = TRUE;
    d3dpp.SwapEffect       = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
    d3dpp.MultiSampleType  = D3DMULTISAMPLE_4_SAMPLES;

    //创建Direct3D设备对象
    if(FAILED(g_pD3D->CheckDeviceMultiSampleType (D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL
              ,D3DFMT_X8R8G8B8,FALSE,D3DMULTISAMPLE_4_SAMPLES,NULL)))
    {
        MessageBox(hWnd, L"硬件不支持多采样反锯齿!\n采用参考设备!"
                   , L"AntiAlisa", 0);
        hr = g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, hWnd,
                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                   &d3dpp, &g_pd3dDevice );
    }
    else
    {
        hr = g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                   D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                   &d3dpp, &g_pd3dDevice );
    }

    //在此设置整个程序运行期间不变换的渲染状态

    return hr;
}
FD3D9MeshUtilities::FD3D9MeshUtilities()
	: DummyWindowHandle(0), Direct3D(0), Device(0)
{
	Direct3D = Direct3DCreate9(D3D_SDK_VERSION);

	if(!Direct3D)
	{
		return;
	}

	WNDCLASSEXW wc;

	ZeroMemory(&wc, sizeof(WNDCLASSEXW));

	wc.cbSize = sizeof(WNDCLASSEX);
	wc.lpszClassName = L"DummyWindowClass";
	wc.style = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc = WindowProc;
	wc.hInstance = GetModuleHandle(0);
//	wc.hbrBackground = (HBRUSH)COLOR_WINDOW;

	RegisterClassExW(&wc);

	DummyWindowHandle = CreateWindowExW(NULL, wc.lpszClassName, L"", WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, NULL, NULL, wc.hInstance, NULL);

	D3DPRESENT_PARAMETERS d3dpp;

	ZeroMemory(&d3dpp, sizeof(d3dpp));
	d3dpp.Windowed = 1;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.hDeviceWindow = DummyWindowHandle;
	d3dpp.BackBufferWidth = 1;
	d3dpp.BackBufferHeight = 1;
	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

	Direct3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, DummyWindowHandle, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &Device);
}
Example #6
0
//-----------------------------------------------------------------------------
// Desc: 初始化Direct3D
//-----------------------------------------------------------------------------
HRESULT InitD3D( HWND hWnd )
{
	//创建Direct3D对象, 该对象用于创建Direct3D设备对象
	if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
		return E_FAIL;

	//设置D3DPRESENT_PARAMETERS结构, 准备创建Direct3D设备对象
	D3DPRESENT_PARAMETERS d3dpp; 
	ZeroMemory( &d3dpp, sizeof(d3dpp) );
	d3dpp.Windowed = TRUE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

	//创建Direct3D设备对象
	if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
		&d3dpp, &g_pd3dDevice ) ) )
	{
		return E_FAIL;
	}

	//禁用照明效果
	g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE ); 

	//设置纹理渲染状态
	g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_SELECTARG1 );
	g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );

	//设置纹理过滤方式
	g_pd3dDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);

	//设置变换矩阵
	SetupMatrices();

	return S_OK;
}
HRESULT GraphicsEngine::InitD3D( HWND hWnd )
{
    // Create the D3D object.
    if( NULL == ( m_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
        return E_FAIL;

    // Set up the structure used to create the D3DDevice
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory( &d3dpp, sizeof( d3dpp ) );
    d3dpp.Windowed			= TRUE;
    d3dpp.SwapEffect		= D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat	= D3DFMT_UNKNOWN;

	d3dpp.EnableAutoDepthStencil	= TRUE;
	d3dpp.AutoDepthStencilFormat	= D3DFMT_D16;

    // Create the D3DDevice
    if( FAILED( m_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      &d3dpp, &m_pDevice ) ) )
    {
        return E_FAIL;
    }
	
	//m_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);

    // Turn off culling, so we see the front and back of the triangle
    m_pDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );

    // Turn off D3D lighting, since we are providing our own vertex colors
    m_pDevice->SetRenderState( D3DRS_LIGHTING, FALSE );

	// Turn on the z-buffer
	m_pDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
	
    return S_OK;
}
	HRESULT DirectX9Renderer::InitDevice(D3DPRESENT_PARAMETERS d3dpp)
	{
		// Create the D3D object, which is needed to create the D3DDevice.
		if( NULL == ( m_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
			return E_FAIL;

		////D3DCREATE_PUREDEVICE
		////D3DCREATE_MULTITHREADED
		//if( FAILED( m_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWindow,
		//	D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED,
		//	&d3dpp, &m_pd3dDevice ) ) )
		//{
		//	if( FAILED( m_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWindow,
		//		D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED,
		//		&d3dpp, &m_pd3dDevice ) ) )
		//	{
		//		m_pd3dDevice=NULL;
		//		return E_FAIL;
		//	}
		//}

		// determine what type of vertex processing to use based on the device capabilities
		DWORD dwVertexProcessing = GetVertexProcessingCaps(m_pD3D);
		// create the D3D device
		if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWindow,
			//dwVertexProcessing | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
			dwVertexProcessing | D3DCREATE_MULTITHREADED,
			//dwVertexProcessing, //Very slow
			&d3dpp, &m_pd3dDevice))){
				return E_FAIL;
		}

		m_pd3dDevice->GetRenderTarget(0,&m_pBackBuffer);
		m_pd3dDevice->GetDepthStencilSurface(&m_pZStencilSurface);

		return S_OK;
	}
Example #9
0
bool initDirect3D(void)
{
    if (NULL == (pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
    {
        return false;
    }

    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp,sizeof(D3DPRESENT_PARAMETERS));

    DWORD flags = D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE | D3DCREATE_NOWINDOWCHANGES
            | D3DCREATE_MULTITHREADED;

    d3dpp.Windowed = true;
    d3dpp.Flags = 0;
    d3dpp.BackBufferCount = 0;
    d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
    d3dpp.BackBufferHeight = HEIGHT;
    d3dpp.BackBufferWidth = WIDTH;
    d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.hDeviceWindow = hWnd;
    d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
    d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;

    if (FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, flags, &d3dpp, &dev)))
    {
        return false;
    }

    if (FAILED(dev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer)))
    {
        return false;
    }

    return true;
}
Example #10
0
		bool DirectX9::InitializeContext( Gwen::WindowProvider* pWindow )
		{
			HWND pHWND = ( HWND ) pWindow->GetWindow();
			m_pD3D = Direct3DCreate9( D3D_SDK_VERSION );

			if ( !m_pD3D ) { return false; }

			D3DCAPS9 D3DCaps;
			m_pD3D->GetDeviceCaps( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &D3DCaps );
			DWORD BehaviourFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;

			if ( D3DCaps.VertexProcessingCaps != 0 ) { BehaviourFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING; }

			D3DPRESENT_PARAMETERS Params;
			FillPresentParameters( pWindow, Params );
			HRESULT hr = m_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, pHWND, D3DCREATE_HARDWARE_VERTEXPROCESSING, &Params, &m_pDevice );

			if ( FAILED( hr ) )
			{
				return false;
			}

			return true;
		}
Example #11
0
bool Direct3D9Video::Init (bool fFirstInit_)
{
    TRACE("Direct3D9Video::Init()\n");

    // If hardware acceleration is disabled we should fall back on DirectDraw software
    if (!GetOption(hwaccel))
        return false;

    // D3D.DLL is delay-loaded, so be prepared for this to fail if it's not available
    __try
    {
        m_pd3d = Direct3DCreate9(D3D_SDK_VERSION);
    }
    __except (EXCEPTION_EXECUTE_HANDLER)
    {
        TRACE("D3D9.dll not found!\n");
        return false;
    }

    CreateDevice();
    UpdateSize();

    return m_pd3d != NULL;
}
//-----------------------------------------------------------------------------
// Name: InitD3D()
// Desc: Initializes Direct3D
//-----------------------------------------------------------------------------
HRESULT InitD3D( HWND hWnd )
{
    // Create the D3D object.
    if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
        return E_FAIL;

    // Set up the structure used to create the D3DDevice. Since we are now
    // using more complex geometry, we will create a device with a zbuffer.
    D3DPRESENT_PARAMETERS d3dpp;
    //ZeroMemory( &d3dpp, sizeof( d3dpp ) );
	vp_os_memset(&d3dpp, 0, sizeof( d3dpp ));
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
    d3dpp.EnableAutoDepthStencil = TRUE;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

    // Create the D3DDevice
    if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      &d3dpp, &g_pd3dDevice ) ) )
    {
        return E_FAIL;
    }

    // Turn off culling
    g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );

    // Turn off D3D lighting
    g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );

    // Turn on the zbuffer
    g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );

    return S_OK;
}
Example #13
0
// this function initializes and prepares Direct3D for use
void initD3D(HWND hWnd)
{
    d3d = Direct3DCreate9(D3D_SDK_VERSION);

    D3DPRESENT_PARAMETERS d3dpp;

    ZeroMemory(&d3dpp, sizeof(d3dpp));
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.hDeviceWindow = hWnd;
    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dpp.BackBufferWidth = SCREEN_WIDTH;
    d3dpp.BackBufferHeight = SCREEN_HEIGHT;

    // create a device class using this information and the info from the d3dpp stuct
    d3d->CreateDevice(D3DADAPTER_DEFAULT,
                      D3DDEVTYPE_HAL,
                      hWnd,
                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                      &d3dpp,
                      &d3ddev);

    init_graphics();    // call the function to initialize the triangle
}
Example #14
0
//-----------------------------------------------------------------------------
// Name: InitD3D()
// Desc: Initializes Direct3D
//-----------------------------------------------------------------------------
HRESULT InitD3D( HWND hWnd )
{
    // Create the D3D object, which is needed to create the D3DDevice.
    if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
        return E_FAIL;

    // Set up the structure used to create the D3DDevice. Most parameters are
    // zeroed out. We set Windowed to TRUE, since we want to do D3D in a
    // window, and then set the SwapEffect to "discard", which is the most
    // efficient method of presenting the back buffer to the display.  And 
    // we request a back buffer format that matches the current desktop display 
    // format.
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory( &d3dpp, sizeof( d3dpp ) );
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

    // Create the Direct3D device. Here we are using the default adapter (most
    // systems only have one, unless they have multiple graphics hardware cards
    // installed) and requesting the HAL (which is saying we want the hardware
    // device rather than a software one). Software vertex processing is 
    // specified since we know it will work on all cards. On cards that support 
    // hardware vertex processing, though, we would see a big performance gain 
    // by specifying hardware vertex processing.
    if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      &d3dpp, &g_pd3dDevice ) ) )
    {
        return E_FAIL;
    }

    // Device state would normally be set here

    return S_OK;
}
Example #15
0
void d3d_control::initD3D(HWND hWnd)
{
    d3d = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface

    D3DPRESENT_PARAMETERS d3dpp;    // create a struct to hold various device information

    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use
    d3dpp.Windowed = TRUE;    // program windowed, not fullscreen
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames
    d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D
	d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
	d3dpp.EnableAutoDepthStencil = TRUE;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;


    // create a device class using this information and the info from the d3dpp stuct
    d3d->CreateDevice(D3DADAPTER_DEFAULT,
                      D3DDEVTYPE_HAL,
                      hWnd,
                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                      &d3dpp,
                      &d3ddev);
	
	d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE);    // turn off the 3D lighting
    d3ddev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);    // turn off culling
    d3ddev->SetRenderState(D3DRS_ZENABLE, TRUE);    // turn on the z-buffer
	d3ddev->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 50, 50));    // ambient light
	
	d3ddev->SetRenderState(D3DRS_FILLMODE,D3DFILL_SOLID);

	init_axis();
	init_text();
	rs.create();
	fillmode_changed=false;
	is_solid = true;
}
Example #16
0
//---------------------------------------------------------------------------------------------
void TMainForm::MakeDevice()
{
  // Создание объекта Direct3D
  m_pD3D = Direct3DCreate9( D3D_SDK_VERSION);
  if( !m_pD3D )
    BL_FIX_BUG();

  // Создание устройства рендера.
  D3DPRESENT_PARAMETERS d3dpp = {0};
  d3dpp.Windowed = TRUE;
  d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
  d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
  d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
  d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
  d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
  d3dpp.EnableAutoDepthStencil = TRUE;
  d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
  HRESULT hr;
  hr = m_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, winId(),
    D3DCREATE_SOFTWARE_VERTEXPROCESSING,
    &d3dpp, &m_pd3dDevice );
  if( FAILED(hr) || !m_pd3dDevice)
    BL_FIX_BUG();
}
Example #17
0
bool DirectxCheck::checkDirectx9(void)
{
	IDirect3D9 *d3d; 
    D3DCAPS9 d3d9caps;
    int count;
    d3d = Direct3DCreate9(D3D_SDK_VERSION);
    if( d3d == NULL)
    {
         MessageBox(NULL, "Stars is unable to run.  A DirectX 9.0 compatibale video card was not found.", "Stars 4.0 Error", MB_OK);
		 d3d->Release();
		 return false;
    }
	d3d->GetDeviceCaps(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,&d3d9caps);
	if( !(d3d9caps.DevCaps & D3DDEVCAPS_HWRASTERIZATION))
    {
         MessageBox(NULL, "Stars is unable to run.  A DirectX 9.0 compatibale video card was not found.", "Stars 4.0 Error", MB_OK);
		 d3d->Release();
		 return false;
    }

    d3d->Release();

	return true;
}
Example #18
0
/********************************************************************
WixQueryDirectXCaps - entry point for WixQueryDirectXCaps CA

 Called as Type 1 custom action (DLL from the Binary table) from
 Windows Installer to set properties that identify the DirectX
 capabilities ("caps") of the system.
********************************************************************/
extern "C" UINT __stdcall WixQueryDirectXCaps(
    __in MSIHANDLE hInstall
    )
{
#if 0
    ::MessageBoxA(0, "break into debugger now please", "---->> ATTACH TO ME!", MB_ICONEXCLAMATION);
#endif

    HRESULT hr = S_OK;
    DWORD er = ERROR_SUCCESS;
    LPDIRECT3D9 pD3D = NULL;

    hr = WcaInitialize(hInstall, "WixQueryDirectXCaps");
    ExitOnFailure(hr, "failed to initialize");

    pD3D = Direct3DCreate9(D3D_SDK_VERSION);
    ExitOnNull(pD3D, hr, E_FAIL, "Direct3DCreate9 failed");

    D3DCAPS9 d3dCaps;
    hr = pD3D->GetDeviceCaps(
        0,                 // first adapter
        D3DDEVTYPE_HAL,    // fail on non-HAL devices
        &d3dCaps
    );
    ExitOnFailure(hr, "GetDeviceCaps call failed");

    int iVertexShaderVersion = D3DSHADER_VERSION_MAJOR(d3dCaps.VertexShaderVersion) * 100 + D3DSHADER_VERSION_MINOR(d3dCaps.VertexShaderVersion);
    WcaSetIntProperty(L"WIX_DIRECTX_VERTEXSHADERVERSION", iVertexShaderVersion);

    int iPixelShaderVersion = D3DSHADER_VERSION_MAJOR(d3dCaps.PixelShaderVersion) * 100 + D3DSHADER_VERSION_MINOR(d3dCaps.PixelShaderVersion);
    WcaSetIntProperty(L"WIX_DIRECTX_PIXELSHADERVERSION", iPixelShaderVersion);

LExit:
    ReleaseObject(pD3D);
    return WcaFinalize(er = FAILED(hr) ? ERROR_INSTALL_FAILURE : er);
}
Example #19
0
bool cD3DManager::initD3DManager(HWND wndHandle)        // Initialise cD3DManager and create Direct3D object
{
	pD3D = NULL;
	pd3dDevice = NULL;

	// Create the DirectX object
	if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
	{
		return false;
	}

	// Fill the presentation parameters structure
	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory( &d3dpp, sizeof( d3dpp ) );
	d3dpp.Windowed = TRUE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
	d3dpp.BackBufferCount = 1;
	d3dpp.BackBufferHeight = 600;
	d3dpp.BackBufferWidth = 800;
	d3dpp.hDeviceWindow = wndHandle;

	// Create a default DirectX device
	if( FAILED( pD3D->CreateDevice( D3DADAPTER_DEFAULT,
									D3DDEVTYPE_REF,
									wndHandle,
									D3DCREATE_SOFTWARE_VERTEXPROCESSING,
									&d3dpp,
									&pd3dDevice ) ) )
	{
		return false;
	}

	return true;
}
Example #20
0
bool Game::InitDirect3D ()
{
	HRESULT hr;

	// Create our directx interface
	m_pd3d = Direct3DCreate9 (D3D_SDK_VERSION);
	// Check to see if it succeeded
	if (!m_pd3d)
		return false;

	//Initialize Present Parameters
	if (!InitPresentParameters ())
		return false;

	D3DCAPS9 caps;
	DWORD	 behaviour;
	hr = m_pd3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);

	//Check to see if they have hardware transform and lighting
	if ( (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == FALSE ||
		caps.VertexShaderVersion < D3DVS_VERSION (1, 1))
		behaviour = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
	else
		behaviour = D3DCREATE_HARDWARE_VERTEXPROCESSING;

	hr = m_pd3d->CreateDevice (D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hGameWindow,
		behaviour, &m_d3dpp, &m_pd3dDevice);

	if (FAILED (hr))
	{
		MessageBox (NULL, L"Cannot create directx 9 device", L"Fatal Error", MB_OK | MB_ICONERROR);
		return FALSE;
	}

	return true;
}
Example #21
0
HRESULT XFileCreator::CreateDevice() {
    HRESULT hr;

    mDirect3D9 = Direct3DCreate9(D3D_SDK_VERSION);

    D3DPRESENT_PARAMETERS fakeParams;
    fakeParams.BackBufferWidth = 320;
    fakeParams.BackBufferHeight = 240;
    fakeParams.BackBufferFormat = D3DFMT_X8R8G8B8;
    fakeParams.BackBufferCount = 1;
    fakeParams.MultiSampleType = D3DMULTISAMPLE_NONE;
    fakeParams.MultiSampleQuality = 0;
    fakeParams.SwapEffect = D3DSWAPEFFECT_DISCARD;
    fakeParams.hDeviceWindow = GetShellWindow();
    fakeParams.Windowed = true;
    fakeParams.Flags = 0;
    fakeParams.FullScreen_RefreshRateInHz = 0;
    fakeParams.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
    fakeParams.EnableAutoDepthStencil = false;

    hr = mDirect3D9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, NULL,
                                  D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                  &fakeParams, &mDevice);
    if(FAILED(hr))
    {
        hr = mDirect3D9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_NULLREF, NULL,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      &fakeParams, &mDevice);
        if(FAILED(hr))
        {
            SAFE_RELEASE(mDirect3D9)
        }
    }

    return hr;
}
HRESULT InitD3D( HWND hWnd )
{
	// Create the D3D object, which is needed to create the D3DDevice.
	if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
	{
		MessageBoxA(NULL, "Create D3D9 object failed!", "Error", 0) ;
		return E_FAIL;
	}

	D3DPRESENT_PARAMETERS d3dpp; 
	ZeroMemory( &d3dpp, sizeof(d3dpp) );

	d3dpp.Windowed = TRUE; // use window mode, not full screen
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

	// Create device
	if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
		&d3dpp, &g_pd3dDevice ) ) )
	{
		MessageBoxA(NULL, "Create D3D9 device failed!", "Error", 0) ;
		return E_FAIL;
	}

	// Disable lighting, since we didn't specify color for vertex
	g_pd3dDevice->SetRenderState( D3DRS_LIGHTING , FALSE );   

	// Create teapot
	D3DXCreateTeapot(g_pd3dDevice, &g_pTeapotMesh, NULL) ;

	// wire frame
	g_pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);

	return S_OK;
}
Example #23
0
///Create Direct3D Device
HRESULT initD3D(HWND hWnd){

	if(NULL == (g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
		return E_FAIL;
	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));
	d3dpp.Windowed = TRUE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

	if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_HARDWARE_VERTEXPROCESSING,
		&d3dpp, &g_pDevice ) ) ){
		return E_FAIL;
	}

	g_pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
	g_pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);//default is open

	setupViewProjMatrix();
	setupViewPort();

	return S_OK;
}
Example #24
0
HRESULT Engine::CGraphicDev::Ready_GraphicDev(WINMODE Mode, HWND hWnd, const WORD& wSizeX, const WORD& wSizeY)
{
	m_pSDK = Direct3DCreate9(D3D_SDK_VERSION);

	D3DCAPS9		devicecaps;
	ZeroMemory(&devicecaps, sizeof(D3DCAPS9));

	if(FAILED(m_pSDK->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &devicecaps)))
	{
		MSG_BOX("GetDeviceCaps Failed");
		return E_FAIL;
	}

	DWORD		vp;

	if(devicecaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT)
		vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
	else
		vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;

	vp |= D3DCREATE_MULTITHREADED;

	D3DPRESENT_PARAMETERS	d3dpp;
	ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));

	SetParameters(d3dpp, Mode, hWnd, wSizeX, wSizeY);

	if(FAILED(m_pSDK->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL
		, hWnd, vp, &d3dpp, &m_pDevice)))
	{
		MSG_BOX("CreateDevice Failed");
		return E_FAIL;
	}

	return S_OK;
}
Example #25
0
HRESULT InitD3D( HWND hWnd )
{
    // Create the D3D object.
    if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
        return E_FAIL;

    // Set up the structure used to create the D3DDevice. Since we are now
    // using more complex geometry, we will create a device with a zbuffer.
    ZeroMemory( &d3dpp, sizeof(d3dpp) );
    d3dpp.Windowed = TRUE;
	d3dpp.BackBufferFormat = (d3dpp.Windowed)?D3DFMT_UNKNOWN:D3DFMT_X8R8G8B8 ;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.EnableAutoDepthStencil = TRUE;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
	d3dpp.BackBufferCount = backbuffercount;
	d3dpp.PresentationInterval = vsync ? D3DPRESENT_INTERVAL_DEFAULT : D3DPRESENT_INTERVAL_IMMEDIATE;
	vsync_current = vsync;
    // Create the D3DDevice
    if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                      ((d3dcreate_software_vertexprocessing)? D3DCREATE_SOFTWARE_VERTEXPROCESSING :D3DCREATE_HARDWARE_VERTEXPROCESSING),
                                      &d3dpp, &g_pd3dDevice ) ) )
    {
		if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
										  D3DCREATE_SOFTWARE_VERTEXPROCESSING,
										  &d3dpp, &g_pd3dDevice ) ) )
			if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, hWnd,
											  D3DCREATE_SOFTWARE_VERTEXPROCESSING,
											  &d3dpp, &g_pd3dDevice ) ) )
		        return E_FAIL;
    }

    g_pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); // Turn off culling
    g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );  // Turn off D3D lighting
    g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );     // Turn on the zbuffer
    return S_OK;
}
Example #26
0
void CDrawManager::initDirectX()
{
	// Create the D3D object.
	if( NULL == ( m_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
        return ;

    // Set up the structure used to create the D3DDevice. Since we are now
    // using more complex geometry, we will create a device with a zbuffer.
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory( &d3dpp, sizeof( d3dpp ) );
#if _DEBUG
    d3dpp.Windowed = TRUE;
#else 
	d3dpp.Windowed = FALSE;
#endif
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
	d3dpp.EnableAutoDepthStencil = TRUE;
	d3dpp.BackBufferWidth = m_pScreenSize.x;
	d3dpp.BackBufferHeight = m_pScreenSize.y;
	d3dpp.BackBufferCount = 1;



    // Create the D3DDevice
    if( FAILED( m_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      &d3dpp, &m_pd3dDevice ) ) )
    {
        return ;
    }

	//스프라이트 생성
	D3DXCreateSprite(m_pd3dDevice,&m_pd3dSprite);
}
Example #27
0
HRESULT InitD3D( HWND hWnd )
{
    g_pD3D = Direct3DCreate9( D3D_SDK_VERSION );

    if( !g_pD3D ) return E_FAIL;

    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory( &d3dpp, sizeof(d3dpp) );
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

    if( FAILED( g_pD3D->CreateDevice( 
                    D3DADAPTER_DEFAULT,
                    D3DDEVTYPE_HAL,
                    hWnd,
                    D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                    &d3dpp, &g_pd3dDevice ) ) )
    {
        return E_FAIL;
    }

    return S_OK;
}
Example #28
0
/**
 * This function is only called in non-native mode
 * Its responsibility is to initialize D3D, create a device and a device manager
 * and call SetD3DDeviceManager with it.
 */
HRESULT CDecDXVA2::InitD3D()
{
  HRESULT hr = S_OK;

  if (FAILED(hr = LoadDXVA2Functions())) {
    DbgLog((LOG_ERROR, 10, L"-> Failed to load DXVA2 DLL functions"));
    return E_FAIL;
  }

  m_pD3D = Direct3DCreate9(D3D_SDK_VERSION);
  if (!m_pD3D) {
    DbgLog((LOG_ERROR, 10, L"-> Failed to acquire IDirect3D9"));
    return E_FAIL;
  }

  int lAdapter = D3DADAPTER_DEFAULT;

  D3DADAPTER_IDENTIFIER9 d3dai = {0};
  m_pD3D->GetAdapterIdentifier(lAdapter, 0, &d3dai);

  const char *vendor = "Unknown";
  for (int i = 0; vendors[i].id != 0; i++) {
    if (vendors[i].id == d3dai.VendorId) {
      vendor = vendors[i].name;
      break;
    }
  }

  DbgLog((LOG_TRACE, 10, L"-> Running on adapter %d, %S, vendor 0x%04X(%S), device 0x%04X", lAdapter, d3dai.Description, d3dai.VendorId, vendor, d3dai.DeviceId));
  m_dwVendorId = d3dai.VendorId;
  m_dwDeviceId = d3dai.DeviceId;

  D3DPRESENT_PARAMETERS d3dpp;
  D3DDISPLAYMODE d3ddm;

  ZeroMemory(&d3dpp, sizeof(d3dpp));
  m_pD3D->GetAdapterDisplayMode(lAdapter, &d3ddm);

  d3dpp.Windowed               = TRUE;
  d3dpp.BackBufferWidth        = 640;
  d3dpp.BackBufferHeight       = 480;
  d3dpp.BackBufferCount        = 0;
  d3dpp.BackBufferFormat       = d3ddm.Format;
  d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD;
  d3dpp.Flags                  = D3DPRESENTFLAG_VIDEO;

  hr = m_pD3D->CreateDevice(lAdapter, D3DDEVTYPE_HAL, GetShellWindow(), D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE, &d3dpp, &m_pD3DDev);
  if (FAILED(hr)) {
    DbgLog((LOG_TRACE, 10, L"-> Creation of device failed with hr: %X", hr));
    return E_FAIL;
  }

  hr = CreateD3DDeviceManager(m_pD3DDev, &m_pD3DResetToken, &m_pD3DDevMngr);
  if (FAILED(hr)) {
    DbgLog((LOG_TRACE, 10, L"-> Creation of Device manager failed with hr: %X", hr));
    return E_FAIL;
  }

  hr = SetD3DDeviceManager(m_pD3DDevMngr);
  if (FAILED(hr)) {
    DbgLog((LOG_TRACE, 10, L"-> SetD3DDeviceManager failed with hr: %X", hr));
    return E_FAIL;
  }

  return S_OK;
}
Example #29
0
HRESULT DXRender::initializeD3D(PWND pwnd)
{
	// Device should only be created once
	VASSERT(NULL == d3d, QString_NT("D3D Object already exists"));
	VASSERT(NULL == device, QString_NT("Device already exists"));
	SAFE_RELEASE(device);
	SAFE_RELEASE(d3d);
	
	HRESULT hr = S_OK;
	d3dEx = false;
	
	if (NULL == (d3d = Direct3DCreate9(D3D_SDK_VERSION)))
		return E_FAIL;
	
	D3DDISPLAYMODE displayMode;
	d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode);
	d3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps);
	
	GLOBAL(settings).maxTextureSize = min(caps.MaxTextureHeight, caps.MaxTextureWidth);
	LOG(QString_NT("Max Texture Size: %1").arg(GLOBAL(settings).maxTextureSize));

	if (caps.TextureCaps & D3DPTEXTURECAPS_POW2)
	{
		if (caps.TextureCaps & D3DPTEXTURECAPS_NONPOW2CONDITIONAL)
			LOG(QString_NT("Conditional use of non-power of two textures"));
		else
			LOG(QString_NT("Can not use non power of two textures"));
	}
	else
		LOG(QString_NT("Can use non power of two textures"));
	
	// Log what is supported and what isn't
	hr = d3d->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, displayMode.Format, D3DUSAGE_DYNAMIC, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8);
	if (FAILED(hr))
		LOG(QString_NT("D3DFMT_A8R8G8B8 not supported"));
	
	bool windowed = true;

	// Set up the structure used to create the D3DDevice. Most parameters are
	// zeroed out. We set Windowed to TRUE, since we want to do D3D in a
	// window, and then set the SwapEffect to "discard", which is the most
	// efficient method of presenting the back buffer to the display.  And 
	// we request a back buffer format that matches the current desktop display 
	// format.
	ZeroMemory(&_dummyDevicePresentationParameters, sizeof(_dummyDevicePresentationParameters));
	
	_dummyDevicePresentationParameters.BackBufferCount = 1;
	_dummyDevicePresentationParameters.BackBufferFormat = D3DFMT_UNKNOWN;
	_dummyDevicePresentationParameters.Windowed = windowed;
	_dummyDevicePresentationParameters.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;
	_dummyDevicePresentationParameters.AutoDepthStencilFormat = D3DFMT_D16;
	_dummyDevicePresentationParameters.EnableAutoDepthStencil = TRUE;
	_dummyDevicePresentationParameters.MultiSampleType = D3DMULTISAMPLE_NONE;
	_dummyDevicePresentationParameters.hDeviceWindow = pwnd;
	_dummyDevicePresentationParameters.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
	_dummyDevicePresentationParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
	_dummyDevicePresentationParameters.BackBufferWidth = 1;										// These are set to 1 since the device will be a dummy placeholder
	_dummyDevicePresentationParameters.BackBufferHeight = 1;										// We want to take up as little room as possible in the video memory

	// Copy most parameters from the dummy device and modify the important ones to make
	// our actual swap chain
	_presentationParameters = _dummyDevicePresentationParameters;
	_presentationParameters.BackBufferFormat = displayMode.Format;								// Use D3DFMT_X8R8G8B8 instead of D3DFMT_UNKNOWN to test to anti-aliasing
	_presentationParameters.EnableAutoDepthStencil = FALSE;										// We need to disable the auto creation of the depth buffer so we can make our own
	_presentationParameters.Flags = (DWORD)0;													// Remove the D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL since there is no depth buffer created here
	_presentationParameters.BackBufferWidth = winOS->GetWindowWidth();
	_presentationParameters.BackBufferHeight = winOS->GetWindowHeight();
	_presentationParameters.MultiSampleQuality = 0;
	
	if (GLOBAL(settings).useAntiAliasing)
	{
		DWORD multiSampleQualityLevel = 0;
		if(SUCCEEDED(d3d->CheckDeviceMultiSampleType(caps.AdapterOrdinal, caps.DeviceType, _presentationParameters.BackBufferFormat, windowed, D3DMULTISAMPLE_2_SAMPLES, &multiSampleQualityLevel)))
		{
			_presentationParameters.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;
			LOG(QString_NT("Video card supports multisampling of 2 samples and %1 levels").arg(multiSampleQualityLevel));
		}
		else
		{
			LOG(QString_NT("Video card does not support multisampling"));
		}
	}
	
	DWORD behaviourFlags;
	if (D3DDEVCAPS_HWTRANSFORMANDLIGHT & caps.DevCaps && caps.VertexShaderVersion >= D3DVS_VERSION(1, 1))
	{
		behaviourFlags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
		LOG(QString_NT("Using hardware vertex processing"));
	}
	else
	{
		behaviourFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
		LOG(QString_NT("Using software vertex processing"));
	}
	behaviourFlags |= D3DCREATE_MULTITHREADED;							// For video playback
	behaviourFlags |= D3DCREATE_FPU_PRESERVE;							// Qt WebKit relies on doubles for layout calculations, it crashes randomly if FPU is single precision

	hr = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, pwnd, behaviourFlags, &_dummyDevicePresentationParameters, &device);
	if (FAILED(hr))
	{
		VASSERT(0, QString_NT("Failed to create IDirect3DDevice9"));
		return hr;	
	}
		
	recreateResources();
	
	// Set up the swap chain
	onResize(winOS->GetWindowWidth(), winOS->GetWindowHeight());

	return hr;
}
Example #30
0
//----------------------------------------------------------------------------------
//
//----------------------------------------------------------------------------------
void InitWindow()
{
	WNDCLASS wndClass;
	wchar_t szClassNme[]      =  L"RuntimeSample";
	wndClass.style         = CS_HREDRAW | CS_VREDRAW;
	wndClass.lpfnWndProc   = WndProc;
	wndClass.cbClsExtra    = 0;
	wndClass.cbWndExtra    = 0;
	wndClass.hInstance     = GetModuleHandle(0);
	wndClass.hIcon         = NULL;
	wndClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
	wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wndClass.lpszMenuName  = NULL;
	wndClass.lpszClassName = szClassNme;
	RegisterClass(&wndClass);
	g_window_handle = CreateWindow(
		szClassNme,
		L"RuntimeSample",
		WS_SYSMENU,
		CW_USEDEFAULT,
		CW_USEDEFAULT,
		g_window_width,
		g_window_height,
		NULL,
		NULL,
		GetModuleHandle(0),
		NULL);
	ShowWindow( g_window_handle, true );
	UpdateWindow( g_window_handle );
	
	// COMの初期化
	CoInitializeEx( NULL, NULL );

	// DirectX9の初期化を行う
	D3DPRESENT_PARAMETERS d3dp;
	ZeroMemory(&d3dp, sizeof(d3dp));
	d3dp.BackBufferWidth = g_window_width;
	d3dp.BackBufferHeight = g_window_height;
	d3dp.BackBufferFormat = D3DFMT_X8R8G8B8;
    d3dp.BackBufferCount = 1;      
	d3dp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dp.Windowed = TRUE;
	d3dp.hDeviceWindow = g_window_handle;
	d3dp.EnableAutoDepthStencil = TRUE;
    d3dp.AutoDepthStencilFormat = D3DFMT_D16;

	g_d3d = Direct3DCreate9(D3D_SDK_VERSION);
	
	g_d3d->CreateDevice( 
		D3DADAPTER_DEFAULT,
		D3DDEVTYPE_HAL,
		g_window_handle,
		D3DCREATE_HARDWARE_VERTEXPROCESSING,
		&d3dp,
		&g_d3d_device );
	
	// XAudio2の初期化を行う
	XAudio2Create( &g_xa2 );

	g_xa2->CreateMasteringVoice( &g_xa2_master );
}