Top Banner
DirectDraw Technology CML Training Course 2001/07/24 Alex Ma
33

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

Mar 31, 2015

Download

Documents

Alex Pullman
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: DirectDraw Technology CML Training Course 2001/07/24 Alex Ma.

DirectDraw Technology

CML Training Course2001/07/24

Alex Ma

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

Outline

• DirectDraw Introduction• DirectDraw Functionality

– Setup– Surface– Rendering– Blitting– Flipping– Overlay

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

DirectDraw Introduction

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

What’s DirectDraw For

• Basic of the DirectX graphics• Provide several simple methods to

manipulate the display system

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

Before DirectDraw

• Windows Graphics Device Interface (GDI)– Font, pen, brush, basic shapes– Bitmap and more raster functions– Device independent

• Display Driver Interface (DDI)

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

Before DirectDraw

Application

Graphics Device Interface(GDI)

Display Driver Interface(DDI)

Display System

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

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

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

With DirectDraw

Application

Graphics Device Interface(GDI)

Display Driver Interface(DDI)

Display System

HardwareEmulation

Layer(HEL)

HardwareAbstractLayer(HAL)

DirectDrawObject

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

With DirectDraw

• Direct access to the display hardware device with HAL/HEL supports

• DirectDraw is not much device-independent as GDI does

• HEL can’t emulate everything

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

DirectDraw Functionality

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

Setup

• Enumerate DirectDraw devices

BOOL WINAPI EnumDDrawDevice(GUID FAR *lpGUID, LPSTR lpDriverDescription,LPSTR lpDriverName, LPVOID lpContext)

DirectDrawEnumerate(EnumDDrawDevice,(LPVOID)GetDlgItem(hWnd, IDC_DEVICE)) ;

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

Setup

• Create DirectDraw object

LPDIRECTDRAW pDDraw ;

DirectDrawCreate(&pDDraw) ;

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

Setup• Set cooperative level

pDDraw->SetCooperativeLevel(hWnd, DDSCL_FULLSCREEN |DDSCL_EXCLUSIVE |DDSCL_NOWINDOWCHANGES) ;

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

Setup

• Enumerate video display mode

BOOL WINAPI EnumDisplayModes(LPDDSURFACEDESC lpDDSurfaceDesc, LPVOID lpContext)

pDDraw3->EnumDisplayModes(0, NULL, (LPVOID)GetDlgItem(hWnd, IDC_MODES), (LPDDENUMMODESCALLBACK)EnumDisplayModes) ;

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

Setup• Set video display mode

pDDraw->SetDisplayMode(Width, Height,PixelFormat) ;

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

Surface

• A memory buffer managed as a rectangle

• Surface type– Primary (display)– Off-screen– Overlay– Z-buffer and more

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

Surface• DirectDraw surface descriptor

typedef DDSURFACEDESC{

LPVIOD lpSurfaceDWORD dwHeightDWORD dwWidthLONG lPitchDDPIXELFORMAT ddpfPixelFormat…

} ;

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

Surface

• Create surface

LPDIRECTDRAWSURFACE pDDrawSurface ;DDSURFACEDESC ddsd ;

pDDraw3->CreateSurface(&ddsd, pDDrawSurface) ;

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

Surface• Primary surface always exists, so do n

ot 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

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

Rendering

• Direct memory access

// Fill the screen with white colorWORD *vmem = (WORD *)ddsd.lpSurfacefor(DWORD y=0; y<ddsd.dwHeight; y++){

for(DWORD x=0; x<ddsd.dwWidth; x++)vmem[x] = 0xffff ;

vmem += ddsd.lPitch/sizeof(WORD) ;}

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

Rendering

• Using GDI

pDDrawSurface->GetDC(&hDC) ;

// GDI functionality testsTextOut(hDC, 320, 0, msg, strlen(msg)) ;Ellipse(hDC, 300, 125, 400, 250) ;

pDDrawSurface->ReleaseDC(hDC) ;

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

Rendering

• Access control

pDDrawSurface->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL) ;

// Rendering

pDDrawSurface->UnLock(NULL) ;

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

Blitting

• Bit block transfer (Blit)Surface #1

Surface #2

Surface #3

PrimarySurface

Blitter

Biltter Queue

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

Blitting

• Using blitting

pDDrawSurface->Blt(&destRect, pDDrawSource, &srcRect, DDBLT_WAIT, NULL) ;

pDDrawSurface->BltFast(200, 240, pDDrawSource, NULL, DDBLTFAST_WAIT) ;

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

Blitting• BltFast is a little bit fast than Blt when

using HEL. If have hardware support, then there is no difference between them

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

Blitting

• Special effects– Filling– Transparency– Scaling– Mirroring– Rotation

• Use DDBLTFX structure to control

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

Blitting

• Example - mirroring

DDBLTFX ddbltfx ;memset(&ddbltfx, 0, sizeof(DDBLTFX)) ;ddbltfx.dwSize = sizeof(DDBLTFX) ;ddbltfx.dwDDFX = DDBLTFX_MIRRORLEFTRIGHT | DD

BLTFX_MIRRORUPDOWN ;pDDrawSurface->Blt(NULL, pDDrawSource, NULL, DD

BLT_DDFX, &ddbltfx) ;

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

Flipping

• Tearing problem

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

Flipping

• Using flipping

pPrimarySurface->GetAttachedSurface(&pBackSurface) ;

// Rendering on the back surfacepBackSurface->Blt(&destRect, pDDrawSource, &srcRec

t, DDBLT_WAIT, NULL) ;

pPrimarySurface->Flip(DDFLIP_WAIT) ;

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

Overlay

• Display a surface without changing the image data in the primary surface

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

Overlay

• Using overlay

pDDraw3->CreateSurface(&ddsd, &pOverlaySurface) ;

// Rendering

pOverlaySurface->UpdateOverlay(&srcRect, pPrimarySurface, &destRect, DDOVER_SHOW) ;

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

Overlay

• Show/Hide overlay

pOverlaySurface->UpdateOverlay(&srcRect, pPrimarySurface, &destRect, DDOVER_SHOW) ;

pOverlaySurface->UpdateOverlay(NULL, pPrimarySurface, NULL, DDOVER_HIDE) ;

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

Discuss and Q&A Time