Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
SSW_8_11.doc
Скачиваний:
0
Добавлен:
01.05.2025
Размер:
5.22 Mб
Скачать

Other DirectDraw Features

In addition to the features discussed in DirectDraw, DirectDraw also supports transparent blitting and overlays.

In transparent blitting, a bitmap is transferred to a surface and a certain color, or range of colors, in the bitmap is defined as transparent. Transparent blits are achieved by using color keying. Source color keying operates by defining which color or color range on the bitmap is transparent and therefore not copied during a transfer operation. Destination color keying operates by defining which color or color range on the surface will be covered by pixels of that color or color range in the source bitmap. For more information about color keying, see Color Keying.

Finally, DirectDraw supports overlays in hardware and by software emulation. Overlays present an easier means of implementing sprites and managing multiple layers of animation. Any DirectDrawSurface object can be created as an overlay with all of the capabilities of any other surface, in addition to the extra capabilities associated only with overlays. These capabilities require extra display memory. If there are no overlays in display memory, the overlay surfaces can exist in system memory.

Color keying works in the same way for overlays as for transparent blits. The z-order of the overlay automatically handles the occlusion and transparency manipulations between overlays.

Types of DirectDraw Objects

The DirectDraw object represents the display device. Multiple DirectDraw objects can be created for each logical display device. Each unique DirectDraw object can create surface, palette, and clipper objects that are independent of all other DirectDraw objects.

A DirectDrawSurface object represents a linear region of display memory that can be directly accessed and manipulated. These display memory addresses may point to visible frame buffer memory (primary surface) or to non-visible buffers (off-screen or overlay surfaces). These non-visible buffers usually reside in display memory, but they can be created in system memory if required by the hardware design or if DirectDraw is performing software emulation.

A DirectDrawPalette object represents either a 16- or a 256-color indexed palette. Palettes are provided for textures, off-screen surfaces, and overlay surfaces, none of which are required to have the same palette as the primary surface.

The DirectDraw object creates DirectDrawSurface, DirectDrawPalette, and DirectDrawClipper objects. DirectDrawPalette and DirectDrawClipper objects must be attached to the DirectDrawSurface objects they affect. A DirectDrawSurface object may refuse the request to attach a DirectDrawPalette object to it. This is not unusual, because most hardware does not support multiple palettes.

Width and Pitch

If the application writes to display memory, bitmaps stored in memory do not necessarily occupy a contiguous block of memory. In this case, the width and pitch of a line in a bitmap can be different. The width is the distance between two addresses in memory that represent the beginning of a line and the end of the line of a stored bitmap. This distance represents only the width of the bitmap in memory; it does not include any extra memory required to reach the beginning of the next line of the bitmap. The pitch is the distance between two addresses in memory that represent the beginning of a line and the beginning of the next line in a stored bitmap.

For rectangular memory, for example, the pitch of the display memory will include the width of the bitmap plus part of a cache. The figure below shows the difference between width and pitch in rectangular memory:

In figure, the front buffer and back buffer are both 640x480x8, and the cache is 384x480x8. To reach the address of the next line to write to the buffer, you must add 640 and 384 to get 1024, which is the beginning of the next line.

Therefore, when rendering directly into surface memory, always use the pitch returned by the IDirectDrawSurface2::Lock method (or the IDirectDrawSurface2::GetDC method). Do not assume a pitch based solely on the display mode. If your application works on some display adapters but looks garbled on others, this may be the cause of your problem.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]