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

zhaozj2021-02-11  199

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.

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

New Post(0)