Beispiel #1
0
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, INT)
{
	WNDCLASSEX wc={sizeof(WNDCLASSEX), CS_CLASSDC, WinProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, "DX Project 1", NULL};
	RegisterClassEx(&wc);
	HWND hWnd=CreateWindow("DX Project 1", "挺进3D", WS_OVERLAPPEDWINDOW, 50, 50, 500, 500, GetDesktopWindow(), NULL, wc.hInstance, NULL);

	if(hWnd==NULL) return FALSE;

	if(SUCCEEDED(InitializeD3D(hWnd)))
	{
		ShowWindow(hWnd, SW_SHOWDEFAULT);
		UpdateWindow(hWnd);
		if(SUCCEEDED(InitializeVertexBuffer()))
		{
			g_pFont=new CFont(g_pD3DDevice, "宋体", 12, true, false, false);

			GameLoop();

			delete g_pFont;
		}
	}

	CleanUp();

	UnregisterClass("DX Project 1", wc.hInstance);

	return 0;
}
D3DPresentEngine::D3DPresentEngine(HRESULT& hr) : 
    m_hwnd(NULL),
    m_DeviceResetToken(0),
    m_pD3D9(NULL),
    m_pDevice(NULL),
    m_pDeviceManager(NULL),
    m_pSurfaceRepaint(NULL),
	gl_handleD3D(NULL),
	d3d_shared_texture(NULL),
	d3d_shared_surface(NULL)
{
    SetRectEmpty(&m_rcDestRect);

    ZeroMemory(&m_DisplayMode, sizeof(m_DisplayMode));

    hr = InitializeD3D();

    if (SUCCEEDED(hr))
    {
       hr = CreateD3DDevice();
    }

	//bool nvdxInteropEnabled = false;
	//if(wglewIsSupported("WGL_NV_DX_interop"))
	//{
	//	nvdxInteropEnabled = true;
	//}
}
SCERROR GfxD3D7Device::Initialize(GFX_VALUE winmod,GFX_VALUE vmode,GFX_VALUE bpp,bool disable_drv_info)
{
  bpp_     = GFX_UNKNOWN;
  wndMode_ = GFX_UNKNOWN;
  mode_    = GFX_UNKNOWN;
  refrate_ = GFX_UNKNOWN;
  width_   = 0;
  height_  = 0;
  filler_color_ = D3DRGBA(0,0,0,1);
  filler_depth_ = 1.0f;
  modelview_stack_count_ = 0;
  wModeNoMenu_ = false;
  wModeNoFrame_ = false;
  safe_ = true;
  flip_immediate_ = false;
  enableFlipping_ = true;
  enableExclusive_ = true;
  vsync_ = false;

  memset( texpf_, 0, sizeof(texpf_) );

  fail_if_fail(InitializeDDraw());

  {
    DDSCAPS2      ddsCaps2;
    DWORD         dwTotal,dwFree;
    ZeroMemory(&ddsCaps2, sizeof(ddsCaps2));
    ddsCaps2.dwCaps = DDSCAPS_LOCALVIDMEM;
    if ( SUCCEEDED(idraw_->GetAvailableVidMem(&ddsCaps2, &dwTotal, &dwFree) ) )
      video_local_mem_ = dwTotal;
  }

  if ( !disable_drv_info )
  {
    DDDEVICEIDENTIFIER2 idi;
    HRESULT hr = idraw_->GetDeviceIdentifier(&idi,/*D3DENUM_NO_WHQL_LEVEL*/ 0x00000002L);
    if ( hr == (HRESULT)E_INVALIDARG ) hr = idraw_->GetDeviceIdentifier(&idi,0);
    if ( SUCCEEDED(hr) ) {
      Lout << _S*"%?%?" %gfxd3d7 %idi.szDescription;
      Lout << _S*"%?DRIVER %-12? [%?]"
        %gfxd3d7 %idi.szDriver %teggo::GetModuleVersion(idi.szDriver);
    }
  }

  Lout << _S*"%?DDRAW  %-12? [%?]" %gfxd3d7 %"ddraw.dll" %teggo::GetModuleVersion("ddraw.dll");
  Lout << _S*"%?D3DIM  %-12? [%?]" %gfxd3d7 %"d3dim700.dll" %teggo::GetModuleVersion("d3dim700.dll");

  fail_if_fail(InitializeD3D());

  id3d_->EnumDevices(LogHALCaps,this);

  LogVMemSize(+idraw_);
  //Lout << "";

  //fail_if_fail(SetMode(GFX_WINDOWED,GFX_640x480,GFX_UNKNOWN,GFX_UNKNOWN));
  fail_if_fail(SetMode(winmod,vmode,bpp,GFX_UNKNOWN));
  context_restored_ = false;

  return SCE_OK;
}
		void xDeviceManager::CreateGlobalDevice(DeviceType type)
		{
			switch(type)
			{
			case DT_GRAPHICS:
				InitializeD3D();
				break;
			case DT_INPUT:
				InitializeDI();
				break;
			}
		}
