DirectX5.0 Latest Game Programming Guide DirectDraw Articles Third, DirectDraw Elements (1)

zhaozj2021-02-11  229

Third, the most basic elements in DirectDraw in DirectDraw include collaborative grades, display mode, DirectDraw objects, surfaces, palettes, clipboards, etc., the following is introduced one by one. 1. Collaborative Level Collaboration Levels describe how DirectDRAW is interactive with interactions and events that may affect display. You can use the iDireAtDraw2 :: SetCoopeRATIVEVELEVEL method to set the collaboration level. In most cases, you can use the collaboration level to determine if the application runs in exclusive full screen mode or window mode. The DirectDraw collaboration also has the following role: Make DirectDRAW to use X mode (Mode X) resolution. If the user presses Ctrl Alt Del, the DirectDraw is prohibited from release the exclusive control and restart of the display (only in exclusive mode). Make DirectDRAW to maximize and minimize events to respond to activated events. The standard collaboration level indicates that the DirectDRAW program is a window application. In this case, you cannot change the palette and execution page of the main surface. In addition, you can't call methods that have high degree of impact on display or video memory, such as IDirectDraw2 :: Compact. Under the full-screen exclusive collaboration, you can use all of the hardware, set the usual palette and dynamic palette, change the display resolution, compact memory, and page flip. Full-screen exclusive mode does not prohibit other application allocation surfaces, nor does it prohibit them from using DirectDraw and GDI, but prohibiting other development applications changing display resolution and palette. Because the application can use DirectDraw at multi-window, when the application requires work in DDSCL_NORMAL mode, the iDirectDraw2 :: setCoopeRATIVELEVELEVELEVELEVELEVELEVELE Way does not require a specified window handle. Pass NULL to the window handle, all of which work simultaneously in standard window mode.

2. Display Modes display mode is a description of the size and bit depth of the image that the display hardware is transmitted from the main surface to the display. The display mode can be combined to: width, high and bit depth. For example, most display adapters can display a wide range of 640 pixels, high 480 pixels, and a data image of 8 bits per pixel, which is 640x480x256. To get a larger resolution or bit depth, you need more display memory. There are two types of display mode: color mode and non-torch mode. For toning display modes, each pixel is a pointing value pointing to the correlation palette. The bit depth of the display mode determines the number of colors that can have in the palette. For example, for an 8-bit color display mode, each pixel is a value from 0 to 255. In this display mode, the palette can contain a color in 256. The non-toning display mode does not use a palette, the bit depth in this mode indicates the total number of bits used to describe a pixel. Any surfaces in the main surface and the main flush chain should be matched with the size, bit depth of the display mode, the bit depth, and pixel format. 2.1, detection The supported display mode is not all of the devices that all devices are supported by all devices. To detect the display mode supported by the system, you need to call the IDirectdraw2 :: EnumDisplayModes method. By setting the appropriate value and flag, the iDirectdraw2 :: EnumDisplayModes method can list all supported display modes, and can also determine if a specified display mode is supported. The first parameter dwflags control method of the method control method can usually set DWFLAGS to 0 to ignore other options; the second parameter LPDDSurFacesc is an address of the structure DDSurfaceDesc to describe the displayed mode, generally set it All modes can be listed for NULL. The third parameter lpContext is a pointer, and DirectDRAW needs to pass the pointer to the callback function. If there is no additional data in the callback function, it can be set to NULL. The last parameter is LPENUMMODESCALLBACK, which is the address of the DirectDraw to the callback function called for each supported display mode. The callback function provided when calling the IDirectDraw2 :: EnumDisplayModes method must match the prototype of the EnumModesCallback function. For each display mode supported by hardware, DirectDraw calls your callback function to pass two parameters, the first is the address of the DDSurfaceDesc structure, which describes a supported display mode; the second parameter is called IDirectDraw2 :: EnumdisplayModes Specifies the address of the application defined by the application. By checking the value of the DDSurfaceDesc structure to get the display mode it described, where the key members are dwwidth, dwheight, and DDPFPixElFormat. DWWIDTH and DWHEIGHT describe the size of the display mode; DDPFpixElFormat is a DDPixElFormat structure that contains information about the location depth. The DDPixelformat structure includes information describing the display mode bit depth and indicates whether the display mode uses a palette. If the dwflags member contains DDPF_PALETTEINDEXED1, DDPF_PALETTEINDEXED2, DDPF_PALETTEINDEXED4, or DDPF_PALETTEINDEXED8 flags, the bit depth of the display mode is 1, 2, 4 or 8, and each pixel is an index of a phased palette. If DWFLAGS contains a DDPF_RGB flag, the display mode is a non-toner display mode, and its bit depth is provided by DwrGbbitCount members in the DDPixelformat structure.

