Two hours learning DirectDraw programming (reproduced)

zhaozj2021-02-16  63

Welcome to C Builder Research, http://www.ccrun.com/doc/go.asp? Id = 440 This is not a demopularity, usually two ways to learn a computer technology. One is my own exploration, in the wrong direction The last mistake was wrong, but the war was defeated, but the last success was successful. The other is some people or good material guidance, so it is half-mexual, and the shortcut is taken in the correct direction. Just like KFC's chicken. A learning method can learn computer genius, because the so-called computer master is actually a master of tankers. The second is the computer talents. This two-hour (?) Is learning, can't make you deeply master DD However, you can give you a framework of DD. You can give you a starting point. This tutorial is successful. DirectDraw programming requires some background knowledge: DirectDraw is a program library written to implement high-speed graphic display in Windows95 / NT. High-speed graphics The basic method of display is to use a technology called page flipping. About what is Page Flipping, see ancient skills. If you are not urgent, see below, you will also see. Under Windows95 / NT, do Page Flipping It is two kinds of full-screen and window. Page flipping under full screen is called blit, which is called blit. I know these background knowledge. We can start writing. Write all DirectDraw's programs, almost the following steps, 1. Initialization, this is a latz .2. Set the display mode .3. Two pages required for Pageflipping required in memory, the previous page, and the rear page. 4. Add a picture to the displayed area To avoid painting to the outside. 5. In the drawing, then "brush", change to the previous page. Step 1: Initialization DirectDraw is an object-oriented function library. "Object-oriented" does not point to face Holding your girlfriend, "Object" here, you can simply imagine a template, say more, "Government", once you said: "I set up a government". Others will immediately put you immediately " Government template, naturally think that you have the function of printing banknotes. In our program, once you declare a variable (such as myDD) is the DirectDraw object (the official name of the DirectDraw object is LPDirectDraw), this MyDD has DirectDraw objects. All features and features. The definition syntax is: lpdirectdraw PMYDD; in addition to the DD object, there are several important objects, "page" , "Crust" and "Pattern". "Page Object" is used to define "previous page" and "rear". Definitions as follows: lpdirectdrawsurface PMYDDSFRONT; LPDIRECTDRAWSURFACE PMYDDSBACK; a "crop board object", in window mode To cut it to the part of the window boundary. LPDirectDrawClipper PMYCLIPPER; "Palette" Sets the color table of the screen, use it when reading 256 colors Bitmap. LPDirectDrawPalette myddpal; the most important "Object" is these Of course, DirectX has a lot of complex obscure objects. This is uncomfortable. Compulating a Windows program has a lot of variables and objects are Windows, which is the most annoying Microsoft place. Since Microsoft seems to know this. So After VC4.0, there is a wizard function to help you generate code. Try to use it with its Wizard to make our lives easier. Because our program may take up a window, give this window a handle: HWnd MyWnd initialization has not finished, we have to point these objects to a safe place null.pmydd = null; PMYDDSFRONT = NULL; PMYDDSBACK = NULL; PMYCLIPPER = NULL; PMYDPAL = NULL;

Finally, the Windows system opens up the corresponding area for our MyDD object: DirectDrawCreate (null, // with current display driver & pMydd, null)) Okay, annoying initialization is finally finished. Step 2: Set the display of the screen. DirectDraw The way you set your own screen, and its screen mode is divided into "all-screen" (unmnal mode). Each setup method. The main difference between settings is the parameter of SetCoopeRATIVELEVE .StcoOPERATIVELEVE in "Window "Mode this settings: PMYDD-> setCooperativeEvel (AFXGETMAINWND () -> getSafehWnd (), DDSCL_NORMAL); in" full screen "mode this setting: PMYDD-> SetCoopeRATIVELEVELEVEL (HWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN); if they return values Successful for DD_OK. We can adjust the screen to what we want, such as 640x480x8. That is 256 colors. There are those screen patterns that can be used depending on your display card PMYDD-> setDisplayMode (640, 480, 8); Now, we have a screen, but you can't paint on it. We need step three to build a picture board for painting painting. Step 3: Establish the front and then page (two sheets). Two pieces The advantage of the drawing board can be painted on one side, while seeing another piece of painting. When this picture is painted, the two boards are tune, let others see this piece of new painting. If the pain is enough Fast, it is enough to change. People will see animation, just like movie. We call this page flipping. What is this to create two drawings in the system (double buffering), However, you can also create three, four drawings.ddsurfaceDesc ddsd; // this structure description "page" characteristics .DDSD.DWFLAGS = DDSD_CAPS; DDSD.DDSCAPS.DWCAPS = DDSCAPS_PRIMARYSURFACE; // Specify that we use it before Page .dsd.dwsize = sizeof (ddsd); // Size / / Pan Previous page: HRESULT RESULT; Result = PMYDD-> CREATE Surface (& DDSD, & PMYDSFRONT, NULL); When an error occurs, remember the Release object .IF (Result! = DD_OK) {PMYDD-> Release (); PMYDD = NULL;} DDSD.DWWIDTH = SCR_WIDTH; / / After setting page size, ddsd.dwHeight = scr_height; // we have to specify the page ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS; ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; // do after page result = pMyDD-> CreateSurface (& ddsd, & pMyDDSBack 4:} Step 4: Add a picture frame (crop board) to the display area. Under the window. To prevent DirectDraw from painting outside the window. You need to add a picture frame (crop board). You can use createclipper to create a clipboard Result = PMYDD-> CREATECLIPPER (0, & PMYCLIPPER, NULL); After creation, put it onto the window, so you have to know that it is the window (Handle) .mywnd = AFXGETMAINWND () -> getsafehwnd (); // HandleResult = in the system

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

New Post(0)