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
There are many, many different types of surfaces, some of which are very specialized for a particular purpose. Surfaces can be used specifically for 3-D rendering, or for storing textures used in 3-D rendering; they can be set up to receive live video feeds, or perhaps to store only transparency information (known as the alpha channel). For the purposes of this book, we will be concerned with only three different types: the primary surface, the backbuffer surface, and off-screen surfaces.
| alpha channel: A component of color that records levels of transparency/opacity as opposed to actual color data.
The Primary and Backbuffer Surfaces Technically speaking, these are really the same type of surface. The primary surface represents the image that the user sees on the display screen. Anything drawn onto the primary surface is immediately displayed. The backbuffer surface has the same capabilities and format of the primary surface, and is used in an animation technique known as page flipping (more on this below). Off-screen Surfaces An off-screen surface, as it will be used in this book, is simply a surface in memory that is never directly displayed on the screen. Typically the same format as the primary and backbuffer surfaces, off-screen surfaces are generally used for storing background graphics and sprite animation frames. They can also be used as work surfaces for composing a graphical image. The image in these surfaces is then copied onto the primary or backbuffer surfaces to be displayed. We’ll see an example of this later in the chapter. #### Page Flipping Page flipping is an incredibly powerful technique for producing flicker-free animation. The term “page flipping” comes from the inspiration for this animation technique—that of traditional cartoon animation. Cartoons (and movies, for that matter) create the illusion of animation by displaying to the viewer a series of images, one after the other. Someone can create a crude animation by taking a stack of paper, drawing an image on each page, and then flipping through it rapidly. This is the architecture of page flipping animation. The idea is to create two surfaces, the primary surface and the backbuffer surface. The next frame of animation is composed on the backbuffer surface, and then it is “flipped” to the display screen. This updates the entire display screen in one fell swoop, resulting in a flickerless animation. Figure 4-1: Page flipping animation This page flipping animation architecture is incredibly easy to implement under DirectX. Just about every video card available supports this in hardware, making it incredibly fast. Therefore, we will use this page flipping technique for nearly every animation and game example throughout the book. We will see how to initialize and implement page flipping in the examples to follow. #### Resolution, Color Depth, and Video Memory We discussed resolution, color depth, and video memory quite a bit in Chapter 3, Basic Graphics Programming. That discussion is just as relevant to DirectDraw programming as it was to GDI graphics programming. However, under DirectDraw, the developer has much more control over the resolution and color depth. This also affects how the memory represented by a surface is directly accessed. To simplify matters, we will be concerned only with 256-color palettized display modes. A number of different display modes may be available under DirectX, and we’ll demonstrate how to retrieve a list of the available display modes shortly. #### Windowed Versus Full-Screen Perhaps the most powerful aspect of DirectDraw programming is that the application can have control over the entire display screen, known as a full-screen application. However, DirectDraw also allows a developer to take advantage of DirectDraw capabilities for drawing graphics in a regular window while sharing desktop space with other windows. This is known as windowed mode. Generally speaking, it is more difficult to support a windowed DirectDraw application than it is to support a full-screen mode. A windowed DirectDraw application requires a DirectDrawClipper object (not covered in this book), and must handle a number of other requirements typical of a traditional GDI graphical application, such as dealing with a shared palette. We are concerned only with high-performance game programming, so this book will only demonstrate full-screen DirectDraw applications. This will greatly simplify the code, and will provide us with the greatest amount of control and power. The distinction between windowed and full-screen is known as the cooperative level, and will be covered in more detail below. #### Initializing DirectDraw We’ve covered several COM and DirectDraw programming concepts, so now it’s time to see them in action. There are several tasks the application is required to perform before DirectDraw can be instantiated and the display mode modified. Some of these tasks are optional, some are not. DirectDraw, and DirectDraw surfaces, are instantiated by performing the following: • Enumerating display devices • Creating the DirectDraw object • Enumerating the supported display modes • Setting the cooperative level • Setting the display mode • Creating surfaces Enumerating Display Devices While it is safe to assume that most machines only have one display device attached, the latest version of Windows does allow multiple monitors and other display devices (such as virtual reality headsets) to be installed simultaneously. Although it is not strictly necessary, it may be good practice to allow the user to pick the display device on which to display the DirectDraw application. However, for the examples in the book, we will only be concerned with the primary display device. The function DirectDrawEnumerateEx is used to list all available display devices. It is a callback function that will call the specified function once for each installed display HAL it finds. The first device enumerated will be the primary display device; any others attached to the system will follow. The DirectDrawEnumerateEx function is declared as:
    function DirectDrawEnumerateEx(

    lpCallback: TDDEnumCallbackEx;  // the address of the callback function

    lpContext: Pointer;             // an application-specific value

    dwFlags: DWORD                  // scope flags

    ): HResult; stdcall;            // returns a DirectX error code
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.