Presentation is loading. Please wait.

Presentation is loading. Please wait.

DirectDraw Technology CML Training Course 2001/07/24 Alex Ma.

Similar presentations


Presentation on theme: "DirectDraw Technology CML Training Course 2001/07/24 Alex Ma."— Presentation transcript:

1 DirectDraw Technology CML Training Course 2001/07/24 Alex Ma

2 Outline DirectDraw Introduction DirectDraw Functionality –Setup –Surface –Rendering –Blitting –Flipping –Overlay

3 DirectDraw Introduction

4 Whats DirectDraw For Basic of the DirectX graphics Provide several simple methods to manipulate the display system

5 Before DirectDraw Windows Graphics Device Interface (GDI) –Font, pen, brush, basic shapes –Bitmap and more raster functions –Device independent Display Driver Interface (DDI)

6 Before DirectDraw

7 With DirectDraw Hardware Abstraction Layer (HAL) –Corresponds to the display system –Exercises hardware supports Hardware Emulation Layer (HEL) –Software emulation or hardware independent methods for specific functionalities

8 With DirectDraw

9 Direct access to the display hardware device with HAL/HEL supports DirectDraw is not much device- independent as GDI does HEL cant emulate everything

10 DirectDraw Functionality

11 Setup Enumerate DirectDraw devices BOOL WINAPI EnumDDrawDevice(GUID FAR *lpGUID, LPSTR lpDriverDescription,LPSTR lpDriverName, LPVOID lpContext) DirectDrawEnumerate(EnumDDrawDevice, (LPVOID)GetDlgItem(hWnd, IDC_DEVICE)) ;

12 Setup Create DirectDraw object LPDIRECTDRAWpDDraw ; DirectDrawCreate(&pDDraw) ;

13 Setup Set cooperative level pDDraw->SetCooperativeLevel(hWnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE | DDSCL_NOWINDOWCHANGES) ;

14 Setup Enumerate video display mode BOOL WINAPI EnumDisplayModes(LPDDSURFACEDESC lpDDSurfaceDesc, LPVOID lpContext) pDDraw3->EnumDisplayModes(0, NULL, (LPVOID)GetDlgItem(hWnd, IDC_MODES), (LPDDENUMMODESCALLBACK)EnumDisplayModes) ;

15 Setup Set video display mode pDDraw->SetDisplayMode(Width,Height,PixelFormat) ;

16 Surface A memory buffer managed as a rectangle Surface type –Primary (display) –Off-screen –Overlay –Z-buffer and more

17 Surface DirectDraw surface descriptor typedef DDSURFACEDESC { LPVIODlpSurface DWORDdwHeight DWORDdwWidth LONGlPitch DDPIXELFORMATddpfPixelFormat … } ;

18 Surface Create surface LPDIRECTDRAWSURFACEpDDrawSurface ; DDSURFACEDESCddsd ; pDDraw3->CreateSurface(&ddsd, pDDrawSurface) ;

19 Surface Primary surface always exists, so do not assign size or format when calling CreateSurface to get primary surface pointer Use a large surface instead of several small surfaces for better memory management

20 Rendering Direct memory access // Fill the screen with white color WORD *vmem = (WORD *)ddsd.lpSurface for(DWORD y=0; y

21 Rendering Using GDI pDDrawSurface->GetDC(&hDC) ; // GDI functionality tests TextOut(hDC, 320, 0, msg, strlen(msg)) ; Ellipse(hDC, 300, 125, 400, 250) ; pDDrawSurface->ReleaseDC(hDC) ;

22 Rendering Access control pDDrawSurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) ; // Rendering pDDrawSurface->UnLock(NULL) ;

23 Blitting Bit block transfer (Blit)

24 Blitting Using blitting pDDrawSurface->Blt(&destRect, pDDrawSource, &srcRect, DDBLT_WAIT, NULL) ; pDDrawSurface->BltFast(200, 240, pDDrawSource, NULL, DDBLTFAST_WAIT) ;

25 Blitting BltFast is a little bit fast than Blt when using HEL. If have hardware support, then there is no difference between them

26 Blitting Special effects –Filling –Transparency –Scaling –Mirroring –Rotation Use DDBLTFX structure to control

27 Blitting Example - mirroring DDBLTFXddbltfx ; memset(&ddbltfx, 0, sizeof(DDBLTFX)) ; ddbltfx.dwSize = sizeof(DDBLTFX) ; ddbltfx.dwDDFX = DDBLTFX_MIRRORLEFTRIGHT | DDBLTFX_MIRRORUPDOWN ; pDDrawSurface->Blt(NULL, pDDrawSource, NULL, DDBLT_DDFX, &ddbltfx) ;

28 Flipping Tearing problem

29 Flipping Using flipping pPrimarySurface->GetAttachedSurface(&pBackSurface) ; // Rendering on the back surface pBackSurface->Blt(&destRect, pDDrawSource, &srcRect, DDBLT_WAIT, NULL) ; pPrimarySurface->Flip(DDFLIP_WAIT) ;

30 Overlay Display a surface without changing the image data in the primary surface

31 Overlay Using overlay pDDraw3->CreateSurface(&ddsd, &pOverlaySurface) ; // Rendering pOverlaySurface->UpdateOverlay(&srcRect, pPrimarySurface, &destRect, DDOVER_SHOW) ;

32 Overlay Show/Hide overlay pOverlaySurface->UpdateOverlay(&srcRect, pPrimarySurface, &destRect, DDOVER_SHOW) ; pOverlaySurface->UpdateOverlay(NULL, pPrimarySurface, NULL, DDOVER_HIDE) ;

33 Discuss and Q&A Time


Download ppt "DirectDraw Technology CML Training Course 2001/07/24 Alex Ma."

Similar presentations


Ads by Google