//-----------------------------------------------------------------------------
// Name: ToggleFullScreen()
// Desc: Called when user toggles between fullscreen mode and windowed mode
//-----------------------------------------------------------------------------
HRESULT CDXGraphicsContext::DoToggleFullscreen()
{
    // Need device change if going windowed and the current device
    // can only be fullscreen
	
    m_bReady = false;
	
    // Toggle the windowed state
    m_bWindowed = !m_bWindowed;
	
    // Prepare window for windowed/fullscreen change
    AdjustWindowForChange();

	Lock();
	m_pd3dDevice->Reset( &m_d3dpp );
	CRender::GetRender()->CleanUp();
	CleanUp();

    m_pD3D = Direct3DCreate9( D3D_SDK_VERSION );
    if( m_pD3D == NULL )
	{
		TRACE0("Error to create m_pD3D");
		Unlock();
        return DisplayD3DErrorMsg( D3DAPPERR_NODIRECT3D, MSGERR_APPMUSTEXIT );
	}
	InitializeD3D();

	Unlock();

	CRender::g_pRender->SetViewport(0, 0, windowSetting.uViWidth, windowSetting.uViHeight, 0x3FF);

    // When moving from fullscreen to windowed mode, it is important to
    // adjust the window size after resetting the device rather than
    // beforehand to ensure that you get the window size you want.  For
    // example, when switching from 640x480 fullscreen to windowed with
    // a 1000x600 window on a 1024x768 desktop, it is impossible to set
    // the window size to 1000x600 until after the display mode has
    // changed to 1024x768, because windows cannot be larger than the
    // desktop.
    if( m_bWindowed )
    {
		SetWindowLong(m_hWnd, GWL_STYLE, WS_OVERLAPPEDWINDOW);
        SetWindowPos( m_hWnd, HWND_NOTOPMOST,
			m_rcWindowBounds.left, m_rcWindowBounds.top,
			( m_rcWindowBounds.right - m_rcWindowBounds.left ),
			( m_rcWindowBounds.bottom - m_rcWindowBounds.top ),
			SWP_SHOWWINDOW );
    }
    m_bReady = true;
    return S_OK;
}
Beispiel #6
0
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR cmd, int show)
{
    WNDCLASSEX wc = {
        sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0, 0, hInst,
        NULL, NULL, NULL, NULL, L"AppClass", NULL
    };
    RegisterClassEx(&wc);

    HWND hWnd = CreateWindow(L"AppClass", L"Blank Window", WS_OVERLAPPEDWINDOW, 100, 100,
        640, 480, NULL, NULL, hInst, NULL);

    if(InitializeD3D(hWnd, false))
    {
        ShowWindow(hWnd, SW_SHOWDEFAULT);
        UpdateWindow(hWnd);

        MSG msg;

        ZeroMemory(&msg, sizeof(msg));

        while(msg.message != WM_QUIT)
        {
            if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
            else
            {
                RenderScene();
            }
        }

        UnregisterClass(L"AppClass", wc.hInstance);
    }

    if(g_D3D != NULL)
    {
        g_D3D->Release();
        g_D3D = NULL;
    }

    if(g_D3DDevice != NULL)
    {
        g_D3DDevice->Release();
        g_D3DDevice = NULL;
    }

    return 0;
}
Beispiel #7
0
VMR9CustomPresenter::VMR9CustomPresenter(HRESULT& hr)
    : m_RefCount(1)
    , m_pPresentCb(NULL)
    , m_pD3D9(NULL)
    , m_pDevice(NULL)
    , m_pSurfAllocNotify(NULL)
    , m_D3D9Ex(false)
{
    hr = InitializeD3D();

    if (SUCCEEDED(hr))
    {
        hr = CreateD3DDevice();
    }
}
//*****************************************************************************
//
//*****************************************************************************
HRESULT CDXGraphicsContext::Create3D( BOOL bWindowed )
{
    HRESULT hr;
	
 	m_bWindowed = (bWindowed==TRUE);		// Make user Toggle manually for now!

    // Initialize the 3D environment for the app
    if( FAILED( hr = InitializeD3D() ) )
    {
        SAFE_RELEASE( m_pD3D );
        return DisplayD3DErrorMsg( hr, MSGERR_APPMUSTEXIT );
    }
	
    // The app is ready to go
    m_bReady = true;
	
    return S_OK;
}
// Constructor
D3DPresentEngine::D3DPresentEngine(IEVRCallback* callback, IDirect3DDevice9Ex* d3DDevice, HWND hwnd, HRESULT& hr) :
m_hwnd(hwnd),
m_DeviceResetToken(0),
m_pD3D9(NULL),
m_pDevice(d3DDevice),
m_pDeviceManager(NULL),
m_pTextureRepaint(NULL),
m_EVRCallback(callback),
m_Width(0),
m_Height(0)
{
  SetRectEmpty(&m_rcDestRect);

  ZeroMemory(&m_DisplayMode, sizeof(m_DisplayMode));

  hr = InitializeD3D();

  m_pDeviceManager->ResetDevice(m_pDevice, m_DeviceResetToken);
}
D3DPresentEngine::D3DPresentEngine(HRESULT& hr) : 
    m_hwnd(NULL),
    m_DeviceResetToken(0),
    m_pD3D9(NULL),
    m_pDevice(NULL),
    m_pDeviceManager(NULL),
    m_pSurfaceRepaint(NULL)
{
    SetRectEmpty(&m_rcDestRect);

    ZeroMemory(&m_DisplayMode, sizeof(m_DisplayMode));

    hr = InitializeD3D();

    if (SUCCEEDED(hr))
    {
       hr = CreateD3DDevice();
    }
}
Beispiel #11
0
D3D::D3D(int screenWidth, int screenHeight, bool vsync, HWND hwnd, bool fullscreen) :
    m_initialized(false),
    m_vsyncEnabled(vsync),
    m_videoCardMemory(),
    m_videoCardDesc(),
    m_swapChain(0),
    m_device(0),
    m_deviceContext(0),
    m_renderTargetView(0),
    m_depthStencilBuffer(0),
    m_depthStencilState(0),
    m_depthDisabledStencilState(0),
    m_depthStencilView(0),
    m_rasterState(0),
    m_screenWidth(screenWidth),
    m_screenHeight(screenHeight),
    m_alphaEnableBlendingState(0),
    m_alphaDisableBlendingState(0)
{
    m_initialized = InitializeD3D(screenWidth, screenHeight, vsync, hwnd, fullscreen);
    TwInit(TW_DIRECT3D11, m_device);
    TwWindowSize(screenWidth, screenHeight);
}
	D3D9WPFRenderer* D3D9WPFRenderer::createWPFRenderer( const char* inAssetDir, PxU32 initialWidth, PxU32 initialHeight )
	{
		if ( incrementClassReference() == 1 )
		{
			WNDCLASS wndclass;
			memset( &wndclass, 0, sizeof( WNDCLASS ) );

			wndclass.style = CS_HREDRAW | CS_VREDRAW;
			wndclass.lpfnWndProc = DefWindowProc;
			wndclass.lpszClassName = TEXT(APP_NAME);

			RegisterClass(&wndclass);
		}

        HWND hWnd = CreateWindow(TEXT(APP_NAME),
                            TEXT(APP_NAME),
                            WS_OVERLAPPEDWINDOW,
                            0,                   // Initial X
                            0,                   // Initial Y
                            0,                   // Width
                            0,                   // Height
                            NULL,
                            NULL,
                            NULL,
                            NULL);
		if ( hWnd == 0 ) return NULL;

		HMODULE hD3D9 = LoadLibrary(TEXT("d3d9.dll"));
		D3DEXCreateFn exCreateFn = reinterpret_cast<D3DEXCreateFn>( GetProcAddress(hD3D9, "Direct3DCreate9Ex") );
		bool is9x = exCreateFn != NULL;
		IDirect3D9*			d3d = NULL;
		IDirect3DDevice9*	d3dDevice = NULL;
		D3DPRESENT_PARAMETERS d3dpp;
		ZeroMemory(&d3dpp, sizeof(d3dpp));
		d3dpp.Windowed = TRUE;
		d3dpp.BackBufferHeight = 1;
		d3dpp.BackBufferWidth = 1;
		d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
		d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
		d3dpp.hDeviceWindow = hWnd;
		HRESULT result;

		if (is9x)
		{
			result = InitializeD3DEx(NULL, d3dpp, d3d, d3dDevice, exCreateFn);
		}
		else
		{
			result = InitializeD3D(NULL, d3dpp, d3d, d3dDevice);
		}
		PX_ASSERT( result >= 0 );
		if ( result >= 0 )
		{
			bool lockable = !is9x; 
			//We only lock earlier interface, not later ones because the later ones use a hardware transfer mechanism
			//where you seem to not need to lock according to some...
			D3D9WPFRenderer* retval = new D3D9WPFRenderer( hWnd, d3d, d3dDevice, "Direct3d", initialWidth, initialHeight, inAssetDir, !is9x, is9x );
			retval->checkResize( false );	//setup viewport.
			//Can we create a vertex buffer here?
			PX_ASSERT( result == D3D_OK );
			return retval;
		}
		return NULL;
	}