DirectX9 Installation

1. DirectX9 SDK (Feb 2010)을 다운 받아 설치해 주어야합니다.

http://www.microsoft.com/downloads/details.aspx?FamilyID=2c7da5fb-ffbb-4af6-8c66-651cbd28ca15&displaylang=en


Quick Details
File Name:DXSDK_Feb10.exe
Version:9.28.1886
Date Published:2/5/2010
Language:English
Download Size:554.6 MB


2. Visual Studio .NET 2008이 설치된 디렉토리의 Include와 Lib 경로 연결하기


도구 -> 옵션 -> 프로젝트 및 솔루션 -> VC++ 디렉토리
실행파일 디렉토리에 C:\Program Files\Microsoft DirectX SDK (February 2010)\Utilities\bin\x86 추가됨
포함파일 디렉토리에 C:\Program Files\Microsoft DirectX SDK (February 2010)\Include 추가됨
라이브러리파일 디렉토리에 C:\Program Files\Microsoft DirectX SDK (February 2010)\Lib\x86 추가됨


3. 셋팅이 모두 끝나면, 프로젝트를 Win32 Project로 생성 (File->New->Project, 템플렛에서 Win32->Win32 Project를 선택하고 <your project name>을 넣는다)하고, 아래의 소스를 넣어 컴파일 실행해 봅니다.



/****************************************************************
* shows the user how to setup a windowed direct3d application
* which clears the window to a blue color
****************************************************************/
// include directx9
#include <windows.h>
#include <d3d9.h>
// global variables
HINSTANCE hInst;       // application instance
HWND wndHandle;        // application window handle


LPDIRECT3D9             pD3D;    // the Direct3D Object
LPDIRECT3DDEVICE9       pd3dDevice;   // the Direct3D Device


////////////////////////////////////////////// forward declarations
bool initWindow(HINSTANCE hInstance);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);


// DirectX functions
bool initDirect3D();
void render(void);


/*********************************************************************
* WinMain
*********************************************************************/
int WINAPI WinMain(HINSTANCE hInstance,
       HINSTANCE hPrevInstance,
       LPTSTR lpCmdLine, int nCmdShow)
{
 if (!initWindow(hInstance))
 {
  MessageBox(NULL, “Unable to create window”, “ERROR”, MB_OK);
  return false;
 }


 if (!initDirect3D())
 {
  MessageBox(NULL, “Unable to init Direct3D”, “ERROR”, MB_OK);
  return false;
 }


 // Main message loop:
    MSG msg;
    ZeroMemory( &msg, sizeof(msg) );
    while( msg.message!=WM_QUIT )
    {
  if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
        {
   TranslateMessage( &msg );
            DispatchMessage( &msg );
        }  
  else
  {
   render();
  }
    }


 // release the device and the direct3D object
 if( pd3dDevice != NULL)
        pd3dDevice->Release();


    if( pD3D != NULL)
        pD3D->Release();
 
 return (int) msg.wParam;
}


/*********************************************************************
* initWindow
*********************************************************************/
bool initWindow(HINSTANCE hInstance)
{
 WNDCLASSEX wcex;


 wcex.cbSize = sizeof(WNDCLASSEX);
 wcex.style   = CS_HREDRAW | CS_VREDRAW;
 wcex.lpfnWndProc = (WNDPROC)WndProc;
 wcex.cbClsExtra  = 0;
 wcex.cbWndExtra  = 0;
 wcex.hInstance  = hInstance;
 wcex.hIcon   = 0;
 wcex.hCursor  = LoadCursor(NULL, IDC_ARROW);
 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
 wcex.lpszMenuName = NULL;
 wcex.lpszClassName = “DirectXExample”;
 wcex.hIconSm  = 0;
 RegisterClassEx(&wcex);


 // create the window
 wndHandle = CreateWindow(“DirectXExample”,
        “DirectXExample”,
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        640,
        480,
        NULL,
        NULL,
        hInstance,
        NULL);
   if (!wndHandle)
      return false;
  
   ShowWindow(wndHandle, SW_SHOW);
   UpdateWindow(wndHandle);


   return true;
}


/*********************************************************************
* WndProc
*********************************************************************/
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
 switch (message)
 {
  case WM_DESTROY:
   PostQuitMessage(0);
   break;
 }
 return DefWindowProc(hWnd, message, wParam, lParam);
}


/*********************************************************************
* initDirect3D
* initializes direct3D
*********************************************************************/
bool initDirect3D()
{
 pD3D = NULL;
 pd3dDevice = NULL;


 // create the directX object
 if( NULL == ( pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
 {
  return false;
 }


 // fill the presentation parameters structure
 D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory( &d3dpp, sizeof(d3dpp) );
    d3dpp.Windowed = TRUE;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
 d3dpp.BackBufferCount  = 1;
 d3dpp.BackBufferHeight = 480;
 d3dpp.BackBufferWidth  = 640;
 d3dpp.hDeviceWindow    = wndHandle;


 // create a default directx device
    if( FAILED( pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_REF, wndHandle,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      &d3dpp, &pd3dDevice ) ) )
    {
        return false;
    }
 return true;
}


/*********************************************************************
* render
*********************************************************************/
void render(void)
{
 // check to make sure we have a valid Direct3D Device
 if( NULL == pd3dDevice )
        return;


    // Clear the backbuffer to a blue color
    pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );


 // Present the backbuffer contents to the display
    pd3dDevice->Present( NULL, NULL, NULL, NULL );
}


4. 이때, d3d9.lib d3dx9.lib winmm.lib 라이브러리 링크를 걸어줍니다.


Visual Studio .NET 2008의 경우 Project->Properties(ALT+F7)->Configuration Properties탭->Linker탭->Input탭에 Additional Dependencies에 “d3d9.lib d3dx9.lib winmm.lib”를 넣는다.


5. 컴파일/링크 (Build)(F7)후 실행(Debug)(F5)시켜서 파란색화면의 윈도우가 뜨면 완성된 것입니다.

Leave a Reply

Your email address will not be published. Required fields are marked *