1 / 22

Chapter 8 DirectDraw 익히기

Chapter 8 DirectDraw 익히기. DirectDraw 의 소개. DirectDraw 는 .DLL 이나 .DLL 의 집합으로서 , 실행시간 (run-time) 라이브러리로 구현 DirectX 가 컴퓨터에 설치되어 있다면 , DirectX COM 객체의 물리적인 구현에 대해서 걱정할 필요는 없고 , 그저 인터페이스에 대해서 신경을 쓰면 된다. More: DXGUID.LIB. #define INITGUID 를 프로그램의 맨 위에 추가하거나 , DXGUID.LIB 라이브러리 파일을 포함해야 한다 .

denton
Download Presentation

Chapter 8 DirectDraw 익히기

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 8DirectDraw 익히기

  2. DirectDraw의 소개 • DirectDraw는 .DLL이나 .DLL의 집합으로서, 실행시간(run-time) 라이브러리로 구현 • DirectX가 컴퓨터에 설치되어 있다면, DirectX COM 객체의 물리적인 구현에 대해서 걱정할 필요는 없고, 그저 인터페이스에 대해서 신경을 쓰면 된다.

  3. More: DXGUID.LIB • #define INITGUID를 프로그램의 맨 위에 추가하거나, DXGUID.LIB 라이브러리 파일을 포함해야 한다. • 그렇지 않으면, 컴파일러는 인터페이스 GUID나 id를 해결하지 못한다.

  4. DirectDraw Interfaces

  5. Using Interfaces • DirectDraw 객체를 생성하고 주요 인터페이스 IDirectDraw7에 대한 접근을 얻는다. • 비디오 모드와 협력 수준을 정한다. 거기에서 하나 혹은 그 이상의 그리기 위한 DirectDraw 표면(IDirectDrawSurface7)을 생성한다. • 색상깊이에 따라, 팔레트를 생성하는 경우도 있다.(IDirectDrawPalette) • 필요하면 클리퍼를 생성한다.(IDirectDrawClipper)

  6. dwSize라는 속성 • DirectX 자료 구조에서 가장 중요한 규칙은 모두 dwSize라는 속성을 가진다는 것 • 이 속성은 자료 구조의 크기를 나타내고, DirectX가 사용하는 가변 자료구조의 실제 크기를 계산하는데 사용된다. • 이 속성을 반드시 직접 채우도록 한다. 윈도우즈가 그것을 대신해 줄 거라고 가정하지 않도록 한다. • 많은 문제들이 이 값을 채우지 않는 데서 기인한다.

  7. DirectDrawCreateEx HRESULT DirectDrawCreateEx(GUID FAR *lpGUID, LPVOID *lplpDD, refiid iid, IUnknown FAR *pUnkOuter); • lpGUID: 사용하고자 하는 비디오 드라이버의 종류를 선택하는 GUID(Globally Unique Identifier)이다. NULL은 기본 드라이버, 즉 현재 드라이버를 나타낸다. • lplpDD: 함수가 성공적으로 수행되면, 이곳에 COM 인터페이스의 주소를 저장한다. lplpDD는 LPVOID 형태이기에, 캐스팅되어야 한다. • iid: 요청하는 인터페이스의 인터페이스 id로, 이 경우는 IID_IDirectDraw7이다. • pUnkOuter: 심화 기능. 항상 NULL로 놓는다.

  8. 반환 자료형이 HRESULT • 함수가 수행되면, DD_OK를 반환한다. • 그렇지 않으면 다른 값을 반환한다. • 따라서 함수가 성공적으로 수행되었는지 알아보기 위해 항상 DD_OK값인지 검사한다. • 그밖에도 FAILED() 매크로를 사용하여 DirectX 함수가 실패했는지 검사할 수 있다. • 그저 FAILED() 매크로 안에 DirectX 함수 호출을 하면 된다. • Ex) if (FAILED(DirectDrawCreateEx(…))) { // error handling }

  9. Creating DirectDraw Object LPDIRECTDRAW7 lpdd; // pointer to interface object // create object and test for error if (DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)!=DD_OK) { /* error */ }

  10. Using DirectDrawObject • Calling Functions lpdd->function(parms...); • Especially, after using the object, lpdd->Release();

  11. DEMO: PROG8_1.CPP • Creating and Destroying DirectDraw Objects int Game_Init(void *parms) { // initialize game here // create object and test for error if (DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)!=DD_OK) return(0); // return success return(1); } // end Game_Init

  12. DEMO: PROG8_1.CPP (2) int Game_Shutdown(void *parms) { // shutdown and release are resources here // release the DirectDraw object if (lpdd!=NULL) lpdd->Release(); // return success return(1); } // end Game_Shutdown

  13. 협력(Cooperation) • Cooperation Level 을 정하는데 고려되는 것 • 응용 프로그램을 윈도우 모드로 생성하는지 혹은 전체 화면 모드로 생성하는지. • 모드 X 비디오 모드(320x200, 320x240)를 사용하고자 하는지. • 이용자가 Ctrl+Alt+Delete를 눌러서 게임을 나갈 수 있는지.

  14. SetCooperativeLevel() HRESULT SetCooperativeLevel(HWND hWnd, // handle to window DWORD dwFlags); // cooperation level flags

  15. 몇 가지 일반적인 규칙들 • 윈도우 모드 응용 프로그램 lpdd->SetCooperativeLevel(hwnd, DDSCL_NORMAL); • full-screen application lpdd->SetCooperativeLevel(hwnd,DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT);

  16. Example LPDIRECTDRAW7 lpdd; // a DirectDraw object pointer // create window and get handle in hwnd.. // create directdraw7 object if (DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)!=DD_OK) { /* error*/ } // set cooperation level to windowed mode normal lpdd->SetCooperativeLevel(hwnd,DDSCL_NORMAL);

  17. DEMO: PROG8_2.CPP

  18. 비디오 모드의 선택 • 함수는 SetDisplayMode() HRESULT SetDisplayMode( DWORD dwWidth, // width of mode in pixels DWORD dwHeight, // height of mode in pixels DWORD dwBPP, // bits per pixel DWORD dwRefreshRate, // refresh rate, set to 0 DWORD dwFlags); // flags, set to 0

  19. DirectX 온라인 • DirectDraw 객체를 생성하고 협력 수준을 설정하고, 비디오 모드를 640x480에 8비트 색상으로 요청하는 완전한 예제 LPDIRECTDRAW7 lpdd; // a DirectDraw object pointer // create window and get handle in hwnd.. // create directdraw object if (DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)!=DD_OK) { /* error*/ } // set cooperation level to windowed mode normal lpdd->SetCooperativeLevel(hwnd,DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT); // set the display mode if ((lpdd->SetDisplayMode(640,480,8,0,0))!=DD_OK) { /* error */ }

  20. 800x600에 16비트 하이컬러 모드 if ((lpdd->SetDisplayMode(800,600,16,0,0))!=DD_OK) { /* error */ }

  21. WS_POPUP Window • 비디오 모드를 부드럽게 변경하기 위해서, 메인 윈도우를 WS_OVERLAPPEDWINDOW가 아닌 WS_POPUP으로 생성하도록 한다. 그렇게 하면 경계나 컨트롤 없이 윈도우를 만들며, 전체 화면 모드처럼 보인다. GetSystemMetrics() 함수를 이용하여 화면의 현재 크기를 요청할 수 있다. 다음은 예제이다. // create a full-screen pop-up window if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class “WinX Game Console”, // title WS_POPUP | WS_VISIBLE, // flags 0,0, // x,y position GetSystemMetrics(SM_CXSCREEN), // max width GetSystemMetrics(SM_CYSCREEN), // max height NULL, // handle to parent NULL, // handle to menu hinstance,// instance NULL))) // creation parms return(0);

  22. DEMO: PROG8_3.CPP

More Related