2.2, Set the display mode You can call the IDirectDraw2 :: SetDisplayMode method to set the display mode. This method accepts four parameters to set the size, bit depth and refresh rate of the resolution of the display mode. It uses the fifth parameters to specify a special option for a given mode, which is currently only used in 13 mode and X mode 320x200x8. You can specify the bit depth of the desired display mode, but you cannot specify a pixel format that displays the hardware for the depth of the bit. To detect the RGB bit shield that the display hardware is used for the current bit depth, you can call the IDirectDraw2 :: getDisplayMode method after setting the display mode. If the current display mode is a non-toning mode, you can get the red, green, blue color position by checking DWRbitMask, DwGbitmask, and DwbbitMask. You can also change the display mode through multiple applications, as long as they share the same display card. You can also change the bit depth, as long as the application can exciptely access the DirectDraw object, all DirectDrawSurface objects release surface memory after the display mode changes, so after changing the display mode, you must use the iDirectdrawsurface3 :: RESTORE method to be re-assigned Surface memory. 2.3, Recovery Display Mode If the display mode is complete by calling the IDirectDraw2 :: SetDisplayMode method (not the iDirectDraw :: setDisplayMode method), you can call the IDirectDraw2 :: RestoreMode method to restore the original display mode. If the application is a single collaboration level, when you set the collaboration level of the application back the standard, the display mode will automatically restore the original mode. If you use the DirectDraw interface, you must explicitly recover the display mode. 2.4, X Mode and 13 Mode DirectDRAW supports x mode and 13 mode two types of display mode. 13 mode is 320x200, each pixel is 8-bit color mode, and its 16-encycloped BIOS mode number is 13. The mode X is a mixed mode derived from the standard VGA 13 mode that allows the use of 256 kB display memory (13 mode only allows the use of the applied 64KB display memory). Under Windows95, DirectDraw provides two X modes for all display cards (320x200x8 and 320x240x8). Some display cards also support linear low resolution mode, and the main surface can be locked directly, which is not allowed in X mode in the linear low resolution. DDSCL_AllowModex, DDSCL_FULLSCREEN, and DDSCL_EXCLUSIVE flags are available, as long as the application is called IDireCTDraw2 :: setCoopeRarativeEvelEvel method. If you do not specify a DDSCL_AllowModex flag, the iDirectdraw2 :: EnumDisplayModes method cannot list the X mode, when requesting the X mode, the call to the idirectdraw2 :: setDisplayMode method will fail. When the application does not use the idirectdrawsurface3 :: locksurface3 :: locksurface3 :: lock or idirectdrawsurface3 :: bLT method, write data to the main surface block, or you cannot use the idirectdrawsurface3 :: getDC method in the main surface or screen DC. The X mode is specified by the DDSCAPS_MODEX flag in the DDSCAPS scapula, and the DDSCAPS structure is part of the DDSurfaceDesc structure returned by call IDirectdrawSurface3 :: getcaps and idirectdraw2 :: EnumDisplayModes method. 2.5, high resolution and true color DirectDraw support all screen resolutions and bit depths supported by the display device driver.

DirectDRAW allows applications to change display mode to any computer display driver supported display mode, including 24-bit and 32-bit (true color) mode. DirectDraw also supports the HEL block transmission of true color surfaces. If the display device driver supports bit block transmission at these resolutions, the memory-display memory bit block transmission will use the hardware block write, otherwise heel will use HEL to increase the performance of the bit block. Windows95 and NT allow you to specify the type of display that is being used. DirectDraw checks a list of known display patterns, if DirectDRAW detects the required mode is not compatible with the monitor, the call to the idirectdraw2 :: setDisplayMode method will fail. When you call Method iDirectDraw2 :: EnumDisplayModes, only the mode supported by the monitor will be listed.

