04 13


Delphi Graphics and Game Programming Exposed! with DirectX For versions 5.0-7.0:An Introduction to DirectX                       Search Tips   Advanced Search        Title Author Publisher ISBN    Please Select ----------- Artificial Intel Business & Mgmt Components Content Mgmt Certification Databases Enterprise Mgmt Fun/Games Groupware Hardware IBM Redbooks Intranet Dev Middleware Multimedia Networks OS Productivity Apps Programming Langs Security Soft Engineering UI Web Services Webmaster Y2K ----------- New Arrivals









Delphi Graphics and Game Programming Exposed with DirectX 7.0

by John Ayres

Wordware Publishing, Inc.

ISBN: 1556226373   Pub Date: 12/01/99














Search this book:
 



Previous Table of Contents Next Lost Surfaces DirectX applications, even under exclusive, full-screen mode, must still coexist gracefully with other Windows applications. This means that users are free to Alt+Tab into and out of a DirectX application into other Windows applications. When a full-screen DirectX application is Alt+Tabbed out of, it is automatically minimized by DirectDraw, and the GDI resumes normal output in the original display mode. This has serious implications for surfaces located in display memory. When the GDI takes over in a situation like this, all display memory is reallocated to the GDI itself, thus wiping out anything stored in a surface located in display memory. When the DirectDraw application is returned to, any methods that manipulate display memory surfaces are likely to return a DDERR_ SURFACELOST error. When this error is detected, it is a simple matter to restore the surface’s memory. Simply call the Restore method of the IDirectDrawSurface4 object in question. The Restore method is defined as: function Restore: HResult; // returns a DirectX error code This will restore the memory allocated for that surface, and further methods that manipulate that surface will no longer fail until the surface’s memory is lost again. However, the contents of that surface may be undefined, and must be restored. Thus,your application should contain a function that initializes the contents of all surfaces that can be called again and again in the event that surface memory is lost. Note: This only applies to surfaces stored in video memory; system memory surfaces and their content will never be lost. You will need to restore the primary surface memory, which in turn implicitly restores the memory of all attached surfaces (such as the backbuffer). Retrieving DirectDraw Capabilities DirectX was written so that a developer can take advantage of certain hardware features if they are available, such as overlays or the ability to create off-screen surfaces wider than the primary surface. We can determine what features are available by calling the IDirectDraw4’s GetCaps method. The GetCaps method is defined as: function GetCaps( var lpDDDriverCaps: TDDCaps; // hardware capabilities var lpDDHELCaps: TDDCaps // emulated capabilities ): HResult; // returns a DirectX error code The first parameter returns a TDDCaps structure outlining the capabilities supported by the hardware itself, and the second parameter returns a similar structure detailing capabilities that are emulated. The hardware capabilities will vary depending on the available hardware, but the emulated capabilities will remain the same regardless of the hardware (but dependent on the version of DirectDraw installed). These structures are huge, and contain just about anything the developer or application would need to know about available features. The following example illustrates how the members of the individual structures are queried to determine the existence of a particular feature. Listing 4-6: Retrieving DirectDraw capabilities procedure TForm1.FormCreate(Sender: TObject); var {we can only get a DirectDraw4 interface from the DirectDraw interface, so we need a temporary interface} TempDirectDraw: IDirectDraw; {hardware and emulated capability structures} HALCaps, HELCaps: TDDCaps; begin {create a temporary DirectDraw object. this is used to create the desired DirectDraw4 object} DirectDrawCreate(nil, TempDirectDraw, nil); try {we can only get a DirectDraw2 interface through the QueryInterface method of the DirectDraw object} TempDirectDraw.QueryInterface(IID_IDirectDraw4, FDirectDraw); finally {now that we have the desired DirectDraw object, the temporary DirectDraw object is no longer needed} TempDirectDraw := nil; end; {initialize the capabilities structures} FillChar(HALCaps, SizeOf(TDDCaps), 0); FillChar(HELCaps, SizeOf(TDDCaps), 0); HALCaps.dwSize := SizeOf(TDDCaps); HELCaps.dwSize := SizeOf(TDDCaps); {retrieve the hardware and software capabilities} FDirectDraw.GetCaps(HALCaps, HELCaps); {display several pieces of information} SysInfo.Items.Add(‘Total Video Memory: ’+IntToStr(HALCaps.dwVidMemTotal div 1000)+‘ KB’); SysInfo.Items.Add(‘’); {hardware caps} SysInfo.Items.Add(‘Hardware Capabilities’); SysInfo.Items.Add(‘——————————————————-’); if (HALCaps.dwCaps and DDCAPS_BLT) = DDCAPS_BLT then SysInfo.Items.Add(‘Hardware accelerated blits’); if (HALCaps.dwCaps and DDCAPS_BLTCOLORFILL) = DDCAPS_BLTCOLORFILL then SysInfo.Items.Add(‘Hardware accelerated color fills’); if (HALCaps.dwCaps and DDCAPS_BLTQUEUE) = DDCAPS_BLTQUEUE then SysInfo.Items.Add(‘Asynchronous hardware blits’); if (HALCaps.dwCaps and DDCAPS_BLTSTRETCH) = DDCAPS_BLTSTRETCH then SysInfo.Items.Add(‘Hardware stretch blits’); if (HALCaps.dwCaps2 and DDCAPS2_CERTIFIED ) = DDCAPS2_CERTIFIED then SysInfo.Items.Add(‘Microsoft certified driver’); if (HALCaps.dwCaps2 and DDCAPS2_NONLOCALVIDMEM ) = DDCAPS2_NONLOCALVIDMEM then SysInfo.Items.Add(‘AGP video card’); if (HALCaps.dwCKeyCaps and DDCKEYCAPS_SRCBLT) = DDCKEYCAPS_SRCBLT then SysInfo.Items.Add(‘Hardware accelerated source color key blits’); SysInfo.Items.Add(‘’); SysInfo.Items.Add(‘’); {emulated caps} SysInfo.Items.Add(‘Emulated Capabilities’); SysInfo.Items.Add(‘——————————————————-’); if (HELCaps.dwCaps and DDCAPS_BLT) = DDCAPS_BLT then SysInfo.Items.Add(‘Emulated blits’); if (HELCaps.dwCaps and DDCAPS_BLTCOLORFILL) = DDCAPS_BLTCOLORFILL then SysInfo.Items.Add(‘Emulated color fills’); if (HELCaps.dwCaps and DDCAPS_BLTQUEUE) = DDCAPS_BLTQUEUE then SysInfo.Items.Add(‘Emulated asynchronous blits’); if (HELCaps.dwCaps and DDCAPS_BLTSTRETCH) = DDCAPS_BLTSTRETCH then SysInfo.Items.Add(‘Emulated stretch blits’); if (HELCaps.dwCaps2 and DDCAPS2_CERTIFIED ) = DDCAPS2_CERTIFIED then SysInfo.Items.Add(‘Microsoft certified driver’); if (HELCaps.dwCaps2 and DDCAPS2_NONLOCALVIDMEM ) = DDCAPS2_NONLOCALVIDMEM then SysInfo.Items.Add(‘Emulated AGP video card’); if (HELCaps.dwCKeyCaps and DDCKEYCAPS_SRCBLT) = DDCKEYCAPS_SRCBLT then SysInfo.Items.Add(‘Emulated source color key blits’); end; Figure 4-5:  Some supported DirectDraw features Previous Table of Contents Next Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.

Wyszukiwarka

Podobne podstrony:
WSM 04 13 pl(1)
egzamin próbny florysta 20 04 13 J Chabros
2 8 Mediatyzacja polityki 04 13
Complete Timeline of Darkest Powers Stories 2011 04 13
AE 2012 04 13 10 44 41
Analiza cwiczenia 8 04 13
pętle 2 30 04 13
02 04 13 pra

więcej podobnych podstron