1 / 31

Lesson 1:  Getting Started with Direct3D

Lesson 1:  Getting Started with Direct3D. COM. COM 은 Component 이다 . 사용은 레고를 하듯이 불러와서 끼워 맞추면 된다 . COM 시리즈중 하나인 direct3D 는 진보한 클래스로 2D , 3D graphics 나 사용하는 software, hardware 또는 그어떤것에라도 사용이 가능하다 . d3d->CreateDevice() d3d->Release(). The Swap Chain and Page Swapping.

zihna
Télécharger la présentation

Lesson 1:  Getting Started with Direct3D

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. Lesson 1:  Getting Started with Direct3D

  2. COM • COM 은 Component이다. 사용은 레고를 하듯이 불러와서 끼워 맞추면 된다. • COM 시리즈중하나인 direct3D는진보한 클래스로 2D , 3D graphics나사용하는 software, hardware 또는 그어떤것에라도 사용이 가능하다. • d3d->CreateDevice()d3d->Release()

  3. The Swap Chain and Page Swapping • 모니터는 실시간 랜더링된 결과물을 보여주기위해서 초당 60~100Hz만큼 깜밖인다. • 다른 모델로 전체를 새로 그리는것이아니라 절반만 새로 그리는것을 생각해보면 ,top~half 까지 새로 그리고 half~bottom까지그리는 방식인데 이런방식을쓰게 되면 화면이 심하게 찢어지는것처럼 (called tearing) 보일것이다.

  4. The Swap Chain and Page Swapping • Swapping- Drect3D는모니터에 바로 출력하는것이 아니라 buffer 을두고 buffer에 먼저 화면을 그린후 그것을 한번에 화면으로 출력하는 형식을 쓰고 있다.

  5. The Swap Chain and Page Swapping • 더 나은 성능을 위해 3장의 버퍼를 사용하는 모습

  6. The Basic Direct3D Program • Direct3D에서 첫화면을 출력하기 위해서 다음 단계를 거친다. • 1.  Create global variables and function prototypes2.  Create a function to initialize Direct3D and create the Direct3D Device3.  Create a function to render a frame4.  Create a function to close Direct3D

  7. 1.  Create global variables and function prototypes // include the basic windows header files and the Direct3D header file#include <windows.h>#include <windowsx.h>#include <d3d9.h>// include the Direct3D Library file#pragma comment (lib, "d3d9.lib")// global declarationsLPDIRECT3D9 d3d;    // the pointer to our Direct3D interfaceLPDIRECT3DDEVICE9 d3ddev;    // the pointer to the device class// function prototypesvoid initD3D(HWND hWnd);    // sets up and initializes Direct3Dvoid render_frame(void);    // renders a single framevoid cleanD3D(void);    // closes Direct3D and releases memory// the WindowProc function prototypeLRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

  8. 2.  Create a function to initialize Direct3D and create the Direct3D Device // this function initializes and prepares Direct3D for usevoid initD3D(HWND hWnd){    d3d = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface    D3DPRESENT_PARAMETERS d3dpp;    // create a struct to hold various device information    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use    d3dpp.Windowed = TRUE;    // program windowed, not fullscreen    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames    d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D    // create a device class using this information and information from the d3dpp stuct    d3d->CreateDevice(D3DADAPTER_DEFAULT,                      D3DDEVTYPE_HAL,                      hWnd,                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,                      &d3dpp,                      &d3ddev);    return;}

  9. 2.  Create a function to initialize Direct3D and create the Direct3D Device // this function initializes and prepares Direct3D for usevoid initD3D(HWND hWnd){    d3d = Direct3DCreate9(D3D_SDK_VERSION);    // create the Direct3D interface    D3DPRESENT_PARAMETERS d3dpp;    // create a struct to hold various device information    ZeroMemory(&d3dpp, sizeof(d3dpp));    // clear out the struct for use    d3dpp.Windowed = TRUE;    // program windowed, not fullscreen    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;    // discard old frames    d3dpp.hDeviceWindow = hWnd;    // set the window to be used by Direct3D    // create a device class using this information and information from the d3dpp stuct    d3d->CreateDevice(D3DADAPTER_DEFAULT,                      D3DDEVTYPE_HAL,                      hWnd,                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,                      &d3dpp,                      &d3ddev);    return;} HRESULT CreateDevice(    UINT Adapter,    D3DDEVTYPE DeviceType,    HWND hFocusWindow,    DWORD BehaviorFlags,    D3DPRESENT_PARAMETERS *pPresentationParameters,    IDirect3DDevice9 **ppReturnedDeviceInterface);

  10. 3.  Create a function to render a frame // this is the function used to render a single framevoid render_frame(void){    // clear the window to a deep blue    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);    d3ddev->BeginScene();    // begins the 3D scene    // do 3D rendering on the back buffer here    d3ddev->EndScene();    // ends the 3D scene    d3ddev->Present(NULL, NULL, NULL, NULL);    // displays the created frame    return;}

  11. 4.  Create a function to close Direct3D // this is the function that cleans up Direct3D and COMvoid cleanD3D(void){    d3ddev->Release();    // close and release the 3D device    d3d->Release();    // close and release Direct3D    return;}

  12. The Finished Program

  13. Summary • 이제 여행을 출발 하였습니다. • 앞으로 여러분은 Direct3D로 화면에 이미지를 넣어 볼 것입니다. • 창의 색을 파랑에서 검은색으로 변화시키는것을 연습해보십시오.

  14. Lesson 2: Going Fullscrean

  15. Lesson Overview • Setting Up the Screen Size • Changing to Fullscreen Mode • The Escape Route • The Finished Program

  16. Lesson Overview • Making fullscreen is easy • we will cover two things. • how to globalize your screen resolution • mechanics of making a window go into fullscreen mode.

  17. Setting Up the Screen Size • add two directives to the top of our program. screen width and the screen height. // define the screen resolution#define SCREEN_WIDTH 640#define SCREEN_HEIGHT 480

  18. Setting Up the Screen Size • go through your program to where you indicate the width and height of your window. 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);

  19. Setting Up the Screen Size • 640 x 480 is rapidly becoming obsolete. • Windows Vista supports a minimum of 800 x 600

  20. Setting Up the Screen Size

  21. Setting Up the Screen Size

  22. Changing to Fullscreen Mode • two of these are handled by changing some CreateWindowEx() parameters. hWnd = CreateWindowEx(NULL, L"WindowClass", L"Our Direct3D Program",WS_EX_TOPMOST | WS_POPUP, // fullscreen values0, 0, // the starting x and y positions should be 0 SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL);

  23. Changing to Fullscreen Mode • set the starting x and y positions to 0. • WS_EX_TOPMOST is self-explanatory.makes the window overlap everything else. • WS_POPUPis less self-explanatory.

  24. Changing to Fullscreen Mode • have to tell DirectX about our new screen resolution. 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

  25. Changing to Fullscreen Mode • d3dpp.BackBufferFormat = Direct3D what kind of pixels should be displayed.

  26. The Escape Route • The first of these goes up front with the other #define directives. • Let's ignore the fine details of this line for now. #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1)

  27. The Escape Route • added to our program right after the frame is rendered. • detect when the 'escape' key has been pressed and tells the program to exit. • PostMessage() function does posts a message on the message queue. // check the 'escape' keyif(KEY_DOWN(VK_ESCAPE)) PostMessage(hWnd, WM_DESTROY, 0, 0);

  28. The Escape Route(Key)

  29. The Finished Program // define the screen resolution and keyboard macros #define SCREEN_WIDTH 640 #define SCREEN_HEIGHT 480 #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0) #define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1) // wc.hbrBackground = (HBRUSH)COLOR_WINDOW; // not needed any more

  30. The Finished Program 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, // set the window to 640 x 480 NULL, NULL, hInstance, NULL); 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

More Related