3, DirectDraw object DirectDraw object is the core of all DirectDRAW applications and an organic component of the Direct3D application. The DirectDraw object is the first object you created, and other related objects are created again through this object. A DirectDraw object is typically created by calling the DirectDrawCreate function, which returns an IDirectDRAW interface. DirectDraw objects characterize the display device. If the display device supports hardware acceleration, the DirectDRAW object can also utilize hardware acceleration. Each DirectDRAW object can process display devices and create surface objects, palette objects, and clipboard objects depending on the DirectDraw object. For example, create a surface requires call IDirectDraw2 :: createSurface method, to attach a palette object on the surface, you need to call the IDirectDraw2 :: CreatePalette method. In addition, the IDIRECTDRAW2 interface also includes a similar way to create a shear board object. You can create multiple instances of a DirectDRAW object at the same time. The easiest example is the use of dual displays in a Windows95 system. Although Windows95 does not currently support multi-display, it is possible to write a DirectDraw hardware abstraction layer for each display device. Windows95 and GDIs can identify the display device to create an instance of the default DirectDRAW object. Windows95 and GDI cannot recognize display devices can be characterized by another independent DirectDRAW object, which must be created with the global unified identifier Guid (Global Unique Identifier) ​​of the second display device. This GUID can be obtained through the function DirectDrawenumerate. DirectDRAW objects manages all other objects it created. It controls the default palette, the Color Key, and hardware display mode, which also makes the resource that has allocated and the reserved resource. The new version of DirectDraw adds new content in previous versions. The IDirectDraw2 interface extends the IDirectDraw interface by adding the IDirectDraw2 :: GetAvailableVidMem method. This method allows you to query the display device's total available video memory and how much memory is used for one specified surface. IdirectDraw2 :: SetCoopeLevel method The interaction between IDirectdraw2 :: SetDisplayMode is different from these methods in the iDirectDRAW interface. If the application uses the iDirectDRAW interface to set the collaboration level of full-screen exclusive way and change the display mode. When the standard collaboration level is returned, the display mode does not automatically recover, you must call the idirectdraw :: restiSplayMode method to explicitly recover. If you use the IDirectDraw2 interface, the call to RestoreMode is not required. However, the iDirectdraw2 :: RestoredISplayMode method does not support explicitly recover the original display mode. COM-based COM specifies that an object can provide new features by adding new interfaces without affecting its backward compatibility. Therefore IdirectDraw2 interface can replace the IDirectDRAW interface.

The new interface may be obtained by IDirectDraw :: QueryInterface method, as shown in the following C Code: // Create an IDirectDraw2 interface LPDIRECTDRAW lpDD; LPDIRECTDRAW2 lpDD2; ddrval = DirectDrawCreate (NULL, & lpDD, NULL); if (ddrval = DD_OK.! ) return; ddrval = lpDD-> SetCooperativeLevel (hwnd, DDSCL_NORMAL); if (ddrval = DD_OK) return;! ddrval = lpDD-> QueryInterface (IID_IDirectDraw2, (LPVOID *) & lpDD2);! if (ddrval = DD_OK) return; Example A DirectDraw object is created in, then call the iUnknown :: queryinterface method for the iDirectDraw interface to create an IDirectDraw2 interface. After getting an IDirectDraw2 interface, you can call its method to utilize the advantages of its new features. Because some methods may vary in the new version of the interface, therefore mixing the use of different versions of interfaces (such as iDirectDraw and idirectDraw2) may result in unpredictable errors. 3.1, multiple DirectDraw objects in each process DirectDraw allows the DirectDrawCreate function multiple times in one process. Each unique independent DirectDRAW object is returned to each unique independent DirectDraw object after each call. Each DirectDRAW object can be used for the required relationship between the objects. Each object is like being created in the process alone. DirectDrawSurface objects created every DirectDRAW object, DirectDrawClipper objects, and DirectDrawPalette objects cannot be used by other DirectDRAW objects because these objects are automatically undo when their parent DirectDRAW objects are canceled. DirectDrawClipper objects created using the DirectDrawCreateClipper function are exceptions, which in this case is independent of any other DirectDRAW object and can be used for one or more DirectDRAW objects. 3.2, Creating a DirectDraw object with CocreateInstance You can also create a DirectDraw object without using the DirectDrawCreate function and creating the DirectDraw object.

转载请注明原文地址:https://www.9cbs.com/read-4917.html

New Post(0)