DIRCETDRAW CC ++ Guidance (2)

zhaozj2021-02-08  262

DIRCETDRAW C / C Guidance (2)

310CDT translation

Tutorial2: In the cache medium loaded

This example discusses the expansion of DDEX1.DDEX2 (routine, search ...), explains the function that contains the setup file. The new feature is implemented by the following steps: Step1: Create color STEP2: Setting the palette Step3: In the cache medium loaded step map STEP4: Turning the plane. Like DDEX1, Ddex2 is initialized in the initialization function. Different code is as follows: LPDDPAL = DDLoadPalette (LPDD, SZBACKGROUND); if (lpDDPal == NULL) goto error; ddrval = lpDDSPrimary-> SetPalette (lpDDPal); if (ddrval = DD_OK!) goto error;. // Load a bitmap into the back buffer ddrval = DDReLoadBitmap (lpDDSBack, szBackground); if ( DDRVAL! = DD_OK) Goto Error;

Step1: Create a palette in DDEX2, first establish a palette with the following code .lpddpal = ddloadpalette (LPDD, SZBACKGROUND); if (lpddpal == null) goto error; DDLoadPalette this function is in / dxsdk / sdk / samples / Public DirectDraw functions in Misc / DDUTIL.CPP. Many DirectDraw examples (SDK packets) use this file. Important, it contains functions that load palette and bitmaps, whether from files or Resources. In order not to repeat the writing code, he put him in a file that can be reused. Confident, you are compiling DDEXN to include this file. (The following is in DDEX2, DDLoadPalette functions from back The .bmp file creates a DirectDrawPalette object.ddloadPalette function determines whether the file or resource created a palette exists. If not, create a default palette. In DDEX2, he extracts the palette information from the bitmap file and ape stored in a structure pointed .DDEx2 DirectDrawPalette subsequently created objects, as follows: pdd-> CreatePalette (DDPCAPS_8BIT, ape, & ddpal, NULL); return ddpal; IDirectDraw7 :: CreatePalette when the method returns, ddpal parameter points to return from the function DDLoadPalette The DirectDrawPalette object. The parameter is a pointer to a structure that can contain or 2 or 4 or 16 or 256 linear organizations. The number of records rely on DWFlags parameters in the CreatePalette method. In the above case, DWFLAGS parameters Set to DDPCAPS_8bit. This means that there are 256 records in the structure. Each record contains 4 bytes (the channels of red, green, blue, and a flag).

Step2: Setting the palette to create a palette, scrubbing the main plane by pointer, as follows: ddrval = lpddsprimary-> setPalette (LPDDPAL); if (DDRVAL! = DD_OK) Goto error; // setpalette Failed. After you call the iDirectdrawsurface7 :: setPalette method, the DirectDrawPalette object is linked to the DirectDrawSurface object. When you want to change the palette, you can simply create a new palette, then set it. (Although this guide uses these steps, there are other methods to change the palette, and will be demonstrated in the later examples)

step3: Loading object DirectDrawSurface DirectDrawPalette bitmap object buffer after linking, DDEx2 load the bitmap back.bmp // Load a bitmap into the back buffer ddrval = DDReLoadBitmap (lpDDSBack, szBackground with the following code in the cache. ); If (DDRVAL! = DD_OK) // load failed.ddreLoadBitmap is another function in ddutil.cpp. He loaded a bitmap file or resource to an existing DirectDraw plane. (You can also use DDLoadBitmap functions Create a flat and load. The function is also in ddutil.cpp.) In DDEX2, he loads the back.bmp file pointed to by SzBackground (ID) to the background cache pointing by LPDDSBACK. DDRELOADBITMAP function call DDCopyBitmap functions Copy the file to the cache and stretched to the appropriate size.ddcopyBitmap function copies the bitmap to the memory, recover the size of the bitmap with the getObject function. Then the bitmap is adjusted to the cache to be placed. Size .// Get the size = sizeof. Ddsd.dwsize = sizeof (ddsd); ddsd.dwflags = ddsd_height | DDSD_WIDTH; PDDS-> GetSurfaceDesc (& DDSD); DDSD is a pointer for a DDSurfaceDesc2 structure. This structure saves now Description of the DirectDraw plane. In this case, members of DDSurfaceDesc2 describe the high and wide of the plane, indicated by DDSD_HEIGHT and DDSD_WIDTH. EdirectDrawSurface7 :: GetSurfaceDestrura's call to put the attribute value into this structure. In Ddex2, The value will be set to a high 480, width 640.ddcopyBitmap function to the flat chamfer and copy the bitmap to the cache, stretch or compress with the StretchBLT function. As follows: IF (((hr = pdds-> getdc (& hdc)) = = DD_OK) {Stretchblt (HDC, 0, 0, DDSD.DWWIDTH, DDSD.DWHEIGHT, HDCIMAGE, X, Y , DX, DY, SRCCOPY; PDDS-> ReleaseDC (HDC);} STEP4: Turning page DDEX2 in the partial image of the flip page in Ddex1. The difference is: when the plane is lost (Dderr_Surfacelost), in the plane After storage, you must reload the bitmap with the DDRELOADBITMAP function.

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

New Post(0)