Пример #1
0
void Engine::init()
{
	// Sets up the main logger.
	setupLogger();

	// Creates the task system.
	taskPool = TaskPoolCreate( AllocatorGetThis(), 2 );

	NetworkInitialize();
	ResourcesInitialize();
	InputInitialize();
	GraphicsInitialize();

	// Creates the resource manager.
	resourceManager = AllocateThis(ResourceManager);
	resourceManager->setTaskPool( taskPool );
	
	// Registers default resource loaders.
	resourceManager->setupResourceLoaders( ResourceLoaderGetType() );

	// Creates the rendering device.
	renderDevice = AllocateThis(RenderDevice);

#ifdef ENABLE_AUDIO_OPENAL
	// Creates the audio device.
	audioDevice = AudioCreateDevice("");

	if( audioDevice )
		audioDevice->createMainContext();
#endif

#ifdef ENABLE_SCRIPTING_LUA
	// Creates the scripting manager.
	scriptManager = AllocateThis(ScriptManager);
#endif
}
Пример #2
0
bool d3d::InitD3D(
	HINSTANCE hInstance,
	int width, int height,
	bool windowed,
	D3DDEVTYPE deviceType,
	IDirect3DDevice9** device)
{
	//
	// 윈도우창을 생성한다.
	//


	WNDCLASS wc;

	wc.style         = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = (WNDPROC)d3d::WndProc; 
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = hInstance;
	wc.hIcon         = LoadIcon(0, IDI_APPLICATION);
	wc.hCursor       = LoadCursor(0, IDC_ARROW);
	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wc.lpszMenuName  = 0;
	wc.lpszClassName = "Direct3D9App";

	if( !RegisterClass(&wc) ) 
	{
		::MessageBox(0, "RegisterClass() - FAILED", 0, 0);
		return false;
	}
		
	char temp[50];

	
	int frameX, frameY;
	//int captionY;
	//frameX = GetSystemMetrics(SM_CXFRAME);
	//frameY = GetSystemMetrics(SM_CYFRAME);
	//captionY = GetSystemMetrics(SM_CYCAPTION);
	GetWindowSizeFromClientSize(WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU,false,WindowWidth,WindowHeight,frameX,frameY);

	sprintf_s(temp,50,"touhou crawl %s",version_string);
	hwnd = ::CreateWindow("Direct3D9App", temp, 
		WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU,
			0, 0, frameX/*WindowWidth + 6*/, frameY/*WindowHeight + 32*/,
		0, 0 , hInstance, 0); 

	if( !hwnd )
	{
		::MessageBox(0, "CreateWindow() - FAILED", 0, 0);
		return false;
	}


	::ShowWindow(hwnd, SW_SHOW);
	InputInitialize(hInstance);
	::UpdateWindow(hwnd);

	//
	// 다이렉트3d 초기화
	//

	HRESULT hr = 0;

	// Step 1: Create the IDirect3D9 object.

	IDirect3D9* d3d9 = 0;
    d3d9 = Direct3DCreate9(D3D_SDK_VERSION);

    if( !d3d9 )
	{
		::MessageBox(0, "Direct3DCreate9() - FAILED", 0, 0);
		return false;
	}

	// Step 2: Check for hardware vp.

	D3DCAPS9 caps;
	d3d9->GetDeviceCaps(D3DADAPTER_DEFAULT, deviceType, &caps);

	int vp = 0;
	if( caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT )
		vp = D3DCREATE_HARDWARE_VERTEXPROCESSING;
	else
		vp = D3DCREATE_SOFTWARE_VERTEXPROCESSING;

	// Step 3: Fill out the D3DPRESENT_PARAMETERS structure.
 
	D3DPRESENT_PARAMETERS d3dpp;
	d3dpp.BackBufferWidth            = width;
	d3dpp.BackBufferHeight           = height;
	d3dpp.BackBufferFormat           = D3DFMT_A8R8G8B8;
	d3dpp.BackBufferCount            = 1;
	d3dpp.MultiSampleType            = D3DMULTISAMPLE_NONE;
	d3dpp.MultiSampleQuality         = 0;
	d3dpp.SwapEffect                 = D3DSWAPEFFECT_DISCARD; 
	d3dpp.hDeviceWindow              = hwnd;
	d3dpp.Windowed                   = windowed;
	d3dpp.EnableAutoDepthStencil     = true; 
	d3dpp.AutoDepthStencilFormat     = D3DFMT_D24S8;
	d3dpp.Flags                      = 0;
	d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
	d3dpp.PresentationInterval       = D3DPRESENT_INTERVAL_IMMEDIATE;

	// Step 4: 

	hr = d3d9->CreateDevice(
		D3DADAPTER_DEFAULT, // primary adapter
		deviceType,         // device type
		hwnd,               // window associated with device
		vp,                 // vertex processing
	    &d3dpp,             // present parameters
	    device);            // return created device

	if( FAILED(hr) )
	{
		// 실패시 16비트 깊이로 다시시도?!
		d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
		
		hr = d3d9->CreateDevice(
			D3DADAPTER_DEFAULT,
			deviceType,
			hwnd,
			vp,
			&d3dpp,
			device);

		if( FAILED(hr) )
		{
			d3d9->Release(); // d3d9를 풀어준다.
			::MessageBox(0, "CreateDevice() - FAILED", 0, 0);
			return false;
		}
	}

	(*device)->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);  //앞뒤 모두 그린다.
	//(*device)->SetRenderState(D3DRS_LIGHTING, FALSE);  //광원효과를 무시한다.(안주면 전부 거매)
    (*device)->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	(*device)->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
    (*device)->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);


	d3d9->Release(); // d3d9를 풀어준다.
	
	return true;
}