示例#1
0
bool D3DRenderer::Init()
{
	GameLog::GetInstance()->Log(DebugChannel::Main, DebugLevel::Normal, "[D3DRenderer] Beginning Initialisation.");
	GameLog::GetInstance()->Log(DebugChannel::Rendering, DebugLevel::None, "[D3DRenderer] Testing Rendering Channel! %i", 2);
	if (!InitDirect3D()) { return false; }
	InitEffects();
	CreateInputLayer();
	mBufferManager = new D3DBufferManager(md3dDevice);
	GameLog::GetInstance()->Log(DebugChannel::Main, DebugLevel::Normal, "[D3DRenderer] Initialisation Complete.");
	return true;
}
示例#2
0
bool CD3DApplication::Init()
{
	if(!InitMainWindow()) {
		return false;
	}

	if(!InitDirect3D()) {
		return false;
	}

	return true;
}
示例#3
0
文件: Game.cpp 项目: DevCool/CPP_Dev
bool Game::Init ()
{
	//Try and initialize game window
	if (!InitGameWindow ())
		return false;
	//Try and initialize direct 3d
	if (!InitDirect3D ())
		return false;

	//If succeeded
	return true;
}
示例#4
0
/*--------------------------------------------
	メイン
---------------------------------------------*/
int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, int)
{
	// デバッグ ヒープ マネージャによるメモリ割り当ての追跡方法を設定
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

	// XNA Mathライブラリのサポート チェック
    if (XMVerifyCPUSupport() != TRUE)
	{
		DXTRACE_MSG(L"WinMain XMVerifyCPUSupport");
		return 0;
	}

	// アプリケーションに関する初期化
	HRESULT hr = InitApp(hInst);
	if (FAILED(hr))
	{
		DXTRACE_ERR(L"WinMain InitApp", hr);
		return 0;
	}

	// Direct3Dの初期化
	hr = InitDirect3D();
	if (FAILED(hr)) {
		DXTRACE_ERR(L"WinMain InitDirect3D", hr);
		CleanupDirect3D();
		CleanupApp();
		return 0;
	}

	// メッセージ ループ
	MSG msg;
	do
	{
		if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			// アイドル処理
			if (!AppIdle())
				// エラーがある場合,アプリケーションを終了する
				DestroyWindow(g_hWindow);
		}
	} while (msg.message != WM_QUIT);

	// アプリケーションの終了処理
	CleanupApp();

	return (int)msg.wParam;
}
示例#5
0
bool D3D11App::Init()
{
	if (!InitMainWindow())
		return false;

	if (!InitDirect3D())
		return false;
	InitResource();
	float AspectHByW = (float)mClientWidth / (float)mClientHeight;
	g_objTrackballCameraController.ProjParams(DirectX::XM_PI*0.25f, AspectHByW, 1.0f, 1000.0f);
	mTimer.Start();
	return true;
}
示例#6
0
bool D3DApp::Init()
{
	if (!InitMainWindow())
	{
		return FALSE;
	}

	if (!InitDirect3D())
	{
		return FALSE;
	}
	return TRUE;
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    HRESULT hr = E_FAIL;
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
        return -1;
    
    DX_VERIFY(InitDirect3D(m_hWnd));  //(HWND)0x00141B48
    DX_VERIFY(InitVertexBuffer());

    Direct3DUtility::DumpAdapterModes(m_pD3d);

    SetTimer(1,1,NULL);
    return 0;
}
示例#8
0
bool D3DApp::Init()
{
	if (!InitMainWindow())
	{
		return false;
	}

	if (!InitDirect3D())
	{
		return false;
	}
	
	return true;
}
示例#9
0
// --------------------------------------------------------
// Handles the window and Direct3D initialization
// --------------------------------------------------------
bool DirectXGameCore::Init()
{
	// Create the actual window itself (no DirectX yet)
	if(!InitMainWindow())
		return false;

	// Now that the window is ready, initialize
	// DirectX (specifically Direct3D)
	if(!InitDirect3D())
		return false;

	// Everything was set up properly
	return true;
}
示例#10
0
bool DX::Initialize(int icon)
{
	ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));

	if (!InitMainWindow(icon))
		return false;

	if (!InitDirect3D())
		return false;

	ResourceManager::Initialize(device, deviceContext);

	return true;
}
示例#11
0
D3dApp::D3dApp(HINSTANCE hInstance,const tstring& winCaption, D3DDEVTYPE devType, DWORD requestedVp):m_MainWndCaption(winCaption),
																								m_DevType(devType),
																								m_RequestedVp(requestedVp),
																								m_hAppInst(hInstance),
																								m_hMainWnd(NULL),
																								m_pD3dObject(NULL),
																								m_AppPaused(false),
																								m_pMyD3dDevice(NULL)
{
	ZeroMemory(&m_D3dParams, sizeof(m_D3dParams));

	InitMainWindow();
	InitDirect3D();
}
示例#12
0
// µð¹ÙÀ̽º Àç »ý¼º
bool cInitD3D::ReCreateDevice()
{
	// ¸®¼Ò½º ºä Ŭ¸®¾î
	ClearResourceView();

	// µð¹ÙÀ̽º Ŭ¸®¾î
	ClearDevice();

	// µð¹ÙÀ̽º »ý¼º
	if (!InitDirect3D())
		return false;

	// È­¸é À籸¼º
	OnResize();

	return true;
}
bool D3DApp::Init()
{

	if(!InitMainWindow())
		return false;

	if (!InitGraphicsCard())
	{
		OutputDebugString(L"fAILED TO FIND MONITOR / GRAPHICS CARD"); return false;
		return false;
	}
		

	if(!InitDirect3D())
		return false;

	return true;
}
示例#14
0
void D3DApp::Init()
{
	srand((unsigned int)time(0));

	//standard input/ output/ error file pointers
	FILE *fpStdIn, *fpStdOut, *fpStdErr;

	// Enable run-time memory check for debug build
#if defined(DEBUG) | defined(_DEBUG)
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

	if (AllocConsole())
	{
		//Assign the stdin/ stdout/ stderr streams to the newly created console
		_tfreopen_s(&fpStdIn, _T("CONIN$"), _T("r"), stdin);
		_tfreopen_s(&fpStdOut, _T("CONOUT$"), _T("w"), stdout);
		_tfreopen_s(&fpStdErr, _T("CONOUT$"), _T("w"), stderr);
	}
#endif

	InitMainWindow();
	InitDirect3D();

	gDInput = new DirectInput(
		mhAppInstance, mhMainWindow,
		DISCL_NONEXCLUSIVE | DISCL_FOREGROUND,
		DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);

	gTimer = new GameTimer();
	gTimer->Reset();

	HR(gD3DDevice->SetRenderState(D3DRS_LIGHTING, false));
	HR(gD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE));
	//HR(gD3DDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME));

}
int WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in LPSTR lpCmdLine, __in int nShowCmd )
{
	//设计窗口类
	WNDCLASS wndclass;
	wndclass.cbClsExtra=0;
	wndclass.cbWndExtra=0;
	wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
	wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
	wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
	wndclass.hInstance=hInstance;
	wndclass.lpfnWndProc=WinMainProc;
	wndclass.lpszClassName=g_pClassName;
	wndclass.lpszMenuName=NULL;
	wndclass.style=CS_HREDRAW|CS_VREDRAW;

	//注册窗口
	if (!RegisterClass(&wndclass))
	{
		MessageBox(NULL,L"注册窗口失败",L"错误提示",NULL);
		return 1;
	}


	//创建窗口
	HWND hWnd=CreateWindow(g_pClassName,g_pWindowName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,640,480,NULL,NULL,hInstance,NULL);
	if (!hWnd)
	{
		MessageBox(NULL,L"创建窗口失败",L"错误提示",NULL);
		return 1;
	}

	//初始化Direct3D
	InitDirect3D(hWnd);

	//显示窗口
	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
		{
			Direct3DRender();//绘制3D场景
		}
	}

	//取消注册窗口
	UnregisterClass(g_pClassName,wndclass.hInstance);
	return 0;
}
示例#16
0
// the main purpose of this function is to build a window and call DirectX
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int iCmdShow)
{
    const TCHAR szClassName[] = _T("DirectX 8 Tutorial");

    // build us a window
    WNDCLASSEX wndclass =
    {
        sizeof(wndclass),                   // cbSize
        CS_HREDRAW | CS_VREDRAW,            // style
        WndProc,                            // lpfnWndProc
        0,                                  // cbClsExtra
        0,                                  // cbWndExtra
        hInstance,                          // hInstance
        LoadIcon(NULL, IDI_APPLICATION),    // hIcon
        LoadCursor(NULL, IDC_ARROW),        // hCursor
        NULL,                               // hBackground
        NULL,                               // lpszMenuName
        szClassName,                        // lpszClassName
        LoadIcon(NULL, IDI_APPLICATION)     // hIconSm
    };

    RegisterClassEx(&wndclass);

    HWND hwnd = CreateWindow(szClassName,           // lpClassName
                             szClassName,           // lpWindowName
                             WS_OVERLAPPEDWINDOW,   // dwStyle
                             CW_USEDEFAULT,         // x
                             CW_USEDEFAULT,         // y
                             CW_USEDEFAULT,         // nWidth
                             CW_USEDEFAULT,         // nHeight
                             NULL,                  // hwndParent
                             NULL,                  // hMenu
                             hInstance,             // hInstance
                             NULL);                 // lpParam

    // in a real app, you might want to give an error message here
    if(FAILED(InitDirect3D(hwnd)))
        return 0;

    ShowWindow(hwnd, iCmdShow);
    UpdateWindow(hwnd);

    while(1)
    {
        // clear out all the messages before we draw a new frame
        MSG msg;
        while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            if(WM_QUIT == msg.message)
            {
                ShutdownDirect3D();
                return msg.wParam;
            }

            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        // draw a frame and end if we error
        if(FAILED(DrawScene()))
        {
            DestroyWindow(hwnd);
        }
    }
} // WinMain
示例#17
0
// INITIALIZE CORE FUNCTIONS
bool RenderEngine::Init(){

	if (!InitWindow()){
		return false; //gick inte att skapa window
	}

	if (!InitDirect3D(hWindow)){
		return false; //gick inte att skapa Direct3D
	}
	// Sets and creates viewport
	SetViewport();

	//Initialize Shaders and triangle data
	Shaders();
	CreatePlaneData();
	TextureFunc();

	//Font
	Fonts();

	//Import
	
	ImportObj("Objects/testPlayer1.obj", "Objects/testPlayer1.mtl", gDevice, true);
	
	ImportObj("Objects/mapPart1.obj", "Objects/mapPart1.mtl", gDevice, false);
	ImportObj("Objects/mapPart2.obj", "Objects/mapPart2.mtl", gDevice, false);
	ImportObj("Objects/mapPart3.obj", "Objects/mapPart3.mtl", gDevice, false);
	ImportObj("Objects/mapPart4.obj", "Objects/mapPart4.mtl", gDevice, false);
	ImportObj("Objects/mapPart5.obj", "Objects/mapPart5.mtl", gDevice, false);
	ImportObj("Objects/mapPart6.obj", "Objects/mapPart6.mtl", gDevice, false);
	ImportObj("Objects/mapPart7.obj", "Objects/mapPart7.mtl", gDevice, false);
	ImportObj("Objects/mapPart7.obj", "Objects/mapPart7.mtl", gDevice, false);

	

	//LIGHT TEST ZONE BITCHES
	/*float l1Int = 1.0f;
	XMFLOAT3 l1Pos = XMFLOAT3(0.0f, 1.0f, -2.0f);
	XMFLOAT4 l1Amb = XMFLOAT4(1.0f, 1.0f, 1.0f,1.0f);
	XMFLOAT4 l1Diff = XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f);
	XMFLOAT4 l1Spec = XMFLOAT4(0.5f, 0.2f, 0.2f, 1.0f);
	XMFLOAT3 l1Dir = XMFLOAT3(0.0f, -50.0f, 30.0f);*/



	testLight[0] = LightClass(l_Directional, XMFLOAT3(1.0f, 1.0f, -5.0f), true, true);
	testLight[0].lightObject.Color = XMFLOAT4(Colors::White);
	/*testLight[0].ToggleActive();*/

	LightClass snoppe(l_Point, XMFLOAT3(1.0f, 1.0f, 0.0f), true, true);

	testLight[1] = snoppe;
	snoppe.lightObject.Type = 2;
	testLight[1].lightObject.Position = XMFLOAT4(-4.0f, 8.0f, 1.0f, 1.0f);
	testLight[1].lightObject.Color = XMFLOAT4(Colors::LightGoldenrodYellow);
	testLight[1].lightObject.AttConst = 1.0f;
	testLight[1].lightObject.AttLinear = 0.08f;
	testLight[1].lightObject.AttQuadratic = 0.00000f;
	//testLight[1].ToggleActive();
 	globalAmb = XMFLOAT4(Colors::Black);

	D3D11_BUFFER_DESC lbuffDesc;
	ZeroMemory(&lbuffDesc, sizeof(lbuffDesc));
	lbuffDesc.Usage = D3D11_USAGE_DEFAULT;
	lbuffDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
	lbuffDesc.CPUAccessFlags = 0;
	lbuffDesc.MiscFlags = 0;
	lbuffDesc.ByteWidth = sizeof(LightProperties);

	HRESULT hr = gDevice->CreateBuffer(&lbuffDesc, NULL, &lightConstBuff);


	// Material Buffers Init
	ZeroMemory(&lbuffDesc, sizeof(lbuffDesc));
	lbuffDesc.ByteWidth = sizeof(MaterialProperties);
	hr = gDevice->CreateBuffer(&lbuffDesc, NULL, &matConstBuff);



	return true; //om båda funkade så returnera true (y)
}
示例#18
0
void D3DApplication::InitApplication()
{
	InitMainWindow();
	InitDirect3D();
}
示例#19
0
//*************************************************************************************************************
int main(int argc, char* argv[])
{
	ReadResolutionFile();

	LARGE_INTEGER qwTicksPerSec = { 0, 0 };
	LARGE_INTEGER qwTime;
	LONGLONG tickspersec;
	double last, current;
	double delta, accum = 0;

	WNDCLASSEX wc =
	{
		sizeof(WNDCLASSEX),
		CS_OWNDC,
		(WNDPROC)WndProc,
		0L,
		0L,
		GetModuleHandle(NULL),
		NULL,
		LoadCursor(0, IDC_ARROW),
		NULL, NULL, "TestClass", NULL
	};

	RegisterClassEx(&wc);
	SystemParametersInfo(SPI_GETWORKAREA, 0, &workarea, 0);

	RECT rect = { 0, 0, screenwidth, screenheight };
	DWORD style = WS_CLIPCHILDREN|WS_CLIPSIBLINGS;

	// windowed mode
	style |= WS_SYSMENU|WS_BORDER|WS_CAPTION;
	Adjust(rect, screenwidth, screenheight, style, 0);

	hwnd = CreateWindowA("TestClass", TITLE, style,
		rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
		NULL, NULL, wc.hInstance, NULL);

	if( !hwnd )
	{
		MYERROR("Could not create window");
		goto _end;
	}

	if( FAILED(InitDirect3D(hwnd)) )
	{
		MYERROR("Failed to initialize Direct3D");
		goto _end;
	}
	
	if( FAILED(InitScene()) )
	{
		MYERROR("Failed to initialize scene");
		goto _end;
	}

	ShowWindow(hwnd, SW_SHOWDEFAULT);
	UpdateWindow(hwnd);

	MSG msg;
	ZeroMemory(&msg, sizeof(msg));

	POINT p;
	GetCursorPos(&p);
	ScreenToClient(hwnd, &p);

	// timer
	QueryPerformanceFrequency(&qwTicksPerSec);
	tickspersec = qwTicksPerSec.QuadPart;

	QueryPerformanceCounter(&qwTime);
	last = (qwTime.QuadPart % tickspersec) / (double)tickspersec;

	while( msg.message != WM_QUIT )
	{
		QueryPerformanceCounter(&qwTime);

		current = (qwTime.QuadPart % tickspersec) / (double)tickspersec;

		if (current < last)
			delta = ((1.0 + current) - last);
		else
			delta = (current - last);

		last = current;
		accum += delta;

		mousedx = mousedy = 0;

		while( accum > 0.0333f )
		{
			accum -= 0.0333f;

			while( PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) )
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}

			Update(0.0333f);
		}

		if( msg.message != WM_QUIT )
			Render((float)accum / 0.0333f, (float)delta);
	}

