Beispiel #1
0
/**
 * Create the window and initialize the graphics device.
 */
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
	gInstanceHandle = hInstance; // Store instance handle in our global variable

	// Calculate the size of the window which will guarantee the client size we want
	unsigned int width, height;
	DetermineWindowSize(width, height);

	// Create the window
	gWindowHandle = CreateWindow(gWindowClass, gWindowTitle, WINDOW_STYLE, CW_USEDEFAULT, CW_USEDEFAULT, width, height,  nullptr, nullptr, hInstance, nullptr);
	if (!gWindowHandle)
	{
		return FALSE;
	}

	// Initialize Direct3D
	gDirect3D = Direct3DCreate9(D3D_SDK_VERSION);

	D3DPRESENT_PARAMETERS params;
	memset(&params, 0, sizeof(D3DPRESENT_PARAMETERS));
	params.Windowed = TRUE;
	params.SwapEffect = D3DSWAPEFFECT_DISCARD;
	params.hDeviceWindow = gWindowHandle;
	params.BackBufferCount = 2;

	gDirect3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, gWindowHandle, D3DCREATE_HARDWARE_VERTEXPROCESSING, &params, &gGraphicsDevice);

	// Display the window
	ShowWindow(gWindowHandle, nCmdShow);
	UpdateWindow(gWindowHandle);

	return TRUE;
}
Beispiel #2
0
/**
 * Initializes the rendering using the appropriate rendering method.
 */
bool InitializeRendering()
{
	DestroyWaveMesh();

	DeinitRendering();

	D3DPRESENT_PARAMETERS params;
	memset(&params, 0, sizeof(D3DPRESENT_PARAMETERS));
	params.Windowed = !gFullscreen;
	params.SwapEffect = D3DSWAPEFFECT_DISCARD;
	params.hDeviceWindow = gWindowHandle;
	params.BackBufferCount = 2;
	if (gFullscreen)
	{
		GetScreenSize(gWindowWidth, gWindowHeight);

		params.BackBufferFormat = D3DFMT_A8R8G8B8;
		params.BackBufferWidth = gWindowWidth;
		params.BackBufferHeight = gWindowHeight;
	}
	else
	{
		gWindowWidth = 1280;
		gWindowHeight = 1024;

		unsigned int width, height;
		DetermineWindowSize(width, height);

		SetWindowPos(gWindowHandle, HWND_TOP, 0, 0, width, height, SWP_NOMOVE);
	}

	HRESULT hr = gGraphicsDevice->Reset(&params);
	if (FAILED(hr))
	{
		ReportError("Failed to initialize device");
		return false;
	}

	InitRendering(gWindowWidth, gWindowHeight, gBroadcastWidth, gBroadcastHeight);
	
	// Set the viewport
	D3DVIEWPORT9 vp;
	vp.X = 0;
	vp.Y = 0;
	vp.MinZ = 0.0f;
	vp.MaxZ = 1.0f;
	vp.Width = gWindowWidth;
	vp.Height = gWindowHeight;
	gGraphicsDevice->SetViewport(&vp);

	// Setup the projection matrix
	D3DXMatrixPerspectiveFovLH(&gProjectionMatrix, D3DXToRadian(60), (FLOAT)gWindowWidth/(FLOAT)gWindowHeight, 1, 1000);

	// Create the mesh that will be rendered
	CreateWaveMesh(64, 20);

	InitializeChatRenderer(gWindowWidth, gWindowHeight);

	return true;
}
Beispiel #3
0
HWND CreateMainWindow() {
	RegisterMainWindowClass();

	SIZE windowSize;
    DetermineWindowSize(&windowSize);

	HWND result = ::CreateWindow(
		WINDOW_CLASS,
		"Arkanoid",
		WINDOW_STYLE,
		CW_USEDEFAULT, CW_USEDEFAULT, windowSize.cx, windowSize.cy,
		NULL, // root window
		NULL, // no menu
		g_hInstance,
		NULL  // no params
	);

	if (result == NULL)
		throw WINException("Screen::Init(): CreateWindow(): ");

	return result;
}