DIRCETDRAW CC ++ Guidance (3)

zhaozj2021-02-08  209

DIRCETDRAW C / C instructions

310CDT translation

I am in the routine of these guidance.

DDEX1 DDEX2 DDEX3TUTORIAL3: Block Mobile (BLT) from an Off-screen Surface

In DDEX2, put a bitmap in the background cache, then turn on the cache and the main plane ... In fact, this is not a general behavior of the bitmap. In this article (example is DDEX3) will pass Contains two remote surfaces to extend DDEX2 capabilities. Two bitmaps - one is the second quarrel display, one is an odd display - stored in these two off-screen surfaces. Example, use iDirectdrawsurface7 :: bltfast method Copy the contents of the slave surface to the background cache, then turn it, then copy the next left surface surface to the cache ... (Translator Note: This article is just a way to display the surface and blit, in fact, Most of the screen is used to store the elves, realize animation. It is a small picture that is stored. It is a special plane) DDEX3 new function: Step1: Create away STEP2 : Load bitmap to the remote surface Step3: Block Mobile (Blit) away from the screen to the background buffer

step1: establishment of the panel from the surface of the underlying code is added to doInit function creates two offscreen surfaces .// Create an off-screen bitmap ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd. .dwHeight = 480; ddsd.dwWidth = 640; ddrval = lpDD-> CreateSurface (& ddsd, & lpDDSOne, NULL); if (ddrval = DD_OK!) {return initFail (hwnd);}. // Create another off-screen bitmap ddrval = LPDD-> CreateSurface (& DDSD, & LPDDSTWO, NULL); if (DDRVAL! = DD_OK) {Return INITFAIL (HWND);} DWFLAGS member defines the program will use the DDSCAPS structure and will set the high and wide width of the surface surface. The surface is indicated in the DDSCAPS_OffScreen in the DDSCAPS structure, so it will be a completely off-screen cache. The high and width are set to 480 and 640 respectively. Subsequently, the surface is created by the IDirectDraw7 :: CreateSurface method. Because two slave surface size Similarly, different pointers were called idirectdraw7 :: createSurface again, and you can create another. You can decide to place the slap in the system memory or in the DDSCAPS_VIDEMEMORY in the DDSCAPS structure. Place in the memory You can speed up the moving speed of the slave surface to the background cache. This will be very important. However, if you use DDSCAPS_VIDEMEMORY and there is not enough video memory area to store the bitmap, when you try to When you create this surface, a DderR_OutofVideoMEMory error will be returned.

Step2: Load bitmap to the remote screen surface When the two off-screen surface is created, DDEX3 uses the INITSURFACE function to load the bitmap of the FRNTBACK.BMP file into the surface. InitSurface function uses the DDCopyBitmap function in the ddutil.cpp file. . follows to load the bitmap: // load the bitmap resource hbm = (HBITMAP) LoadImage (GetModuleHandle (NULL), szBitmap, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION); if (hbm == NULL) return FALSE; DDCopyBitmap (lpDDSOne , HBM, 0, 0, 640, 480); DDCopyBitmap (LPDDSTWO, HBM, 0, 480, 640, 480); deleteObject (HBM); return true; if you look at FRNTBACK.BMP files You know, this file includes two charts, one on the other of the.ddcopybitmap function divides this bitmap from the boundary. One is loaded into the first left surface (LPDDsone), another In the second off-screen surface (LPDDSTWO) .STEP3: Block Move (Blit) The code triggered by the back screen to the background buffer WM_TIMER message includes writing the surface and flip surface. In DDEX3, he contains the following code to choose the appropriate Off-screen surface, then move his block (blit) to the background cache.rcRect.LEFT = 0; rcRect.top = 0; rcRect.Right = 640; rcRect.bottom = 480; if (Phase) {PDDS = LPDDSTWO; Phase = 0;} else {pdds = lpddsone; Phase = 1;} while (1) {ddrval = LPDDSBACK-> BLTFAST (0, 0, PDDS, & RCRECT, FALSE); if (ddrval == dd_ok) {Break;} } The Phase variable determines which over-screen surface will be moved to the background cache .idirectdrawsurface7 :: Bltfast The call to the method is used to move the selected off-screen surface block to the background cache. Start at (0, 0), the upper left corner.recture parameter points to a RECT structure, he defines the left surface of the remote surface of the moving And the lower right corner. The last parameter is set to false (0), the label does not use a special transmission marker. According to your program, you can use the idirectdrawsurface7 :: blt or idirectdrawsurface7 :: bltfast method to implement block movement. If you The remote surface surface is in the memory, you'd better use the idirectdrawsurface7 :: bltfast method. Do this, if you use the hardware block mobile support, you won't get faster speed, but if you use hardware imitation Block movement, you will use less 10%. So you should use the idirectdrawsurface7 :: bltfast method to do all the block moves in the memory. If you move from the system memory, or require special hardware flags, then I have to use idirectdrawsurface7 :: blt. When the completed block moves from the slave surface to the background cache, the background cache is like the front of the main plane.

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

New Post(0)