• No results found

DirectX has hopefully been installed to your machine by now, and we have the units required to give us access to DirectX components and functionality. At this point, we can begin exploring the world of DirectX programming and all of its nuances, pitfalls, and rewards.

DirectDraw is the core, most fundamental DirectX component, and as such, is a good starting point for a discussion of DirectX programming. We will go over a good number of DirectDraw concepts, many of which are mirrored in other DirectX components. Several of the methods called and tasks performed by the

DirectDraw objects are very similar, if not exact, to those of other DirectX components, such as DirectSound and DirectInput. The learning curve discussed earlier starts here, as there are quite a few concepts to explain.

Features

DirectDraw offers many features above and beyond what is available through the Win32 API. As with all DirectX components, DirectDraw gives the developer more control over graphical output than the Windows API, while providing incredible performance not attainable using GDI functions. DirectDraw provides the following features and many more for powerful Windows game programming:

• Direct access to image memory, whether located in system or display memory

• The ability to specify the location of surface memory (i.e., system or display memory)

• Hardware acceleration for many graphical functions

• Screen resolution and color depth changing on the fly

• Direct control over the system palette (in full-screen mode)

• Powerful page-flipping methods for incredibly fast animation

In the following sections we will see how DirectDraw is used to change the display mode and color depth, how bitmaps are loaded into usable DirectDrawSurfaces, and how page-flipping animation is implemented.

Functional Overview

DirectX programming primarily consists of creating parent objects, namely objects that represent specific DirectX components, and then using these objects to create child objects that represent a specific

functionality. The following illustration and discussion outline actions that will become familiar when we cover other DirectX components.

DirectDraw programming consists of creating a DirectDraw object and several DirectDrawSurface objects.

The DirectDraw object itself acts as a liaison between the application and the display driver. Through the DirectDraw object, we can change the display resolution and color depth as well as create individual DirectDrawSurface and DirectDrawPalette objects.

Previous Table of Contents Next [an error occurred while processing this directive]

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.

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

Individual DirectDrawSurface objects represent display buffer memory. This can be either offscreen storage for image data or the visible display itself. The application uses these surface objects to communicate directly with the video hardware, either through direct memory access of image data or methods that access hardware acceleration. Surfaces provide methods to copy image data to and from each other, performing various operations on the image data such as scaling or ignoring transparent pixels. DirectDrawSurface objects encapsulate much of the power provided by DirectDraw.

DirectDrawPalette objects hold color data for images that are stored in a palettized format. They also

represent the application’s interface directly to the display hardware’s palette. DirectDrawPalette objects will be covered in more detail in the next chapter.

COM Fundamentals

DirectX objects are COM based, consequently involving all of the associated benefits and drawbacks of using COM objects. Microsoft’s Component Object Model (COM) is a huge beast, not unlike that of the VCL. A full-fledged discussion of COM is beyond the scope of this book, and unnecessary for the purposes of DirectX programming. However, there are a few COM theories that we must understand before delving into the heart of DirectX programming.

Working with DirectX objects has some similarities to working with other COM objects, but there are a few differences. The primary difference that most experienced COM programmers will discover is the fact that DirectX objects do not need to be created by using the CoCreateInstance function. Other COM objects frequently used in a traditional COM application, such as IClassFactory, are also unnecessary. All DirectX objects are created through custom function calls that return an instantiated COM object. For example, the DirectDrawCreate function is used to create an instantiated IDirectDraw object (more on this later). If you’ve never worked with COM objects before, this takes some of the confusion out of the loop, and is similar to creating traditional VCL objects in code.

A COM object can almost be thought of as a VCL object with no properties, only methods. The methods of a COM object are known as an interface. A COM object can have more than one interface, and it can be

extended by added new interfaces, similar to deriving a new component from an ancestor. However, the COM standard dictates that an interface can never change. The result of this is that older code is guaranteed to work with newer COM objects, as the original interfaces will still be implemented and available. For this reason, you will see several different types of interface declarations in the DirectX header files. As each new version

Title

---of DirectX comes out, ---offering new functionality, an entirely new interface must be created to support this functionality. However, you can rest assured that your DirectX game will still work when DirectX 7, 8, 9, etc., are introduced in the future.

An interesting feature implemented by COM allows applications to query a COM object to see if it

implements a particular interface. This allows your application to be extremely flexible when implementing certain features. For example, force feedback is a newer addition to DirectInput functionality. Your

application, upon startup, could query the DirectInput objects to see if they support the interface required to implement force feedback output. If they do not, indicating that the game is running on a machine with an older version of DirectX, you could simply bypass the part of your code that implemented force feedback.

However, if the force feedback interface is available, your application can make full use of its features. In this way, game applications can be very robust, taking advantage of special features only on those machines that have them available, while still running acceptably on older machines without those features. We will see an example of this later in this chapter when we discuss how to detect what version of DirectX the user has installed.