블로그 이미지
대갈장군

calendar

1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

Notice

2008. 2. 2. 01:02 프로그래밍/DirectX
이 내용은 www.directxtutorial.com 사이트의 내용을 번역한 하여 참조하였습니다.

풀 스크린으로 만드는 것은 몇가지 사항을 추가해야 하고 코드도 바꿔야 한다. 여기서 살펴볼 두가지 사항은 어떻게 나의 스크린 해상도를 globalize 하는가 어떤 메커니즘으로 최대화면을 만드는지 이다.

1. Setting Up the Screen Size
프로그램 실행중에 빈번하게 나의 화면 크기를 조사하고 바꾸어야 할 때가 많은데 이럴때 어떻게 하는지 살펴보자.

우선 두개의 기본값을 설정하자.
// define the screen resolution
#define SCREEN_WIDTH  640
#define SCREEN_HEIGHT 480

그리고 나서 아마도 WinMain안에 있는 아래 함수를 다음과 같이 바꾸자 (blod)
    hWnd = CreateWindowEx(NULL,
                          L"WindowClass",
                          L"Our Direct3D Program",
                          WS_OVERLAPPEDWINDOW,
                          300, 300,
                          SCREEN_WIDTH, SCREEN_HEIGHT,    // set window to new resolution
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

이렇게 하면 정의된 사이즈로 윈도우가 만들어 질 것이다. (아직 FULL screen 아닐거임)

2. Changing to Fullscreen Mode
    hWnd = CreateWindowEx(NULL,
                          L"WindowClass",
                          L"Our Direct3D Program",
                          WS_EX_TOPMOST | WS_POPUP,    // fullscreen values
                          0, 0,    // the starting x and y positions should be 0
                          SCREEN_WIDTH, SCREEN_HEIGHT,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

우선 Full screen 모드로 들어가기 위해서 해줘야 할 것이 4가지 있는데,
1. 윈도우 시스템에게 어떤 윈도우 외곽선도 보이지 말게 하라는 명령을 줘야 하고
2. 스크린 위에 있는 모든 다른 것을 overlap 하라는 (덮어 씌워 버리라는) 명령을 줘야 하고
3. DirectX에게 모니터 해상도를 내가 원하는 대로 바꾼다고 알려줘야 하고
4. 윈도우 배경 색은 남겨두라는 명령이랜다. (이건 뭐 별로 중요하지 않대요)

1번과 2번은 위의 CreateWindowEx 함수의 굵은 글씨제 부분에서 해결한다.

그리고 WINDOWCLASSEX 구조체에서 바꿔야 할 부분은,
// wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
게임 시작할때 윈도우를 안보이게 한다음 한꺼번에 나타내는 기술인가봐...

그라고 나서 인제 해야 할 부분이 DirectX에게 알려주는 것인데, 이것은 d3dpp 구조체를 바꿈으로써 가능하다. 굵은 부분이 추가 혹은 바뀐 부분이다.
D3DPRESENT_PARAMETERS d3dpp;    // create a struct to hold various device information

    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use
    d3dpp.Windowed = FALSE;    // program fullscreen, not windowed
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames
    d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D
    d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;    // set the back buffer format to 32-bit
    d3dpp.BackBufferWidth = SCREEN_WIDTH;    // set the width of the buffer
    d3dpp.BackBufferHeight = SCREEN_HEIGHT;    // set the height of the buffer

일단 windowed 인자가 false로 바뀌었다. 저것으로써 fullscreen mode를 선언함.

BackBufferFormat이 나와 있는데 여기서 사용할수 있는 몇가지 타입이 있는데 요즘은 거의 32 비트를 사용하나 보다.

Value Description
D3DFMT_A8R8G8B8 This is a 32-Bit pixel format, with 256 levels (8 bits) of red, green, blue and alpha (semi-transparency).
D3DFMT_X8R8G8B8 This is similar to A8R8G8B8, with the one difference being that it does not support alpha, even though there are 8 bits to represent this.
D3DFMT_A2R10G10B10 This is a 32-Bit pixel format, with only two bits of alpha, but 10 bits (1024 levels) of each red, green and blue.
D3DFMT_A16B16G16R16 64-BIT COLOR!  If you have the capability to run 64-bit color, I'd recommend playing around with this to see how it works.  Of course, Windows Vista will fully support 64-bit color, and so this is just a prelude for now.

This value has 16 bits for each component (65536 levels compared to the current measly 256!)

BackBufferWidth와 BackBufferHeight는 단순히 봐도 뭔지 알겠다....

3. The Escape Route
이제는 탈출을 하는 코드를 만들때인데 원래라면 DirectInput을 사용하는가 본데 여기서는 약간의 편법을 이용해서 하는 것같다.

#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

우선 이 두 줄을 코드 제일 위에 붙여 주고 (현재 키가 눌러졌는지 안눌러 졌는지 조사하는 매크로) 그 다음에

// check the 'escape' key
if(KEY_DOWN(VK_ESCAPE))
    PostMessage(hWnd, WM_DESTROY, 0, 0);
를 이용해서 ESC 키가 눌러졌는지를 확인하는 코드를 적절한 곳에 삽입해 주면 윈도를 뿌수고 나올수 있따.

참고로 키 테이블을 올려 놨다.
Description Hexadecimal Value Identifier
Left Mouse Button 01 VK_LBUTTON
Right Mouse Button 02 VK_RBUTTON
Backspace Key 08 VK_BACK
Tab Key 09 VK_TAB
Enter Key 0D VK_RETURN
Shift Key 10 VK_SHIFT
Control Key 11 VK_CONTROL
Alt Key 12 VK_MENU
Pause Key 13 VK_PAUSE
Escape Key 1B VK_ESCAPE
Spacebar 20 VK_SPACE
Page Up Key 21 VK_PRIOR
Page Down Key 22 VK_NEXT
End Key 23 VK_END
Home Key 24 VK_HOME
Left Arrow Key 25 VK_LEFT
Up Arrow Key 26 VK_UP
Right Arrow Key 27 VK_RIGHT
Down Arrow Key 28 VK_DOWN
Insert Key 2D VK_INSERT
Delete Key 2E VK_DELETE
0 - 9 Keys 30-39 No Identifier
A - Z Keys 41-5A No Identifier
F1 - F12 Keys 70-7B VK_F1 ... VK_F12



posted by 대갈장군