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
DirectX Result Codes
Just about every DirectX function and method returns an HResult, a 32-bit number that maps to a DirectX error code. There are hundreds of error codes, all of which are located in the DDraw unit. These codes can be translated into a textual form by calling the DXErrorString function located in the DXTools unit. The DXTools unit also contains a procedure called DXCheck that will raise an exception if a DirectX function returns any error code other than DD_OK.
In theory, every call to any DirectX method should be wrapped with this DXCheck function. In practice, this may be impractical, but you should always check the results of any extremely critical methods, such as blits, flips, and initialization code. Methods such as these can cause an application to waltz off into limbo if they fail and are not gracefully handled, so checking the result code is very important for a robust application.
The DXErrorString function can be incredibly useful when debugging a DirectX application. The result of this function could be written out to a disk- based text file, and later examined if the DirectX application crashes. This tends to happen often when developing DirectX applications, and due to the fact that you cannot step through your code or use any of Delphis awesome debugging features, this is a useful, if sloppy, debugging technique.
Retrieving the DirectX Version
Most commercial DirectX applications ship with a version of the DirectX run- time redistributables. The developer knows that the application will be using either the version installed with the application or a more recent version installed by other applications or the operating system. However, sometimes it is necessary to determine which version of DirectX is installed before initializing objects, particularly if the application is to be distributed without the DirectX run-time redistributables, such as on floppy or over the Internet.
Specifically, you should not be checking for an overall DirectX version, but instead you should check for the availability of specific interfaces. As weve seen, the QueryInterface method implemented in every COM object can determine if a specific interface is supported. Using this method, you can determine if certain features are supported on the target machine. For example, if the IDirectDraw4 interface is not available, you know that youre working with a version of DirectDraw older than 6. By querying for other interfaces, you can determine if 3-D sound or force feedback devices are supported. Using the QueryInterface method is much more reliable than checking the drive for the existence and time stamp of particular files.
Additionally, DirectSetup features a method for retrieving the current version of DirectX that is installed on the machine. See Appendix A for complete information about DirectSetup and how to retrieve the current version of DirectX.
Summary
In this chapter, we discussed several DirectX and DirectDraw topics. The examples built from initializing DirectDraw all the way to implementing a general page flipping architecture and displaying bitmaps. DirectX programming in general is a very complex topic, filled with many nuances with which the developer must become familiar. We covered DirectDraw programming to a minor degree in order to illustrate this point, and as a foundation upon which the rest of the books knowledge will be built. When coding a DirectX application, and using DirectDraw in particular, it is important to keep these points in mind:
The DirectX development teams goal was to create a low-level architecture that would provide developers with the hardware control they need at the speed they demanded, while still retaining Windows device-independent benefits. This was to be accomplished without imposing a restrictive high-level design architecture. Therefore, DirectX promises three things to developers: fast execution, minimal style restraints, and a level of abstraction that will provide benefits from future hardware.
DirectX delivers exceptionally on all of its promises, and offers many benefits, such as speed, control, and feature emulation. However, DirectX programming has a number of drawbacks, such as difficult debugging, few Delphi-specific examples, and a steep learning curve. The developer must determine if the benefits and advantages offered by DirectX outweigh the drawbacks and disadvantages for the specific functionality required by the application.
The DirectX API itself, in the form of various COM objects and their methods, acts as an interface into the DirectX drivers. On the back side, the DirectX drivers can be thought of as two separate systems: the hardware abstraction layer (HAL) and the hardware emulation layer (HEL). The HAL represents the hardware itself. The HEL, on the other hand, represents the software emulation of certain features. It is important to note that, for the most part, this is completely transparent to developers.
DirectX is comprised of many components. While the inventive game developer could potentially make use of all of these components, there are only a few which are essential for game development: DirectDraw, DirectSound, and DirectInput. Other components that may be useful in a particular game include DirectPlay, DirectSetup, Direct3D, and DirectMusic.
Under Delphi, you do not necessarily need the DirectX SDK; you only need the DirectX redistributables that are installed with the DirectX SDK or almost any commercially available game. However, the DirectX SDK includes a number of debugging and control panel utilities that can be useful, and is the only source for the DirectX API documentation. In this book, we use the DirectX headers from the JEDI project, translated by Erik Unger. However, there are several other commercial and shareware/freeware DirectX components and headers that can dramatically decrease the production time for a DirectX project under Delphi.
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:
04 j 152005 04 15TI 99 04 15 T B M pl(1)Dz U 04 15 130 Zasadnicze wymagania dla kolei linowych przeWM Cw9 Spraw v13 12 04 152016 04 15 CV201615 04 2014 Pietrzyk15 04 Pilarki lancuchoweCennik zasobniki ciepła 15 04 201315 04 08 sem VIIIwięcej podobnych podstron