Search Tips Advanced Search |
| 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
## CHAPTER 4 An Introduction to DirectX This chapter covers the following topics: • The promise of DirectX • The benefits and drawbacks of DirectX programming • DirectX architecture • DirectX components • DirectX programming under Delphi • COM fundamentals • DirectDraw surfaces • Page flipping • Initializing DirectDraw • GDI rendering with DirectDraw • Displaying bitmaps • Retrieving DirectDraw capabilities • DirectX result codes • Retrieving the DirectX version Now that we’ve covered some basic graphics programming techniques, it’s time to dive into what really makes game programming under Windows a reality: DirectX. When DirectX was initially introduced, it was not well received among game programmers. People feared that Microsoft was trying to force them into a game development architecture that would potentially render useless any proprietary graphics techniques. Fortunately, this was not Microsoft’s aim, and after DirectX was looked over and evaluated by the gaming industry at large, it was embraced, and has now become the standard low-level programming interface around which games are now created. While it is possible to create some cool games using various GDI functions, to make games that will compete in today’s market the savvy Delphi programmer must use the DirectX API. ### What is DirectX? To put it technically, DirectX is really nothing more than a series of DLLs which give the developer access to low-level hardware while still maintaining some level of device independence. More specifically, DirectX is comprised of a number of COM objects which are implemented in the aforementioned DLLs. These COM objects provide the primary interface to system-level hardware in an object-oriented, language-independent fashion. The overall COM architecture allows the DirectX development team to expand and advance DirectX functionality without affecting applications written with earlier versions of DirectX. In essence, developers can now write games with all the power available under DOS while still maintaining the device independence of the Windows operating system. In practice, DirectX programming is a lot like using Delphi VCL objects without the benefit of a visual environment. Various DirectX objects are instantiated and initialized, and sometimes linked with other DirectX objects through various method calls. Unlike the VCL, however, DirectX uses several very complex data structures as parameters in many methods. The DirectX API itself is huge, spread across numerous subsystems and various objects within those subsystems. We’ll examine several of these subsystems closely throughout the remainder of this book. #### The Promise of DirectX Developing games in a DOS environment can be a nightmare. The multitude of new hardware devices pouring out of hardware vendors had dramatically differing interfaces, making it difficult indeed to support more than a handful of devices in any one game. A high-level operating system like Windows, on the other hand, offers many benefits to game developers, such as consistent programming interfaces to new devices, simplified installation and configuration features, and extensive built-in functionality. However, before the advent of DirectX, this level of abstraction in the Windows environment posed a serious performance penalty that was unacceptable in any fast-action, high- performance game. The DirectX development team’s 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. First and foremost, DirectX had to be fast in order to allow game developers to create the high-performance, adrenaline-pumping action games demanded by hard-core game players. DirectX applications must also coexist peacefully with other Windows applications, such as spreadsheets and word processors. Therefore, DirectX promises three things to developers: fast execution, minimal style restraints, and a level of abstraction that will provide benefits from future hardware. Speed One of the things that makes DirectX so fast is that it takes advantage of hardware acceleration whenever possible. If a hardware device directly supports a certain function within its electronics, such as copying an image from one area in memory to another, the DirectX drivers send the function call directly to the hardware (which is probably where the “Direct” moniker was derived). This results in blindingly fast performance. Another benefit to hardware acceleration is true multitasking capabilities. Any DirectX function that is supported in hardware will return immediately after the function is called, even before the task of that function is carried out. This allows the CPU to continue processing application instructions while other hardware is carrying out the previous command. For example, if the display hardware supports moving an image from one area to another, the application can instruct the hardware to perform this task while asynchronously performing game logic calculations. Minimal Style Restraints By its very nature, DirectX is a very low-level application programming interface. Game developers have spent a lot of time and money in creating innovative techniques for performing graphical output, techniques which can make one game stand apart from the others. If this competitive edge were to be threatened, many game developers would never have taken a second look at DirectX. Therefore, instead of creating a general gaming library that imposed high-level restrictions in how a game is put together, DirectX acts as a general enhancement to the Windows operating system. This results in many low-level function calls that provide power and speed while not insisting that developers create games “the right way.” While this may not exactly automate certain tasks, it does allow for the greatest level of creativity and ingenuity when designing new games while affording the developer a certain level of device independence. Abstraction The level of abstraction provided by the Windows operating system allows DirectX to take advantage of hardware advances as they become available. The DirectX interfaces were not designed merely to support the currently available hardware; they were designed in such a way that developers can take advantage of new hardware benefits when they are introduced. This shifts the burden of providing support for new hardware from the developers to the hardware manufacturers themselves. In many cases, when users purchase some new hardware device, all that is required for their existing DirectX games to take advantage of new benefits is to download the latest DirectX drivers. For example, when MMX technology was introduced, DirectX drivers were updated to support the new features. If a user downloaded and installed the new DirectX drivers, existing games would immediately and transparently take advantage of the new technology.
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.