DirectDraw is one of the main parts of the DirectX SDK, which allows you to display memory operations directly, support hardware bit blocks, hardware override, surface flip, and maintain compatible with current Windows-based applications and drivers. DirectDraw is a software interface that keeps also compatible with Windows Graphics Device Interface in addition to the display device access. For graphics, it is not an advanced application interface. DirectDRAW provides a method-independent approilt that allows Windows-based applications and games (such as 3D graphics packages, and digital video games) to directly acquire the characteristics of the display device. DirectDraw can work in a wide variety of display devices, from simple SVGA displays to advanced display devices that provide shear, stretching, and non-RGB formats. The DirectDraw interface allows your application to simulate the performance of basic hardware and use hardware acceleration features; hardware does not provide feature will be simulated by DirectX. DirectDraw provides access to devices that display memory that makes you easily manage display memory. Your application only needs to identify some basic device properties, which are all standard hardware applications, such as the colors of RGB and YUV format. You don't need to call special procedures to use bit blocks to transfer or manipulate palette registers. Using DirectDraw, you can easily display memory and make full use of bit blocks of different types of display devices, without having to rely on specific hardware. DirectDRAW can run in Windows95 / NT4.0 and later. DirectDraw's hardware abstraction layer HAL (Hardware Abstract Layer) provides a unified interface, and the program can work directly in memory or video memory to obtain the best performance of the hardware. DirectDraw estimates the performance of video hardware, as long as you may use the specific performance provided by the hardware. For example, if the video card support bit block transmission, DirectDraw will delegate the bit block to the video card, the CPU does not participate in the processing of bit block transmission, which greatly enhances the performance of the program. In addition, DirectDRAW provides hardware simulation layer HEL (Hardware Emulation Layer), making it possible to use software simulations when certain hardware does not exist. This should be provided by these hardware. DirectDraw runs on Windows 95, which can utilize 32-bit memory superiority and "flat" memory models provided by the operating system. DirectDraw uses system memory and video memory as bulk storage instead of a small segment. In addition, DirectDraw also brought many powerful features for Windows graphics: .directDraw enables easy transformation of multiple background buffers in full screen mode. Support window mode and cutting function in full screen mode. Supports three-dimensional Z buffer. Hardware auxiliary coverage in the Z direction. Provides access to hardware for image stretching. Access standard and enhanced display device memory area. Dynamic palette, exclusive hardware access, resolution Rate switching, etc., combine these features, you can easily prepare performances that exceed GDI-based standard Windows games or even MS-DOS.
First, the basic image concept of DirectDraw provides a set of graphical terms that are different from GDI, so it is necessary to use DirectDraw, first you should understand the concepts. The following is an introduction to the important concepts in DirectDraw. 1.1 Device-independent bitmap DIB (Device-Independent Bitmap) DirectX uses device-independent bitmap DIB as the primary graphical file format. A DIB file mainly protects the following information: the dimension of the image, the number of colors used, describes the value of the color and the data describing each pixel. The DIB file also protects less use parameters, like information about file compression, and physical dimension of the image. The extension of the DIB file is generally ".bmp", sometimes it may be ".dib". Because DIB is extremely widely used in Windows programming, DirectX SDK already contains many related functions.
For example, there is a function in the DDUTIL.CPP file provided by DirectX SDK, which combines the Win32 and DirectX functions. The concept is to load a DIB file into the DirectX surface, the code is as follows: Extern "c" idirectdrawsurface * DDLoadBitmap (iDirectDraw * PDD) , LPCSTR szBitmap, int dx, int dy) {HBITMAP hbm; BITMAP bm; DDSURFACEDESC ddsd; IDirectDrawSurface * pdds;. // This is the Win32 part // Try to load the bitmap as a resource, if that fails, try it as . a file hbm = (HBITMAP) LoadImage (GetModuleHandle (NULL), szBitmap, IMAGE_BITMAP, dx, dy, LR_CREATEDIBSECTION); if (hbm == NULL) hbm = (HBITMAP) LoadImage (NULL, szBitmap, IMAGE_BITMAP, dx, dy, Lr_loadfromfile | lr_createdibsection; if (hbm == null) Return Null; // Get the size of the bitmap. GetObject (HBM, SIZEOF (BM), & BM); // Now, Return to Directx Function Calls. // Create A DirectDrawSurface for this Bitmap. ZeromeMory (& DDSD, SIZEOF (DDSD); DDSD.DWSIZE = SizeOf (DDSD); DDSD.DWFLAGS = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; DDSD.D dsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = bm.bmWidth; ddsd.dwHeight = bm.bmHeight; if (! pdd-> CreateSurface (& ddsd, & pdds, NULL) = DD_OK) return NULL; DDCopyBitmap (pdds, hbm, 0, 0, 0, 0); DeleteObject (HBM); Return PDDS;
1.2, drawing surface (Drawing Surface) Draw the surface accepts video data and displays it as an image. In most Windows applications, you can use the Win32 function such as getDC to access the drawing surface. GETDC Getting the Device Context DC (Device Context), after obtaining the device, you can redraw the surface. However, the image function of Win32 is provided by GDI. GDI is part of the system that provides an abstract layer that allows the standard Windows program to draw surfaces. The disadvantage of GDI is that it is not designed for high-performance multimedia software, which is mainly used for commercial software such as word processing and spreadsheet software. GDI provides access to video buffers in system memory, but does not provide access to video memory. Although GDI is very suitable for most commercial software, it is too slow to multimedia applications and game software. On the other hand, DirectDraw provides a drawing surface that characterizes real video memory, which means that when you use DirectDraw, you can write data directly to the video, so that the image's display speed is enough. These surfaces are characterized as a continuous memory block that makes it easier to address addresses. 1.3, bit block Transfer Blit Blit is the story of "Bit Block Transfer", indicating bit block transmission. It is a way to transmit a data of one address in memory to another address. Block transmission is often used in the elf animation. You can use the iDirectdrawsurface3 :: BLT method and the iDirectdrawsurface3 :: Bltfast method to perform bit block transmission. 1.4, page flipping and back buffering page flip is the key to multimedia, animation, game software. The software page flip is an simulation of cartoon painters to motion image motion. For example, the painter draws a character on a piece of paper, then placed it in the next frame, for each frame, only rarely changing the character image. When you quickly flip the sheet of paper, the continuous character image seems to have an animation. The page flips in the software is similar to the above process. First, you have established a series of DirectDraw surfaces, which are ready to "flip" to the screen. The first surface is considered as a primary surface, which is called a background buffer after all surfaces behind the main surface. The application writes the data to the background buffer, then flips the main surface, so the background buffer is displayed on the side. When the system is displaying an image, the program can write data to the background buffer, which has continued until the end of the animation, which makes you quickly and efficiently turn the discrete image into an animation. DirectDraw can utilize relatively simple double buffers (one main surface and a background buffer), can also use more complex technologies to add other background buffers. Make you can easily create a program that flipped.
1.5, rectangle, one of the most important concepts programming through DirectDraw and Windows is the object on the surface - a bounded rectangle. A bounded rectangle is determined by two points, namely the upper left corner and the lower right corner. When writing data in a block transmission, most applications use the RECT structure to transmit information about the boundary rectangle. The definition of the RECT structure is as follows: typedef struct tagRect {long left; // this is the top-left corner's x-coordinate. Long top; // the top-left corner's y-coordinate. Long Right; // the bottom-Right Corner's X-coordinate. Long bottom; // the bottom-right corner's y-coordinate.} Rect, * prect, Near * npRect, Far * LPRECT; where Left and TOP member variables are values of X, Y coordinate in the upper left corner of the rectangle, Right and Bottom are coordinate values of X, Y in the lower right corner.
1.6, Sprite Many video games use the elf. In the most basic sense, a wizy is an image that moves on the screen. The elves drawn on a surface, overridden on the existing background, the synthetic image is sent to the screen. 1.6.1, the difficulty in transparent blitting and Color Key Elf animation is the treatment of non-standard rectangular wizards. Because the bit block transport function is working in a rectangular mode, your elf must be placed in a rectangle, regardless of whether it is rectangular on the screen. The elf image itself is not a rectangular, but it is included in the rectangular area. When the image is transferred to the destination when using the bit block to the destination, the pixels that do not belong to the elves are "transparent". The programmer selects any color to create a wizard, which is used as a transparency "color key". It is an uncommon color, and the programmer is only used to represent transparency or specific color ranges. With the idirectdrawsurface3 :: setColorKey method, you can set the Color Key for a surface. After setting the Color Key, call the idirectdrawsurface3 :: bltfast method to use the set of Color Key, regardless of whether the pixel matches the color key. This type of Color Key is the source Color Key. Source Color Key Forbidden "Transparent" pixels from writing to the destination, so that the original background pixel is retained, making the elf look up and the elf can move on the background. In addition, you can also use a Color Key to influence the surface of the target (the purpose of the purpose of the purpose). The purposes of the purpose Color Key are also a color on the surface, which is used to indicate whether pixels can be covered by the elves. 1.6.2, Sprite and Patch Rectangle In order to produce the effect of the elf movement, you must erase the elf image from the old position from the background before drawing the elf. Of course, it is also possible to re-transfer the entire background and then heavy painting, but this will greatly reduce the quality of animation. In fact, you can keep the last trajectory of the elongated rectangle, and then redraw only the location. This method is called "patching". In order to fix the outstanding position, you can use the original background image (already transferred to a screen outside the surface) to redraw this location. The bit block transmission method is used in this process, and the processing time for the consumption is very small during the cycle of the entire surface. The following is a simple step of this process: (1). Setting the fixing rectangle (2) in the last position of the Elf. Use the bit block to transfer the primary copy of the background image in the outer surface of the screen to this position (3). Update The elf is a destination rectangle, which reflects the new position (4). Transfer the wizard block to the newly updated rectangular position (5) on the background. Repeat the powerful image function provided by DirectDraw with linear C / C The program combines, using the above steps, you can create a simple elf animation. 1.6.3, Bounds Checking and Hit Detection In the elf animation, boundary inspection and collision detection is two very shops and a very important task. The boundary is the scope of the restrictions, and the boundary check is to check the position of the elves through the RECT structure. Collision detection is to check if multiple elves take up the same location. Most collision detection is to check if there is a coverage between the rectangles of each elf.
Second, DirectDraw system multimedia software requires high performance image. Through DirectDraw, Microsoft makes the procedures for image sensitivity are greatly improved in speed and efficiency, while maintaining device-independence, DirectDRAW provides tools to complete the following key tasks:. Operate more Display surface. Access video memory directly. Page flip. Background buffer. Management of palette. Cutting additionally, DirectDraw allows you to query the display hardware's performance and then provide the optimal performance that the display device can support. DirectDraw provides a COM-based service interface that uses the most iDirectDraw2, IDirectdrawSurface3, iDirectdrawPalette, IDirectDrawClipper, and IDirectDrawVideoport. In addition to these interfaces, DirectDraw continues to support previous versions of interfaces. The DirectDRAW object is characterized to display the adapter, reveal its method through the iDirectdraw and the iDirectDraw2 interface. In most cases, you can use the DirectDrawCreate function to create a DirectDRAW object, or you can use COM functions CocreateInstance. Once you have created a DirectDraw object, you can call the IDirectDraw2 :: createSurface method to create a surface for that object. The surface characterizes the memory on the hardware, or both video memory, or system memory. DirectDraw expands support for palette, shear, and video ports through other interfaces.
1. DirectDraw object type DirectDRAW object can be a separate object or a combination of several objects. The latest version of DirectDraw has the following types of objects: 1.1, DirectDraw object DirectDraw object is the core of the DirectDraw application, which is the first object you created. Once you have created a DirectDraw object, you can create all other relevant objects on it based on it. Creating a DirectDraw object is DirectDrawCreate. 1.2, the DirectDrawSurface object DirectDrawSurface object characterizes a memory area, and the data of the area will be displayed on the screen or moved to other surfaces as an image. Creating a DirectDrawSurface object is iDirectdraw2 :: createSurface, other related methods can be obtained by interface IDirectdrawSurface, IDirectdrawSurface2, and IDirectDrawSurface3. 1.3, the DirectDrawPalette object DirectDrawPalette object (sometimes "Palette") characterizes a 16-color or 256 colored index palette for the surface, which contains a series of RGB color index values that describe the same surface. The method for creating a DirectDrawPalette object is iDirectdraw2 :: CreatePalette. Other methods can be obtained from the interface IDirectDrawPalette. 1.4, DirectDrawClipper object DirectDrawClipper object (sometimes "clipper") Help you write data from a location or exceeding the surface, creating DirectDraw2 :: CreateClipper, other related methods can be from interface IdirectDrawClipper is obtained. 1.5, DirectDrawVideoPort Object DirectDrawVideoPort object characterizes only video port hardware with only one system, which allows the frame buffer to access the frame buffer without having to access the CPU or use the PCI bus. You can first specify the IDDVIDEOPORTCONTAINER flag, then call the QueryInterface method to create a DirectDrawVideoPort object. Other related methods can be obtained from interface IDDVideoPortContainer and IDirectDrawVideoport. 2, hardware abstraction layer HAL (Hardware Abstract Layer) DirectDRAW provides devices independent by hardware abstraction layer HAL. HAL is a special equipment interface and is provided by equipment manufacturers. DirectDRAW operates directly on the display device with HAL. Applications and different HAL interactions. Equipment manufacturers provide HAL in the form of 16 or 32-bit code under Windows95. Under WindowsNT, HAL is 32-bit code. HAL can be part of the display driver, or a dynamic link DLL that displays the driver communication with the private interface defined by the manufacturer. DirectDraw HAL is provided by a chip, a board or OEM (Original Equipment Manufacture). HAL only provides device-related code, not simulated when executed. If a function is not supported by hardware, HAL will not treat this function as part of hardware performance. In addition, HAL does not confirm the parameters, and DirectDRAW will work in the call to complete the parameters prior to calling HAL.
3. Software Emulation When the hardware Hal does not support a certain feature, DirectDRAW tries to simulate this feature. The simulation function is provided by the hardware emulation layer HEL (Hardware-emulation waiting. Obviously, software simulation is not equivalent to the characteristics of hardware itself. You can use the iDirectdraw2 :: getCaps method to query the features supported by the hardware. Sometimes, the inherent characteristics of hardware and the combination of both software simulation are slower than the software simulation alone. For example, if the display device driver supports DirectDraw but does not support the pull-out block write, it will generate loss of performance when stretched from the video memory surface or bit block transmission. Because video memory is usually slower than the speed of the system memory, the CPU must wait. Therefore, if your application uses hardware unable to provide features, it is best to create a surface in system memory to avoid performance losses that occur when the CPU accesses the video memory. 4. System Integration The following figure shows the relationship between DirectDraw, graphics device interface GDI, hardware abstraction layer HAL, hardware simulation layer HEL, and hardware. As shown in the figure, a DirectDRAW object is a parallel relationship with GDI, both through the device-related abstract layer access hardware. Different from GDI, DirectDRAW will make full use of unique features provided by hardware. If the hardware does not support a feature, DirectDraw will try to simulate it with HEL. DirectDraw can also provide surface memory in the form of device context, which can use GDI functions to handle surface objects.
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.
Here are the steps used to create DirectDraw object CoCreateInstance function: i COM call CoInitialize initialized when the application starts:.. If (FAILED (CoInitialize (NULL))) return FALSE; ii CoCreateInstance function and use IDirectDraw2 :: Initialize method creates DirectDraw objects : ddrval = CoCreateInstance (& CLSID_DirectDraw, NULL, CLSCTX_ALL, & IID_IDirectDraw2, & lpdd); if ddrval = IDirectDraw2_Initialize (lpdd, NULL); in the call to CoCreateInstance, the first parameter CLSID_DirectDraw is DirectDraw driver object class (FAILED (ddrval)!) The class flag, the IID_IDIRECTDRAW2 parameter indicates the DirectDraw interface to be created, and the LPDD parameter points to the acquired DirectDRAW object. If the call is successful, the function will return the DirectDRAW object that has been initially initialized. Before using the DirectDraw object, you must also call the iDirectdraw2 :: initialize method, which does not use the GUID parameter (DirectDrawCreate function requires only as long as it is). After the DirectDraw object is initialized, you can use it or release the object, just that the object is created by the DirectDrawCreate function. If you use the method associated with the DirectDraw object before calling the IDirectDraw2 :: Initialize method, a DderR_notinitialized error will result in a DDERR_Notinitialized error. Before shutting down the application, you should use the CounInitialize function to close the COM, the form is as follows: Counitialize ();
4. Surface A surface or DirectDrawSurface object characterizes a linear memory area. The surface usually resides in the display memory, and of course, it can also exist in system memory. DirectdrawSurface objects are placed on the location where the DirectDrawSurface object is capable of gaining the DirectDrawSurface object unless you are creating a DirectDrawSurface object. The DirectDrawSurface object can also utilize the special processor on the display card, which can not only speed up the execution speed of the task, but also to handle some tasks with the system CPU parallel. With the iDirectdraw2 :: CreateSurface method, you can create a single surface object, a complex surface flip strand and a three-dimensional surface. Use the CreateSurface method to create the required surface or flip chain and get a pointer to the IDirectDrawSurface interface of the main surface. The IDirectDrawSurface3 interface allows you to access memory directly with bit block transmission methods, such as IDirectDrawSurface3 :: BLTFAST methods, etc. Surface objects can improve a device context, which allows you to use GDI functions. In addition, you can access the display memory between the iDirectDrawSurface3 method. For example, you can use the iDirectdrawSurface3 :: Lock method to lock the display memory and get the address of the relevant surface. The address of the display memory may point to the visible buffer memory (main surface) or invisible buffer (exterior surface or overlay surface). Inasoless buffers typically reside in the display memory, but can be created in system memory, if the hardware allows or DirectDRAW uses software simulation functions. In addition, the IDirectdrawSurface3 interface extends some ways. With these methods, you can place or get the palette to work in the specified type surface. 4.1 Surface Interface DirectDrawSurface object expresses its function via iDirectdrawsurface, IDirectDrawSurface2, and iDirectDrawSurface3 interface. Each new version of the interface has increased the same functionality as previous versions, and through new methods, it provides the ability to have no feature in the old version. The oldest version in this class interface on the IDirectdrawSurface interface, when you use the idirectdraw2 :: createSurface method to create a surface, the default is this interface. To use the new features provided by another version, you must also query the new version of the interface with the queryinterface method.
The following code shows how to do this work: LPDIRECTDRAWSURFACE lpSurf; LPDIRECTDRAWSURFACE2 lpSurf2; // Create surfaces memset (& ddsd, 0, sizeof (ddsd)); ddsd.dwSize = sizeof (ddsd); ddsd.dwFlags = DDSD_CAPS |. DDSD_WIDTH | DDSD_HEIGHT; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; ddsd.dwWidth = 10; ddsd.dwHeight = 10; ddrval = lpDD2-> CreateSurface (& ddsd, & lpSurf, NULL); if (ddrval = DD_OK!) return; ddrval = lpSurf-> QueryInterface (IID_IDirectDrawSurface2, (LPVOID *) & lpSurf2); if (ddrval = DD_OK!) return; ddrval = lpSurf2-> PageLock (0); if (! ddrval = DD_OK) return; ddrval = lpSurf2-> PageUnlock ( 0); if (DDRVAL! = DD_OK) Return; the above example is the IDirectDrawSurface 2 interface of the DirectDrawSurface object by specifying the IID_IDirectDraw2 flag when calling the QueryInterFace method. To get the idirectdrawsurface3 interface, use the IID_IDIRECTDRAWSURFACE3 flag instead of IID_IDIRECTDRAW2. 4.2, Color Key DirectDRAW Supports bit block transmission and override surface mode Source Color Key and destination Color Key. Set the Color Key of the surface by calling the IDirectdrawSurface3 :: SetColorKey method. When using the bit block transmission, the source color key indicates the color or color range that is not copied, and the destination Color Key indicates the replaced color or color range. Some hardware only support the color range of YUV pixel format. YUV data is usually video data, and the transparent background may not be a single color due to the quantization error in the conversion. Color Key is specified with the pixel format of the surface. If the surface is a color format, the Color Key is specified as the range of indexes or indexes. If the pixel format of the surface is specified by the FourCC code describing the YUV format, YUV's Color Key is specified by two members dwcolorspacelowValue and DWColorspacehighValue in three DDColorKey structures. The three bytes are V, U, Y data, respectively. . The dwflags parameter in the IDirectdrawSurface3 :: setColorKey method indicates whether the Color Key is used to overwrite or bit block transfer operations, whether it is a source Color Key or the destination Color Key.
The following code is a valid Color Key Some instances: // 8-bit torch mode // palette entity 26 is Color Key. Dwcolorspacelowvalue = 26; dwcolorspacehighValue = 26; // 24-bit true color mode // color 255, 128, 128 is a color key dwColorSpaceLowValue = RGBQUAD (255,128,128);. dwColorSpaceHighValue = RGBQUAD (255,128,128); // FourCC YUV mode // Any YUV color where Y is between 100 and 110 // and U or V is between 50 and 55 is DWCOLORSPACLOWVALUE = YUVQUAD (100, 50, 50); dwcolorspacehighValue = YUVQUAD (110, 55, 55); 4.3, pixel format pixel format points to any explanation of each pixel data in surface memory. DirectDRAW describes various pixel information using the DDPixElFormat structure. Members of the DDPixelformat structure describe the following features of the pixel format:. Toning or non-torch pixel format. If it is a non-toner format, the pixel format is RGB or YUV format. Bit depth. Pixel format components The bit shielding you can call you IDirectDrawSurface3 :: getpixelformat method to get the pixel format of the existing surface.
4.4, Creating a surface DirectDrawSurface object characterizes a surface that resides in the display memory. If the memory is displayed or explicitly created, the surface can also exist in system memory. You can create one or more surfaces using the iDirectdraw2 :: CreateSurface method. When calling createSurface, you must specify the size of the surface, the surface type (is a single surface or complex surface), the pixel format (if the surface does not use the palette of the index). All of these features are included in the DDSurfaceDesc structure, and the address of the structure will be transmitted in the past. If the hardware does not support request, the call will fail if those resources have been assigned to another DirectDrawSurface object. Creating a single surface or multi-surface requires only a few lines of simple code. There are four main steps to create a surface. Every step is more ready than the previous step, but it is not too difficult, they are: (1). Create a main surface (2). Create a screen (3). Create a complex surface and flip chain (4). Creating a wide surface In the default, DirectDraw creates a surface in the local video memory. If enough local video memory saves the surface, DirectDraw tries to use non-local video memory (only in some AGP device systems) . You can explicitly specify the surface in which type memory is explicitly indicated to the DDSCAPS structure with the appropriate flag when calling createSurface. 4.4.1, Creating the main surface main surface is visible on the display and indicated by the DDSCAPS_PRIMARYSURFACE flag, each DirectDRAW object can only have a main surface. When you create a home surface, its size should match the current display mode. Therefore, in this case you don't need to indicate the size of the surface. In fact, if you indicate the size of the surface, even if you match the current display mode, it will also result in failure of the creation process. The following example shows how to set the relevant members of the structure to create a master DDSURFACEDESC surface:. DDSURFACEDESC ddsd; ddsd.dwSize = sizeof (ddsd); // Tell DirectDraw which members are valid ddsd.dwFlags = DDSD_CAPS; // Request a primary surface DDSD.DDSCAPS.DWCAPS = DDSCAPS_PRIMARYSURFACE; 4.4.2, Creating a screen Out of Surface Screen The outer surface is usually used for the cache of bitmaps, which will be transferred by the bit block to the main surface or in the background buffer. You must set the DDSC_WIDTH and DDSD_HEIGHT flags and set DWWIDTH and DWHEIGHT members to explain the size of the outer surface of the screen. In addition, you must also include DDSCAPS_OFFSCREENPLAIN flags in the DDSCAPS structure. DirectDraw uses system memory to create a surface when there is not enough display memory usage. You can display DDSCAPS_SYSTEMEMORY or DDSCAPS_VIDEMEMORY flags in the DDSCAPS structure to explicitly indicate that the memory is displayed in the system memory.
The following example shows the previous screen to create an outer surface preparation: DDSURFACEDESC ddsd; ddsd.dwSize = sizeof (ddsd); // Tell DirectDraw which members are valid ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; // Request a. Simple Off-Screen Surface, SIZED / / 100 BY 100 Pixels. Ddsd.ddscaps.dwcaps = DDSCAPS_OffScreenPlain; dwheight = 100; dwWidth = 100; In previous versions of DirectX, the maximum width of the exterior surface cannot exceed the width of the main surface. In DirectX 5, you can create an exterior surface of any width, as long as the display device is pointed out. It should be noted that when the width of the exterior surface is declared, if the width of the surface of the requested surface is displayed, the surface will be created in the system memory. If the video memory is explicitly declared, the work of creating a surface will fail when the video memory is not enough. 4.4.3, Creating a complex surface (FLIPPING) A complex surface is a set of single surfaces created with the idirectdraw2 :: createSurface method. If the DDSCAPS_COMPLEX flag is set when CreateSurface is called. In addition to the explicit specified surface, DirectDRAW will also implicate one or more surfaces. You can manage complex surfaces like manageing a single surface. Call iDirectDraw :: Release method Releases all surfaces, call IDirectdrawSurface3 :: Restore to recover these surfaces. The most commonly used complex surface is a flip chain. Typically, a flip chain is from one main surface and one or more background buffer groups. The DDSCAPS_FLIP flag shows that a surface is part of a flip chain. Creating a flip chain with this way also requires the DDSCAPS_COMPLEX flag. The following example creates a chain of flip main surface preparation needed: DDSURFACEDESC ddsd; ddsd.dwSize = sizeof (ddsd); // Tell DirectDraw which members are valid ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; // Request a primary surface. WITH A SINGLE / / BACK Buffer DDSD.DDSCAPS.DWCAPS = DDSCAPS_COMPLEX | DDSCAPS_FLIP | DDSCAPS_PRIMARYSURFACE; DDSD.DWBACKBUFFERCOUNT = 1; this example constructs a double buffer overwhelming environment. Call the IDirectdrawSurface3 :: Flip method to swap the surface memory of the main surface and the background buffer. If the DwBackBufferCount in the DDSurfaceDesc structure is 2, two back buffers will be created, and the surface will be turned around each time the flip is looped and the three buffer overwhelming environments are provided. 4.4.4, Creating a wide surface (Wide Surface) DirectDRAW allows you to create an exterior surface that is wide than the main surface, of course this needs to display hardware support. To determine if the display device supports the wide surface, you need to call the IDirectDraw2 :: getCaps method to see if DWCaps2 members in the first DDCAPS structure include DDCaps2_WIDesurfaces flags.
If the flag exists, it indicates that the outer surface of the exterior surface that is wider than the main surface can be created in the video memory. If the flag does not exist, create a wide surface in the video memory will fail and return a DDERR_INVALIDPARAMS error. The system memory surface, the video port surface, and the buffer are supported by the wide surface. 4.4.5 Flipping Surface DirectDraw can be constructed as a flip surface. A flip surface is any of the memory that can exchange each other between the Front Buffer and the Back Buffer. Typically, the front buffer is the main surface, but this is not required. When using the IDirectDrawSurface3 :: FLIP method to perform surface flip operation, pointing to the surface memory of the main surface and a pointer to the surface memory of the background buffer interchange. Therefore, the flip of the surface is the exchange of the display device to point to the pointer of the memory, not a copy of the surface memory. The only exception is that it is just simply copy the surface when DirectDraw is flipped. DirectDraw uses software simulation to flip operations with software simulation when a background buffer cannot be loaded into memory or hardware is not supported. When a flip chain contains a major surface and a plurality of background buffers, the switching of the pointer uses a loop mode, as shown below: The other additional surface of the DirectDRAW object is not part of the flip chain, not affected by the FLIP method. influences. Remember that the DirectDRAW flip surface is implemented by swapping a pointer to the surface memory of the DirectDrawSurface object instead of exchanging these objects. This means that when the bit block is transmitted to the background buffer, the same DirectDrawSurface object must always be used, which is the background buffer you created a flip chain. The pointing operation is always done by calling the FLIP method of the front desk buffer. 4.4.6 Losing Surface When the DirectDrawSurface object characterizing the surface memory is unnecessary, the surface memory associated with the surface is released. This is to lose the surface. When the DirectDrawSurface object is in its surface memory, many methods do not perform other operations and returns Dderr_SurfaceLost. Since the display mode or another application has released all surface memory that is currently allocated, the surface may be lost. The iDirectdrawsurface3 :: RESTORE method Recreate these lost surfaces and re-connects with the DirectDrawSurface object. The recovery surface does not place the bitmap before the surface is lost. Therefore, if the lost surface must be completely reloaded into the previously loaded graphics. 4.4.7, the release surface is like all COM interfaces, when there is no need, the Release method must be called to release the surface. Each individually created surface must be explicitly released. If it is called IDirectdraw2 :: createSurface or iDirectdraw :: CreateSurface method Explicitly created multiple surfaces (such as flip chains, etc.), you only need to release the front bobbure. In this case, any pointer to the surface of the background buffer will be explicitly released, and it is not reused. 4.4.8, Updating Surface Characteristics You can use the iDirectdrawsurface3 :: setSurfaceDesc method to update features of existing surfaces. With this method, you can change the pixel format, or you can change the location of the system memory in the surface of the DirectDrawSurface object, which is explicitly assigned by the application.
It allows a surface directly using data in the previously assigned buffer without copying, this new surface memory is allocated by the customer application, and is also released by the customer application. When calling the idirectdrawsurface3 :: setSurfaceDesc method, the LPDDSD parameter must be the address of the structure DDSurfaceDesc describing the new surface memory, that is, pointing to the memory address. In the DDSurfaceDesc structure, only DWFLAGS members can be set to reflect the location, size, and pixel format of the surface memory. Therefore, DWFLAGS can only contain a combination of DDSD_WIDTH, DDSD_HEIGHT, DDSD_PITCH, DDSD_LPSURFACE, and DDSD_PIXELFORMAT, etc., with these combinations to set effective structural members. Before setting the value of the structure, you must allocate the memory to load the surface. The size of the assigned memory is very important. You need not only to assign enough memory to accommodate the width and high surface, but also leave enough memory space for surface spacing (PITCH), the surface spacing is a Qword (8 bytes), the spacing is high instead of using pixels Measurement. When setting the value of the surface in the structure, the LPSURFACE member is a pointer you assigned, DwHeight and DWWIDTH members describe the size of the surface in pixel units. If the size of the surface is specified, you also need to populate the iPitch member to reflect the surface spacing. DDPFPixelformat members describe the pixel format of the surface. In addition to the LPSurface member, if you don't set a value for these members, the IDirectdrawSurface3 :: setSurfaceDesc method uses the default value from the current surface. Pay attention to some problems when calling the IDirectDrawsurface3 :: setSurfaceDesc method. For example, LPSurface must be a valid pointer for system memory (this method does not currently support video memory pointers); DWWIDTH and DWHEIGHT must be non-zero; the main surface or other surface cannot be reassigned in the main flip chain. You can assign the same memory for multiple DirectDrawSurface objects, but you must notice that the memory is allocated to the memory when the memory is assigned to any surface object. The use of incorrect use of the setsurfacedesc method can result in an unpredictable reaction. Therefore, when you no longer need surface memory, you must remember to release it. However, when the method is called, DirectDRAW will release the explicitly allocated surface memory when the surface is created. 4.4.9, Direct Accessing The Frame-Buffer Directly You can use the iDirectdrawSurface3 :: Lock method to access surface memory in the frame buffer or system memory. When this method is called, the LPDESTRECT parameter is a pointer for a RECT structure. This structure describes a rectangle on the surface to be directly accessed. To lock the entire surface, you can set the LPDESTRECT to NULL. You can also specify a RECT that contains only a part of the surface. If there is no two rectangles overlap, two processes can lock multiple rectangles in a surface. The LOCK method fills the DDSurfaceDesc structure with all the information that needs to properly access the surface memory. This structure contains information about surface spacing and pixel format (the pixel format of the same host surface is not at the same time). After completing access to the surface, call the iDirectdrawsurface3 :: UNLOCK method to unlock it. 4.4.10, using non-local video memory surface (use non-local video memory "DirectDraw supports advanced graphics port AGP (Advanced Graphics Port) feature, can be created in non-local video memory.
In the AGP system, if the local video memory has been used or the application explicitly requires non-local memory, DirectDRAW will create a surface using a non-local video memory. Currently, there are two AGP systems. One is "Execute Model), one is Direct Memory Access Model. In the execution model, the display device supports the same characteristics of non-local video memory and local video memory. Therefore, when you use the IDirectDraw2 :: getCaps method to get your hardware performance, the same bit block transfers related flags DWNLVBCAPS, DWNLVBCAPS2, DWNLVBCAPS, DWNLVBFXCAPS, and DWNLVBROPS will indicate that the local video memory is used. In execution mode, if the local video memory is run, DirectDRAW will automatically use non-local video memory. In the DMA model, support for texture map transmitted from non-local video memory is limited. When the display device uses the DMA model, you want to obtain the performance of the hardware, and the DWCAPS member will be set to the DDCAPS2_NONLOCALVIDMEMCAPS flag. The same bit block transmission-related logo is included in members of DWNLVBCAPS, DWNLVBCAPS, DWNLVBCKEYCAPS, DWNLVBFXCAPS, and DWNLVBROPS. DirectDraw will not use non-local video memory to create surfaces unless explicitly indicated. The implementation of the DMA model is different in support for non-local video memory surfaces. If the driver supports the texture map from a non-local video memory surface, the D3DDEVCAPS_TEXTURENONONLOCALVIDMEM flag will be set when the 3D device is obtained with the iDirect3ddevice2 :: getcaps method. 4.4.11 Conversion Color and Format Non-RGB Surface Format is represented by four characters. If the application calls the iDirectdrawsurface3 :: getpixelformat method to require the use of the pixel format, and the surface is a non-RGB surface, the DDPF_FOURCC flag will be set, and the members dwfourcc in the DDPixElFormat will become effective. If the Fourcc code is represented by a YUV format, the DDPF_YUV flag will be set, dwyuvbitcount, dwybits, dwubits, dwvbits, and dwyuvalphabits members will be a valid mask, which can be used to extract information from the pixels. If the current RGB format is current, the DDPF_RGB flag will be set, dwrgbbitcount, dwrbits, dwgbits, dwbits, and dwrgbalphabits members will be a valid mask that can be used for advance information from pixels. During the colors and formats, there are two groups of FOURCC code for the application. A set of capabilities identified the power of hardware block transmission, and the other group identified hardware coverage. 4.4.12, overlay surface (Overlay Surfaces) coverage surface is a surface with special hardware support capabilities, typically used to display active video, recording video, or still bitmaps without providing bit blocks to the main surface or changing the main surface. This is entirely provided by the word coverage surface, and DirectDraw supports the features supported by the display device driver, and DirectDRAW does not simulate the surface. The cover surface can be imagined as a plastic paper, and we can draw on this plastic and placed it in front of the display. When plastic paper is covered in front of the display, you can see the overlay and main surface, after removing plastic paper, the main surface has not changed. The working principle of covering the surface is similar to the principle of transparent plastic paper.
When a cover surface is displayed, it is to tell the device driver how to make the coverage surface visible. When the display device scan line is swatched to the display, it checks each pixel on the main surface to see if it is overwritten. If so, the display device is replaced from the data of the associated pixel from the overlay surface. Using this method, display the adapter card generates the main surface and the synthetic surface of the cover surface, generating transparent and stretching effects without changing the content of each surface. Synthetic surface is sent to the display directly to the display. Because this processing and pixel replacement is the hardware level operation, there is no significant performance loss. In addition, this method also enables seamlessly synthesizing the main surface and covers the surface with different pixel formats. Creating an overlay surface You need to specify a DDSCAPS_OVERLAY flag in the DDSCAPS structure, then call the iDirectDraw2 :: CreateSurface method The overlay surface can only be created in the dominant memory, so you must also include the DDSCAPS_VIDEMEMORY flag. As with other types of surfaces, by containing a suitable logo, a single coverage surface can be created, or a flip chain consisting of multiple overrides. You can call the iDirectdraw2 :: getCaps method to get information about supported overlay features. This method fills a DDCAPS structure with the description of all feature information. In reporting hardware features, the device driver sets the flag of the DWCAPS member to indicate when to enforce some type of constraint provided by the hardware. After the ability to obtain the driver, you can know the information provided by checking the DWCAPS member. The DDCAPS structure contains nine members, which describes the constraints of coverage of the surface. The subscript is listed in the same coverage. Membership Sign dwMaxVisibleOverlays the member is always active member of the dwCurrVisibleOverlays always effective dwAlignBoundarySrcDDCAPS_ALIGNBOUNDARYSRCdwAlignSizeSrcDDCAPS_ALIGNSIZESRCdwAlignBoundaryDestDDCAPS_ALIGNBOUNDARYDESTdwAlignSizeDestDDCAPS_ALIGNSIZEDESTdwMinOverlayStretchDDCAPS_OVERLAYSTRETCHdwMaxOverlayStretchDDCAPS_OVERLAYSTRETCH
DwMaxvisibleOverlays and dwcurrvisibleoverlays members indicate the maximum number of overrides that the hardware can be displayed, as well as how many visible. DwalignBoundarySRC, DwalignSizesrc, DwalignBoundaryDest, DwalignSizeDest, and DwalIgnstridealign members are constraints of the rectangle and size of the hardware report. The values of these members refer to how to determine the size and position of the source rectangle and the destination rectangle when the cover is displayed. DWMINOVERLAYSTRETCH and DWMAXOverLaystretch are information about tensile factors. A, source rectangular and destination rectangle To display an overlay surface, you need to call the idirectdrawsurface3 :: updateoverLay method, specify the DDOVER_SHOW flag in the dwflags parameter. This method requires you to specify a source rectangle and destination rectangle in the LPSRCRECT and LPDESTRECT parameters. If the entire surface is used, the LPSRCRECT parameter is set to NULL. The destination rectangle is a position where the cover surface is generated on the main surface. Source, the destination rectangle does not have to be the same. Generally, the destination rectangle must be large or small, and the hardware is automatically compressed or stretched when the hardware is displayed. To successfully display a coverage surface, you may need to adjust the source, the size of the destination rectangle, whether this process is necessary to deserve the limitations of the device driver. B, Boundary and Size Alignment Due to different hardware restrictions, some device drivers are constrained for the size and location of the source rectangle and the destination rectangle of the cover surface. To find out the constraints of the device application, call the IDirectDraw2 :: getCaps method, then check the flag of the DDCaps structure that covered the related DWCaps. The subscript lists the members and signs of the specified boundary and size adjustment constraints. Category Sign Member Boundary Constrained DDCAPS_ALIGNBOUNDARYSRCDWALIGNBOUNDARYSRC
DDCAPS_ALIGNBOUNDARYDESTDWALIGNBOUNDARYDEST Size Constrained DDCAPS_ALIGNSIZESRCDWALIGNSIZESRC
DDCAPS_ALIGNSIZEDESTDWALIGNSIZEDEST
There are two, boundary constraints, and size constraints. Both constraints are represented by pixels, and can be used for source rectles and destination rectangles. Of course, these constraints can be different due to the different surface and the pixel format of the main surface. The boundary constraint affects the position of the source rectangle and the rectangular rectangle. The value of DwalignBoundarySRC and DwalignBoundaryDest members tells you how to adjust the upper left corner of the related rectangle. The X coordinate in the upper left corner of the rectangle (the LEFT member in the RECT structure) must be an integer multiple of the reported values. The size constraint affects the effective width of the source rectangle and the rectangular rectangle. The value of DwalignSizesRC and DwalIgnsizedest members indicate how to adjust the width of the correlation rectangle in pixel format. If the rectangular tensile rectangle is drawn according to a minimum tensile factor, it should be ensured that the rectangle after the stretch is still adjusted. After the tensile rectangle, the width can be maintained by adjusting the width upwards, and the minimum tensile factor can be maintained. C, MINIMUM AND MAXIMUM Stretch Factors, due to hardware limitations, some devices limits the comparison of destination rectangular rectangular widths. DirectDraw uses these constraints as tensile factors. A tensile fact is the ratio between the source rectangular rectangles. If the driver provides information about the stretch factor, it will set the DDCaps_Overlaystretch flag in the DDCAPS structure when calling the IDirectDraw2 :: getCaps method. Note that all tensile factors have been multiplied by 1000, so the tensile factor having a value of 1300 is actually 1.3. The maximum minimum tensile factor reported by non-compression and stretching covered rectangular devices is usually 0. The minimum tensile factor indicates how much or narrower in the rectangular rectangular rectangle. If the minimum tensile factor is greater than 1000, the width of the objective rectangle must be increased. For example, if the stretching factor is 1300, the width of the destination rectangle should be at least 1.3 times that of the source rectangular width. If the tensile factor is less than 1000, the destination rectangle is smaller than the width of the source rectangle. The maximum tensile factor is the maximum multiple of the destination rectangle to stretch. For example, if the maximum tensile factor is 2000, the width of the destination rectangle can be 2 times the source rectangular width. If the maximum tensile factor is less than 1000, the destination rectangle needs to be compressed. After stretching, the destination rectangle must comply with any size adjustment constraints required by the device. Therefore, it is finally stretched with the rectangle before the size is adjusted. Hardware does not require adjustment of the height of the destination rectangle. You can increase the height of the rectangle to keep the direction ratio. D, the COLOR Key is covered like other types of surfaces, and the cover surface also uses the source, the destination color key to control the transparent bit block transmission operation between the surface. Because the display of the cover is not completed by the bit block, you need to take different ways to display different methods when calling the IDIRECTDRAWSURFACE3 :: UpdateOverlay method. The answer is to override the Color Key. Symphoto block Transmission Related Color Key Similarly, override the Color Key also has the source color key and the purpose of the purpose, can set the source Color Key and the destination color key with the DDCKEY_DESTOVERLAY flag by calling method iDirectdrawsurface3 :: setColorKey. The overlay surface can combine bit block transmission and override Color Key to control bit block transmission operations and override display operations, and two different types of Color Key do not conflict with each other. IdirectDrawSurface3 :: Updateoverlay method Source Color Key Check which pixel in the overlay surface should be transparent, allowing the main surface to be displayed through the overlay surface. Similarly, the method uses the purpose to override the Color Key to determine which part allows which part allows the overlay surface to be overwritten, and its display effect is the same as the same bit block.
E. Positioning overlay surface (positioning overlay Surfaces) When you call the idirectdrawsurface3 :: updateOverlay method, you can use Method IDireTDrawSurface3 :: SetoverLayPosition to update the destination rectangle. You must ensure that the location of the destination of the destination is complied with the boundary alignment, the idirectdraw2 :: setoverLayPosition method does not perform clipping work, using the coordinates that may cause overwriting offline failure, and return DDERR_INVALIDPOSITION. f. Creating a Creating Overlay Surfaces like all surfaces, you can call the IDirectDraw2 :: CreateSurface method to create a cover surface. Creating a coverage surface also requires the DDSCAPS_OVERLAY flag in the related structure DDSCAPS. Covering a number of display devices, therefore cannot determine if a given pixel format is supported by most drivers, must be prepared to make it work in a variety of pixel formats. You can call the IDirectdraw2 :: getFourcccodes method to get the driver supported information about non-RGB formats. To create an overlay surface, it is best to use the most commonly used pixel format, if the given pixel format is not supported, DirectDRAW uses the other pixel format supported by the display device. Creating a coverage surface flip chain is also allowed. g, Flipping Overlay Surfaces, like other types of surfaces, you can create overwritten surface flip chains. Once you have created a flipped chain, you can call Method IdirectDrawSurface3 :: flip to flip these overwritten. Software decompression can use DDFLIP_ODD and DDFLIP_EVEN flags to reduce sports artifacts when calling the FLIP method to display the coverage surface. If the driver supports 奇 奇 奇, after obtaining the drive, the DDCaps2_canflipodDeven flag will be set in the DDCAPS structure. Once DDCAPS2_CANFLIPODDEVEN is set, you can include the DDOVER_BOB flag to notify the driver using the "Bob" algorithm to minimize the sport art. Thereafter, when FLIP is called with DDFLIP_ODD or DDFLIP_EVEN flags, the driver will automatically adjust the overworked source rectangle to make up for jitter. If the DDCAPS2_CANFLIPODDEVEN flag is not set up after obtaining the hardware, the DDOVER_BOB flag is used when calling UpdateOverlay, then the call will fail.
5, the palette (PALETTE) toning surface requires a palette to display it correctly. A toning surface (both color index) is a simple set of numbers, each of which is characterized by a pixel. The value of the number is an index of a color table, which tells DirectDraw to display what color when each pixel is used. The DirectDrawPalette object is often referred to as a palette that provides a simple way to manage color tables. The palette is not used using a 16-bit or higher pixel format. The DirectDrawPalette object characterizes an index color table for a color index surface with 2, 4, 16 or 256 entities. Each entity in the palette is a RGB ternary group, which describes the color used in the display surface. Color tables can include 16-bit and 24-bit RGB ternary groups to characterize the color used. For a 16-color palette, the color table can also contain an index of another 256-color palette. The palette can be applied to textures, exterior surfaces, and coverage surfaces, they do not require the same palette as the main surface. You can call the iDirectdraw2 :: createPalette method to create a palette that acquires the pointer of the IDirectdrawPalette interface of the palette object. Then, the method of the interface can then be used to process the entity of the palette, and obtain information or initialization objects related to the ability of the object (if the palette is created with the COM function CoCreateInstance). Call the idirectdrawsurface3 :: setPalette method to attach a palette on a surface. A single palette can be applied to multiple surfaces. The DirectDrawPalette object retains entities 0 and entities 255 to 8-bit palette, unless you specify that DDPCAPS_ALLOW256 flags are available for both entities available. You can get a palette entity with the idirectdrawpalette :: getEntries method, modify the palette entity with the IDirectDrawpalette :: STENTRIES method. 5.1, palette type DirectDraw supports 1 bit, 2-bit, 4-bit, and 8-bit palette. A palette can only be attached to a surface with the same pixel format. For example, a 2 entity palette created by the DDPCAPS_1bit flag can only be attached to the 1-bit surface created with the DDPF_PALETTEINDEXED1 flag. Alternatively, you can create a palette that does not contain color tables, ie the index palette. Different from the color table, the index palette contains an index value, which is characterized by another palette color table. To create an index palette, call the idirectdraw2 :: createpalette method, specify the DDPCAPS_8BITENTRIES logo. For example, to create a 4-bit palette, you also need to specify DDPCAPS_4BIT and DDPCAPS_8BITENTRIES flags. When you create an index palette, pass a pointer to the byte array. 5.2. Setting the setting palette on the non-main surface (SETTING) palette can be attached to any toning surface (main surface, background buffer, exterior surface and texture map), but only attached The palette on the main surface can affect the system palette. It must be noted that the DirectDRAW bit block transmission does not perform a color transform operation, and any source surface and destination surface attached to the bit block are ignored. The palettes on the non-main surface are mainly used for Direct3D applications. 5.3, Sharing Palettes palette can be shared between multiple surfaces. The same palette can be attached to a forward buffer and background buffer, or a plurality of texture surfaces.
When using the idirectdrawsurface3 :: setPalette method, the surface increases the index value of the palette when the index value of the surface reaches 0, which reduces the palette attached. The index value. In addition, if a palette is separated from the same surface, the index value of the palette of the surface is also reduced. 5.4, Palette Animation Moving Panel Animation refers to the process of changing the appearance of the surface by changing the surface of the surface by changing the surface of the surface. Repeat the palette again, the surface looks like a change, but in fact, the true content of the surface has no change. Therefore, the palette animation provides a method of changing the display performance of the surface without changing the specific content of the surface. Two methods can be provided for linear palette animations: i. Modify the palette entity II in a single palette. Switching between multiple palettes, you can change the tumble The entities of those related colors are called in the board, then call the IDirectDrawpalette :: setEntries method to reset these entities at a time. The second method requires 2 or more DirectDrawPalette objects, and then calls the iDirectdrawSurface3 :: setPalette method to attach a palette object to the surface object to generate an animation. Both methods are independent of hardware, so which way to use is mainly to see if the application is suitable.
6, the clipper (Clipper) or the DirectDrawClipper object allows the bit block to be transmitted to the selected part of the surface. A clipboard object pulls a list of one or more clipboards in the sea. A list of clipboards is a bounded rectangular or several bounded rectangular columns, which is a piece of block or several areas that allow bit blocks to be transferred in the surface. These areas are represented by the Rect structure in a screen coordinate. The clip list is a very useful tool, which is the most commonly used to prohibit the application to write data blocks to places that are outside the screen. For example, if you want to display a wizard from the screen boundary, you don't want the elf to pop up, and slowly move slowly from the screen border to the center of the screen. If there is no clipboard object, you need to include the logic that restrict bit block operations to protect surface memory. The following figure shows the shear of this class. You can use the shear board object to be a certain area of a destination rectangle, and DirectDRAW will transfers the bit block to the bit block to protect the specified pixels other than the specified shear rectangle. This cutting method is shown below: 6.1, Clip List DirectDraw uses DirectDrawClipper objects to manage the clip list. A clip-cut list is a series of rectangles that describe the surface visible area. A DirectDrawClipper object can be attached to any surface. One window handle can also be attached to the DirectDrawClipper object. In this case, DirectDraw will use the clip list updated in the window to modify the DirectDrawClipper clippers. Although the clipping list in DirectDraw Hal is visible, DirectDraw also calls HAL only when using rectangular bit blocks to meet the clip list requirements. For example, if the upper left corner rectangle of a surface is cut off, when the application writes the surface block to the main surface, DirectDRAW will use HAL to perform two bit block transmission operations, the first time, the upper left corner of the transmission surface, The second operation is the lower half of the transmission surface. This clipped list can be transferred to the driver (if the driver supports cut), instead of calling the driver if the driver supports shearing. In addition, you can call the idirectdrawclipper :: sethwnd method to a single window by the handle of the specified window. The cover surface supports the shear feature only when the cover hardware supports shear or the destination Color Key is not activated. 6.1, Sharing DirectDrawclipper object DirectDrawClipper objects can be shared between multiple surfaces. For example, the same DirectDrawClipper object can be used at the same time and the front desk and background buffers of the chain. When the application uses the IDirectdrawSurface3 :: setClipper method to attach a DirectDrawClipper object at a surface, the secondary surface adds the index value of the object. If a DirectDrawClipper object is the same surface (this surface is created with the idirectdrawsurface3 :: setClipper method) separated by an empty shear board interface pointer, the index value of the DirectDrawclipper object will be reduced. 6.3, stand-alone clipboard object You can create a DirectDrawClipper object that is not directly from any DirectDraw object. This clipboard object can be shared between multiple DirectDRAW objects. The driver independent clipboard object can be created with a new DirectDraw function DirectDrawCreateClipper, which calls the function before creating any DirectDRAW object. Because the DirectDRAW object cannot own these independent DirectDrawClipper objects, these DirectDrawClipper objects are not automatically released when the objects in the app are released.
If the application does not explicitly release these clipboard objects, DirectDraw will release them at the end of the program. Of course, you can also create a DirectDrawClipper object with the IDirectDraw2 :: CreateClipper method, which is automatically released with the clipboard object created with this method. 6.4, Create a DirectDrawClipper object with a COM function The DirectDrawClipper object fully supports COM applications. In addition to using standard IDirectDraw2 :: CreateClipper methods, you can create a clipboard object with a COM function COGETCLASSOBJECT. The following is an example of creating clipboard object with CoCreateInstance function and IDirectDrawClipper :: Initialize method: ddrval = CoCreateInstance (& CLSID_DirectDrawClipper, NULL, CLSCTX_ALL, & IID_IDirectDrawClipper, & lpClipper); if ddrval = IDirectDrawClipper_Initialize (lpClipper, lpDD, (FAILED (ddrval)!) 0UL); In the call to COCREATEINSTANCE, the first parameter CLSID_DIRECTDRAWCLIPPER is a class flag of the shear board object class, and the IID_IDIRECTDRAWClipper parameter indicates the currently supported interface, and the LPClipper parameter is a pointer to the shear board. The application must have to use the iDirectdrawclipper :: initialize method to initialize the shearing board object, 0UL is the value of the dwflags parameter, in this example, there is no sign without any flag. LPDD is a DirectDraw object with the clipboard object; if you replace LPDD with null, you will create a separate DirectDrawClipper object, which will also be equivalent to the clipboard object created with the DirectDrawCreateclipper function. Before shutting down the application, you should use the CounInitialize function to close COM. DirectDraw usually provides users with a method of booting using a mouse. For applications for full-screen exclusions using the page flip, the only option is to manually implement the cursor of the mouse in a wizard, relying on the mouse message from DirectInput from the data or window acquired from the device or window to move the wizard. Any application that does not use the page flip can also use the system's mouse cursor support. When using the system's mouse cursor, image artifacts may appear when the block is part of the main surface. In the bit block transmission operation, the shearing plate object prevents the appearance of these artifacts. In the application, first create a clipboard object with the idirectdraw2 :: createclipper method, and then assign the handle of the app to the clipboard with the idirectdrawclipper :: sethwnd method. Once the shear plate is attached, the operation of the bit block transmitted by the iDirectdrawsurface3 :: bLT method will not appear. You can write a clipboard object block to multiple windows. First create a DirectDraw object with only one main surface, then create a clipboard object, and use the idirectdrawsurface3 :: setClipper method to assign the shear board object to the main surface. To write to the client area of the window, you need to use the idirectdrawclipper :: sethwnd method to write the clipboard to the window of the window with the idirectdrawclipper :: sethwnd method before the block is written to the main surface. If you need a block to write to another window, use the handle of the target window to call the idirectdrawclipper :: sethwnd method once.
Fourth, DirectDRAW Advanced Features 1, Direct Memory Access DMA Some Display Devices can support bit block transfer operations (or other operations) in the system memory surface, which is direct memory access DMA (Direct Memory Access). You can use DMA support to accelerate a certain action. For example, in this device you can transfer from the system memory block to the video memory, and the processor is also ready to process the next frame. Before using the DMA operation, it is necessary to detect whether the device supports DMA and support. The step is to get the ability to get the device with the iDirectdraw2 :: getCaps method, then view the DWCAPS member in the DDCAPS structure contains the DDCaps_canbltsysmem flag, if it indicates that the device supports DMA. If the device supports DMA, you need to know how the driver is supported. This needs to view the relevant structural members, which contain information about the system memory - video memory, video memory - system memory and system memory - system memory. Several members DDCAPS structure provides the information, as shown below: System-to-videoVideo-to-systemSystem-to-system dwSVBCaps dwVSBCaps dwSSBCaps dwSVBCKeyCaps dwVSBCKeyCaps dwSSBCKeyCaps dwSVBFXCaps dwVSBFXCaps dwSSBFXCaps dwSVBRops dwVSBRops dwSSBRops
For example, the performance flag of bit block transmission of the system memory to video memory is provided by DWSVBCAPS, DWSVBCKEYCAPS, DWSVBFXCAPS, and DWSVBROPS. The bit block transmission performance flag of the video memory to the system memory is included in a member starting with the "DWVSB", and the bit block transfer performance flag between the system memory is included in a member starting with the "DWSSB". The most critical characteristics of these members are support for transmission operations for asynchronous DMA bit blocks. If the driver supports the asynchronous DMA bit block transfer operation between the surface, the DDCaps_bltqueue flag will be located in DWSVBCAPS, DWVSBCAPS, and DWSSBCAPS members. If the flag does not exist, it indicates that the driver does not support asynchronous DMA bit block transfer operations. SRCPY transmission between the system memory to video memory is the most common bit block transmission operation supported by hardware. Therefore, the most typical application of this operation is to move many textures to video memory from the system surface memory. The DMA transfer of the system memory to video memory is approximately as fast as the processor control, but has a greater advantage because these operations can run parallel with the host processor. Hardware transfer uses physical memory addresses instead of virtual memory addresses, some device drivers require physical memory. This mechanism is done by calling the idirectdrawsurface3 :: panel method. If the device driver does not require a page lock, the DDCAPS2_nopageLockRequired flag will be set when the hardware is obtained with the iDirectdraw2 :: getCaps method. Page locking a surface prevents the system from doing the physical memory of the surface and keeps the physical memory of the surface unchanged until the IDirectdrawSurface3 :: PageUnlock method is called. If the device driver request page is locked, DirectDraw only allows the DMA to operate on the system memory surface that is already locked. If you don't call IDirectdrawSurface3 :: PageLock, DirectDraw will perform transfer work with software simulation. It should be noted that the locking surface will greatly reduce the efficiency of Windows operation. Therefore, it is preferable to handle more quantity of system memory only in full-screen exclusive mode, and can unlock these surfaces when the application minimizes. Of course, after the application is restored, the system memory surface page should be re-locked.
2. When using the DirectDraw palette in window mode, the iDirectdrawpalette interface method is directly written to the hardware. When the window mode is displayed, the iDirectdrawpalette interface method will call the GDI palette processing function to make it harmonically with other Windows applications. 2.1, window mode The type of palette entity is different from full-screen exclusive applications, and the window mode of the window must share the desktop palette with other applications. The PaletteEntry structure used to work with DirectDrawPalette objects and GDI contains a PEFLAGS member that contains information about how the system explains the PaletteEntry structure. Members of Peflags describe three types of palette entities. 2.1.1 Windows Static entity In standard mode, Windows reserves palette entities 0 ~ 9 and entities 246 ~ 255 for system color, display menu strips, menu text, and window boundaries. In order to keep the application consistent appearance, avoid damage to other applications, you need to protect these entities that are set to the palette of the main surface. Typically, the programmer can call the Win32 function getSystemPaletteEntries to get the system palette, and then explicitly set the same palette in the custom palette to match the system palette in front of the main table. Although the system palette entity is copied to the custom palette in the custom palette, it can work in the first place, but when the user changes the color of the desktop color, the custom palette will become invalid. In order to avoid the user's ability to change the color color color, you can provide an index of a system palette to replace the specified color value to protect the appropriate entity. With this method, the palette will always match whether the system is used, and the palette will always match and do not need to do any updates. The PC_EXPLICIT logo for PEFLAGS members allows you to directly index to a system palette entity. After using this flag, the system will no longer think that other members of the structure contain color information. You can set the value of the PERED member to the required system palette index to set all the colors to 0. For example, if you want to guarantee the appropriate entity in your palette, you can always match the system palette color matching, you can use the following code: // set the first and last 10 Entries to match the system palette.paletteentry PE [256 ]; ZeromeMory (PE, SIZEOF (PE)); for (int i = 0; i <10; i ) {PE [i] .peflags = pe [i 246] .peflags = pc_explicit; pe [i] .pled = I; PE [i 246] .pled = i 246;} You can call Win32 function setsystempaletteuse to force Windows only use the first and last palette entities 0 and 255. In this case, only entities 0 and 255 should be set to PC_ExPlicit in the PaletteEntry structure. 2.1.2, ANIMATED Entries You can use the PC_RESERVED flag in the PaletteEntry structure to specify that the motion is a palette entity. Windows does not allow other applications to map its own logical palette entities to your specified physical palette entity, avoiding other applications to change their color when moving palettes in your application. 2.1.3 Non-sports entities You can use the PC_nocollapse flag in the PaletteEntry structure to specify a non-motion palette entity. The PC_NOCOLLAPSE flag notifies that Windows does not have to replace the non-sports entity without the assigned palette entity.
2.2, create a palette under window mode is an example of creating a DirectDraw palette in non-exclusive window mode. In order to make the palette work normally, 256 entities are set in the PaletteEntry structure submitted to the IDiretDraw2 :: CreatePalette method.
LPDIRECTDRAW lpDD; // Assumed to be initialized previously PALETTEENTRY pPaletteEntry [256]; int index; HRESULT ddrval; LPDIRECTDRAWPALETTE lpDDPal; // First set up the Windows static entries for (index = 0; index <10; index ). {// The first 10 static entries: pPaletteEntry [index] .peFlags = PC_EXPLICIT; pPaletteEntry [index] .peRed = index; pPaletteEntry [index] .peGreen = 0; pPaletteEntry [index] .peBlue = 0; // The last 10 static entries: pPaletteEntry [index 246] .peFlags = PC_EXPLICIT; pPaletteEntry [index 246] .peRed = index 246; pPaletteEntry [index 246] .peGreen = 0; pPaletteEntry [index 246] .peBlue = 0;} // Now . set up private entries In this example, the first 16 // available entries are animated for (index = 10; index <26; index ) {pPaletteEntry [index] .peFlags = PC_NOCOLLAPSE | PC_RESERVED;. pPaletteEntry [index]. Pred = 255; pPaletteentry [index] .pegreen = 64; ppaletteentry [index] .peb Lue = 32;} // NOW SET UP THE REST, THE NONANIMATED Entries. for (Index <246; Index ) // Index IS set up by previous for loop {ppaletteentry [index] .peflags = pc_nocollapse; ppaletteentry index] .peRed = 25; pPaletteEntry [index] .peGreen = 6; pPaletteEntry [index] .peBlue = 63;..} // All 256 entries are filled Create the palette ddrval = lpDD-> CreatePalette (DDPCAPS_8BIT, pPaletteEntry, & lpDDPal , NULL); 2.3, window mode Setting the palette entity for the IdirectDraw2 :: CREATEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTEENTTEENTTEENTTEENTTEENTTTE :: STENTRIES method. Therefore, you can maintain the PaletteEntry group without reconstructing it.
When needed, change the structure group and call the IDirectDrawPalette :: setNtries method. In most environments, when you are in window mode, don't try to set any window static entities, otherwise you will appear unpredictable results. The window still entity is allowed only when resetting the entity. For the palette animation, you only need to change very little part of the entity in the PaletteEntry group, submit these entities to the IDirectDrawpalette :: setEntries method. If you want to perform a reset operation, you can only reset the entities that are marked with the PC_NOCOLLLAPSE flag and the PC_RESERVED logo. Attempting to move other entities will bring unpredictable errors. Examples of the palette animation in the following non-exclusive mode: LPDIRECTDRAW lpDD; // Already initialized PALETTEENTRY pPaletteEntry [256]; // Already initialized LPDIRECTDRAWPALETTE lpDDPal; // Already initialized int index; HRESULT ddrval; PALETTEENTRY temp; // Animate . some entries Cycle the first 16 available entries // They were already animated temp = pPaletteEntry [10];.. for (index = 10; index <25; index ) {pPaletteEntry [index] = pPaletteEntry [index 1] PPALETTEENTRY [25] = Temp; // set the values. do not pass a pointer to the entire patrie entry /// structrue, but only to the change Entries. DDRVAL = LPDDPAL-> setEntries (0, // Flags Must BE Zero 10, // First Entry 16, // Number of Entries & (PPALETTEENTRY [10])); // Where to get the data 3, Multi-Display System Windows 98 (Memphis) and Windows NT support multiple systems Display devices and displays. Multi-display system (commonly referred to as "multimon" enables operating systems to use two or more display devices and displays to create a single logical desktop. For example, in a Multimon system with two displays, users can display applications on one of the displays, and can also drag and drop the window from one display to another display. DirectDraw supports this architecture. A DirectDRAW application is capable of listing hardware devices, selecting a device, then using the GUID of the device to create a DirectDRAW object for the device. This technology ensures that the best performance performance can be achieved regardless of the Multimon system or in a single display system. The current active display device is considered "default device", or "null device" (null device "because the currently active display device is null as its GUID as it is listed.
Many applications can create a DirectDraw object for "empty devices", assuming that the device is hardware acceleration. However, in the Multimon system, "empty equipment" does not always accelerate hardware, depending on the collaboration level used at the time. In full-screen exclusive mode, "empty equipment" is hardware acceleration, but the system does not know other installed devices. This means that the full-screen exclusive mode is running as fast as the speed of the Multimon system is as fast as running on other systems, but cannot use the embedded support for image operations that span image operations across the display device. An application that requires full-screen exclusive mode of multiple devices can create a DirectDRAW object for each device to use. Note that the DirectDraw object is created for the specified device, and you must provide the GUID of the object. When you call the DirectDrawenumeRate method, you can list the GUID of each device. When the standard collaboration level is set, the "empty device" does not have hardware acceleration capabilities. In fact, it simulates the resources of the two physical devices to simulate a logical device. On the other hand, the "empty device" automatically has graphical operational capabilities across the display. Therefore, when the logical position of the second display is in the left side of the main display, the negative coordinate value is legal. If the application requires the hardware acceleration function after setting the standard collaboration level, it must create a single DirectDraw object using the GUID of the specified device. If you don't use "empty devices", you cannot get image operation capabilities across the display device. That is, the bit block transmission operation across the main surface boundary will be cut (if a shear plate) or failure (returns Dderr_INVALIDRECT). Regardless of which system, the collaboration level should be set immediately after obtaining the DirectDRAW object before being queried by other interfaces, and avoid setting a collaboration level multiple times in the Multimon system. If you need to switch from full screen mode to standard mode, you'd better create new DirectDraw objects, not to use old DirectDraw objects.
4, Video Ports DirectDraw video port extension is a low-level programming interface, which is not used for current system multimedia programming. The object of the video port interface is a video software company, such as a company developing DirectShow. Programmers who want to use video technology in their own software can also use video port extensions. However, the advanced programming interfaces provided in many software are sufficient to meet the needs. The DirectDrawVideoPort object is characterized by the video port hardware installed in some computer systems. In general, the video port object controls how video port hardware applies directly to the video signal from the video decoder to the frame buffer. You can create multiple DirectDrawVideoPort objects to control multiple video channels as needed. Because each channel can be listed and configured, video hardware does not need to be completely identical to each channel. Video port hardware can access the surface directly in the frame buffer, and bypass the CPU and PCI bus. Direct access to the frame buffer allows you to effectively play active video and recording a video without loading in the CPU. Once there is a surface existing, the image can be displayed on the screen, which can be used for Direct3D texture, intercept access and other processing of the CPU. In a computer equipped with a video port device, the data in the video stream can directly flow from the video decoder and the video port to the frame buffer. These components typically connect together with the display adapter, or as separate hardware interconnects. The following figure gives the process of data stream: What is the video source? In the video port technology, strict, the video source is a Video INPUT device, such as Zoom video port, MPEG encoder, etc. These hardware sources will be sent to the physical connection of the video decoder by connecting the signal in different formats (including NTSC, PAL, and SECAM). Video decoder (Viceo decoder) is another hardware component. It works is to translate the information provided by the video source and send it to the video port with the connection format followed. The decoder keeps the physical connection with the video port, which is also responsible for sending video data, hourglass information, and synchronization information to the video port. Video port is also a set of hardware. It exists on the VGA chip that displays the adapter, with the ability to directly access the frame buffer. It handles information from the decoder and placed in the frame buffer for display. During the processing of data, the video port can operate image data to provide proportional changes, stretch compression, color control, and shear. Frame Buffer Accepts video data provided by the video port, and then processes these image data with programmed methods, transfer their bit blocks to other locations or use overrides to display them on the screen. The virtual DirectDraw video port extension is a DirectDrawVideoPort object that provides video services using video port technology via IDDVIDEOPORTCONTAINER and IDIRECTDRAWVIDEOPORT interface. The DirectDrawVideoPort object does not control the video decoder and can only provide your own service. DirectDraw also cannot control video sources because the video source has exceeded the range of video ports. The DirectDrawVideoPort object is just characterized by the video port itself. It uses the parameters set by the interface method to send the input signal and the image data to the frame buffer to perform flip or other processing. The IDDVIDEOPORTCONTAINER interface (obtained with iDirectdraw2 :: queryinterface) provides the ability to query hardware to create a video port object. You can create a video port object with the IDDVIDEOPORTCONTAINER :: CreateVideoPort method, which shows its feature via the iDirectDrawVideoPort interface.
With these interfaces, you can check the ability of the video port, allocate override surfaces to receive image data, start and stop video playback, set hardware parameters to process image data to generate cut, color conversion, scale zoom, and stretching compression. The DirectDraw video port extension supports multiple video ports on the same computer, allowing you to create multiple video port objects.
5. Get flipping and bit block transmission status We already know that after calling the IDirectdrawSurface3 :: Flip method, the main surface and the background buffer will exchange each other. But the action of the exchange is not immediately happening immediately. For example, if the previous flip task is not completed, the method returns DDERR_WASSTILLDRAWING, and DirectDraw continues to call iDirectdrawsurface3 :: flip until DD_OK. If the application is in a waiting state before calling the idirectdrawsurface3 :: flip method, the efficiency of the program will be very low. Instead, you can create a function to call the idirectdrawsurface3 :: getFlipStatus method in the background buffer to detect if the previous flip work is completed. If not completed, return or DDERR_WASSTILLDRAWING, the application can perform other tasks within a period of time between the state. Here is an example of this idea:. While (lpDDSBack-> GetFlipStatus (DDGFS_ISFLIPDONE) == DDERR_WASSTILLDRAWING); // Waiting for the previous flip to finish The application can // perform another task here ddrval = lpDDSPrimary-> Flip (NULL. , 0); You can also call IDirectDrawsurface3 :: getBltstatus with the same method to detect whether the primary block transfer is completed. Because IdirectdrawSurface3 :: getflipstatus and idirectdrawsurface3 :: getBltstatus can return to the current status currently in the application, so you can use them in the program without too much influence running speed. The work that performs color fill needs to call the idirectdrawsurface3 :: blt method. For example, if the most often displayed color is blue, you can call the idirectdrawsurface3 :: bLT method in a blue, use the DDBLT_COLORFILL flag first filled the surface, and then write other objects to the top. This method allows you to fill the most common colors very quickly, then just write a small number of colors to the surface. The following is an example of performing color fill: DDBLTFX ddbltfx; ddbltfx.dwSize = sizeof (ddbltfx); ddbltfx.dwFillColor = 0; ddrval = lpDDSPrimary-> Blt (NULL, // Destination NULL, NULL, // Source rectangle DDBLT_COLORFILL, & ddbltfx) Switch (DDRVAL) {CASE DDERR_WASSTILLDRAWING:.................................................... .. . In order to improve the execution speed of the DirectDRAW application, the ability to display the hardware should be detected immediately after creating the DirectDraw object, and then use the feature component program provided by the hardware as much as possible. You can detect hardware performance using the idirectdraw2 :: getcaps method.
Not all hardware features can be simulated with software. If you want to use a feature that is only supported by some hardware, it is best to do a system that you may not support this hardware, that is, if the hardware does not support this hardware solution. 7. In display memory, the bitmap is typically, from the display memory to the bit block transmission between the display memory is high, the bit block transmitted between the display memory is high. Therefore, it is preferred to store the wizard bitmap that will be used as much as possible in the display memory. Most display adapters contain sufficient additional memory to store more than one main surface and background buffer. You can use DWVIDMEMTAAL and DWVIDMEMFree members in the DDCAPS structure to detect how much memory can be used to store bitmaps in memory. The DirectX Viewer sample program included in the DirectX SDK gives this process.
8, Triple Buffering In some cases, display the adapter may have more display memory, which may use three cushions to increase the display speed. Three buffers use a master surface and two back buffers. The following is an example of initializing a three buffer: // The LPDDSPRIMARY, LPDDSMIDDLE, AND LPDDSBACK Are Globally // Declared, Uninitialized LPDirectdrawSurface Variables.
DDSurfaceDesc Ddsd; ZeromeMory (& DDSD, SIZEOF (DDSD));
// Create the primary surface with two back buffers ddsd.dwSize = sizeof (ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;. Ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; ddsd.dwBackBufferCount = 2; ddrval = lpDD- > CreateSurface (& DDSD, & LPDDSPRIMARY, NULL);
// If we successfully created the flipping chain, // retrieve pointers to the surfaces we need for // flipping and blitting.if (ddrval == DD_OK) {// Get the surface directly attached to the primary (the back buffer). ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER; ddrval = lpDDSPrimary-> GetAttachedSurface (& ddsd.ddsCaps, & lpDDSMiddle); if (! ddrval = DD_OK);. // Display an error message here} you need to keep all three buffer flip chain surface The trajectory only needs to keep the main surface and the pointer of the background buffer surface. The main surface pointer is used to flip the main surface in the flip chain, and the background buffer pointer is used for bit block transmission. The three buffer allows the application continuation bit block to be transferred to the background buffer, as long as the last bit block transmission of the background buffer has been completed, even if the flip is not completed. Execution flip is not a synchronous event, and once the flip may be longer than the other flip. Therefore, if only one background buffer is used, the program may consume a waiting state before the iDirectdrawsurface3 :: flip method returns DD_OK.
9. DirectDRAW Applications and Window Style If the application uses DirectDraw in window mode, you can use any style to create a window. The appearance of full screen exclusation cannot be created with a WS_EX_TOOLWINDOW style, which should be used with the WS_EX_TOPMOST extension window style and WS_Visible window style to ensure that the image is correctly displayed. These two styles can keep the application at the front end of the window z direction, avoiding GDI to the main surface. The following example shows how to make exclusive full-screen mode applications: // register the window, and init all directx and graphic objects.bool winApi initApp (int nwinmode) {Wcex.cbsize = sizeof (WNDCLASSEX); wcex.hInstance = g_hinst; wcex.lpszClassName = g_szWinName; wcex.lpfnWndProc = WndProc; wcex.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS; wcex.hIcon = LoadIcon (NULL, IDI_APPLICATION); wcex.hIconSm = LoadIcon ( NULL, IDI_WINLOGO); wcex.hCursor = LoadCursor (NULL, IDC_ARROW); wcex.lpszMenuName = MAKEINTRESOURCE (IDR_APPMENU); wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hbrBackground = GetStockObject (NULL_BRUSH);
RegisterClassex (& WCEX);
G_hWndmain = CREATEWINDOWEX (WS_EX_TOPMOST, G_SZWINNAME, G_SZWINCAPTION, WS_Visible | WS_POPUP, 0, 0, CX_SCREEN, CY_SCREEN, NULL, NULL, G_HINST, NULL);
IF (! g_hwndmain) return (false);
Setfocus (g_hwndmain); showwindow (g_hwndmain, nwinmode); UpdateWindow (g_hwndmain);
Return True;}