コード例 #1
0
ファイル: dxtest.cpp プロジェクト: AceRoqs/DirectXTutorials
// 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
コード例 #2
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;
}