_end:
	UninitScene();

	if( device )
	{
		ULONG rc = device->Release();

		if( rc > 0 )
			MYERROR("You forgot to release something");
	}

	if( direct3d )
		direct3d->Release();

	UnregisterClass("TestClass", wc.hInstance);
	_CrtDumpMemoryLeaks();

#ifdef _DEBUG
	system("pause");
#endif

	return 0;
}
示例#20
0
文件: UI.cpp 项目: FuzzySmurf/GSPCAGE
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
					   _In_opt_ HINSTANCE hPrevInstance,
					   _In_ LPTSTR    lpCmdLine,
					   _In_ int       nCmdShow)
{
	UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpCmdLine);

	MSG msg;
	// call our function to init and create our window
	if (!InitWindow(hInstance, nCmdShow))
	{
		MessageBox(NULL, TEXT("Unable to create window"), TEXT("ERROR"), MB_OK);
		return FALSE;
	}

	if (!InitDirect3D(hWnd))
	{
		MessageBox(NULL, TEXT("Unable to init Direct3D"), TEXT("ERROR"), MB_OK);
		return FALSE;
	}

	InventorySetup(); // INVENTORY_EXAMPLE - build the inventory
	//HUD SAMPLE
		//main declarations
	SpriteStrip barSprites(L"bar.png", 4);
	SpriteStrip CreditSprites(L"credits.png", 8);

	//healthbar
	float playerHealth = 100.0;
	float maxPlayerHealth = playerHealth;
	int healthBarImageID = 0;
	StatusBar playerHealthBar(L"Health", 5, 5, healthBarImageID, playerHealth, maxPlayerHealth, barSprites );
	/*
	//when health is modified
	if(playerHealth >= 50.0){
		healthBarImageID = 0;
	}else{
		if(playerHealth >= 25.0){
			healthBarImageID = 1;
		}else{
			healthBarImageID = 2;
		}
	}
	playerHealthBar.changeImage(healthBarImageID);
	playerHealthBar.modifyValue(playerHealth, barSprites);
	*/
	//stamina bar
	float playerStamina = 100.0;
	float maxPlayerStamina = playerStamina;
	StatusBar playerStaminaBar(L"Stamina", 5, 26, 4, playerStamina, maxPlayerStamina, barSprites );

	/*
	//when stamina is modified
	playerStaminaBar.modifyValue(playerStamina, barSprites);
	*/

	//credits
	
	bool showCredits = true;
	int li = 0;
	int crSlide = 0;
	StatusIcon credits(L"credits", SCREEN_WIDTH/4, SCREEN_HEIGHT/4, crSlide, CreditSprites);
	//END HUD SAMPLE

	// Main message loop:
	// Enter the message loop
	memset(&msg, 0, sizeof(MSG));
	while( msg.message!=WM_QUIT )
	{
		// check for messages
		if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
		{
			TranslateMessage( &msg );
			DispatchMessage( &msg );
		}
		// this is called when no messages are pending
		else
		{
			// clear background to a white offset
			g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(240, 240, 240), 1.0f, 0);

			if(SUCCEEDED(g_pD3DDevice->BeginScene()))
			{

				inventory.drawElement(); // INVENTORY_EXAMPLE
				//HUD SAMPLE
				playerHealthBar.drawElement(barSprites);
				playerStaminaBar.drawElement(barSprites);
				if(showCredits == true){
					credits.drawElement(CreditSprites);
					li++;
					if (li > 150){
						crSlide++;
						credits.changeImage(crSlide, CreditSprites);

						li = 0;
					}
					if(crSlide > 7){
						li = 0;
						crSlide = 0;
						showCredits = false;
					}else{
						showCredits = true;
					}
				}
				//END HUD SAMPLE

				g_pD3DDevice->EndScene();
			}

			// Present the backbuffer contents to the display
			g_pD3DDevice->Present( NULL, NULL, NULL, NULL );
		}
	}

	// release and shutdown Direct3D
	ShutdownDirect3D();

	return (int) msg.wParam;
}