To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
(Publisher: The Coriolis Group)
Author(s): Stan Trujillo
ISBN: 1576100502
Publication Date: 11/01/96
Chapter 10 Full-Screen Applications
- DirectDraw
- Upgrading The RMWin Class
- The FullScreen Demo
The demos that weve looked at so far have all been windowed applications. They appear in and among windows on the Windows desktop, and can be overlapped, minimized, and maximized. Because windowed applications must integrate themselves into the desktop, they are forced to use the current Windows display mode. In this chapter, well look at full-screen applications.
A full-screen application is a program that ignores the Windows desktop and all of the desktops rules. Full-screen applications take full control of the video card and can use whatever display modes the video card supports.
Internally, windowed and full-screen applications are quite different. Full-screen applications are generally more complicated than their windowed counterparts. There are a number of practical differences, as well.
Probably the biggest difference is that with full-screen applications, we must perform our own screen updates and palette handling. With the windowed variety of Direct3D programs, we dont have to worry about these tasks. The good news is that only 8-bit modes require palettes (16-, 24-, and 32-bit display modes do not).
Another difference is that Windows doesnt understand full-screen applications. Normal Windows screen updates are performed by the Windows Graphics Device Interface (GDI). The GDI doesnt have any knowledge of full-screen applications; it assumes that it is in control at all times. This is a problem because if the GDI displays a menu or window in full-screen mode, it does so without regard for the current display mode and palette. Some full-screen applications use the GDI to display menus despite its lack of support for full-screen operation, but it is usually best not to use the GDI while in full-screen mode. The GDI can be made to behave (remain inactive) by placing a TOPMOST-style menuless window over the whole screen.
Our discussion will start with brief, focused coverage of DirectDraw. From there, we will modify the RMWin class to support full-screen operation. We will then use the new version of the RMWin class to create the FullScreen demo.
DirectDraw
DirectDraw is a generic video card control API that allows you to detect and exploit any two-dimensional features that a video card supports. DirectDraw also includes software emulation capabilities that are used to compensate for lacking video card features.
The following discussion of DirectDraw is by no means complete, but it neednt be. We will discuss only the DirectDraw functionality that we will need in our full-screen applications.
The DirectDraw Interface
DirectDraw, like Direct3D, provides the bulk of its functionality through a master interface. For Retained-Mode Direct3D, the master interface is the Direct3DRM interface. For DirectDraw, the master interface is the DirectDraw interface.
The DirectDraw interface is created with the DirectDrawCreate() function, like this:
LPDIRECTDRAW ddraw;
DirectDrawCreate( 0, &ddraw, 0 );
Cooperative Levels
DirectDraws control of the video card can be adjusted with the SetCooperativeLevel() function. The cooperative level indicates to what extent DirectDraw will cooperate with other applications. For our purposes, we will use the SetCooperativeLevel() function to obtain exclusive, full-screen control.
Display Modes
The DirectDraw interface allows us to detect and activate display modes. Display modes are detected using the EnumDisplayModes() function. Detected display modes can be activated with the SetDisplayMode() function. The RestoreDisplayMode() function can be used to return the video card to the display mode that was active before our application was launched. Later, when we write the FullScreen demo, well use these functions to write a demo that allows any detected display mode to be activated.
Page Flipping
One important DirectDraw feature is page flipping. Page flipping is an animation technique where images are prepared in an off-screen buffer and then displayed on the screen. This method is useful for two reasons. First, the preparation of the image in a hidden buffer allows for flicker-free animation because each screen image is fully assembled before it becomes visible. The second advantage is speed. Page flipping is performed by video hardware, so the screen update is virtually instantaneous.
Page flipping requires two buffers: a primary buffer and a back buffer. The primary buffer contains the data that is currently visible on the screen. The back buffer contains image data that can be moved to the primary buffer with a single operation. Later, well create both a primary buffer and a back buffer. Well copy 3D and 2D images to the back buffer, and then perform page flipping to make the new images visible.
Surfaces
In DirectDraw, a surface is a portion of memory designed to store image data. The memory that a surface uses can exist either on the video card or in system memory. Only surfaces that reside in video card memory, however, can be displayed on the screen.
Surfaces are represented by the DirectDrawSurface interface, and can be created with the DirectDraw CreateSurface() function. The CreateSurface() function takes arguments that specify the type, size, and capabilities of the surface to be created.
There are three basic types of surface: flipping surfaces, off-screen surfaces, and Z-buffers. Flipping surfaces are used to perform page flipping. The primary and back buffers in our code will be represented by flipping surfaces. Off-screen surfaces are used to store and manipulate image data, such as backgrounds and sprites. Well talk about Z-buffers next.
Z-Buffering
One of the luxuries of using Direct3D in a windowed environment is the automatic creation of Z-buffers. With full-screen applications, we must create Z-buffers explicitly.
Z-buffers are DirectDraw surfaces that have Z-buffering capabilities. Like regular surfaces, Z-buffers are created with the DirectDraw CreateSurface() function. Once a Z-buffer has been created and installed, Direct3D makes use of the Z-buffer without further intervention.
|