DirectXGuide entry

zhaozj2021-02-08  241

DirectXGuide introduces some entry knowledge of the DXGuide library 2D section, mainly including how to create a DirectX program, turn the page, rendering page, etc. in DXGDD wizards, whether you are a master or a newbie, you get up as soon as possible. 1. The first DirectX program 2. Let your page move 3. Rendering page 4. Read the bit from the file Figure 5. Pack your file 6 ....... The first DirectX program starts Before, first you have to download the library file and header file of the DXGUID class library (note that there is a debug version and release!), Here is temporary and assume that you have placed the DXGUID's header file in D: / DXGUID / include, the library file is put D: / DXGUID / LIB. Then download a project guide Dxgdd.AWX, put it in ../microsoft visual studio / common / msdev98 / template (VC 6.0). Finally, the path to the DXGUID header file and library file is set. From the Tools menu to Options ... / Directorys, add the path to the header file and library file in the include files and library files. After the preparation is complete, you can start your first DirectX program. Enter VC, select New from the File menu, select DirectX Guide's DirectDraw AppWizard in the Pogjects form, and enter your project file name in Project Name, such as DDTest. Click the OK button to generate a DirectX program. Press Alt F7 before compiling the connection, set the Microsoft Foundation Classes to Use MFC in A Static Library in General. Well here, your DirectX program can compile, how, is it good? The program can switch in the window and full screen mode via the Alt Enter key. 2) Let your page move from the screen we see the content in front of the Front Buffer, we can also create one or more backbuffers, just as a paper is positive and Like the back, we can turn paper over. Also we can turn pages between Front Buffer and Backbuffer. Usually rendering in Back Buffer, render it to positive page, after turning, Back buffer has become Front Buffer, and the original Front Buffer has become a back buffer, in fact, Front Buffer and Back Buffer One loop is like a cube column in front of us, and the front face is positive, and the other three faces are referred to. However, these details do not need to be involved in the time of programming. All procedures can be done with a function flip (). What is the benefit of turn the page? You think about it, if we do rendering directly in Front Buffer, your eyes can see the rendering process, just like painting on the blackboard, first wipe the blackboard clean, and then draw a picture. That is to say, there is a gap that can be perceived by the eyes in each display frame, it looks very uncomfortable. Let's take a look at how to turn the page.

Class Wizard CDDTest to use the UpdateFrame () bool CDDTestApp :: UpdateFrame (void) {// add your code here m_pDDDevice-> GetRenderSurface () -> Fill (0);! Return CDirectXApp :: UpdateFrame ();} The m_pDDDevice -> getrendersurface () -> Fill (0); replace with the following code:............................................ Getrendersurface () -> Fill (0xfffffffff); bodd =! Bodd ;....... Is it very uncomfortable? But don't matter, the next tutorial will be better. What is it forgot? FLIP ()? How can I turn a page? Why did I not see it? In fact, the basic action DxGuide is packaged in the base class. See cdirectxapp :: updateFrame ()? You change it into m_pdirectdraw-> flip () to run again, really sorry, let you bloom, don't take it. The rendering page tells our rendering to be completed in the back buffer, then flip to Front Buffer after rendering. So how do I get backbuffer? Let's go back to a tutorial to see, there is such a sentence: m_pdddevice-> getrendersurface () -> Fill (0); here (cdddevice *) m_pdddevice is your current graphics device, CDDDevice is mainly used for enumeration The display device, that is, DDGUIDE supports multi-screen, here is not more introduced, know what m_pdddevice is OK. GetRendersurface () returned is the Back Buffer of this graphics, the return value type is CDDSurface *, Fill (DWORD) is CDDSurface is a member function that is used to fill in the buffer. So Fill (0) is filled in the buffer, Fill (0xffffffffff) is filled in white. Seeing this here, you should know that in fact, the previous tutorial has been rendered. Let's take a look at how to do some simple rendering on Buffer.

Still use the project generated in the first example to do some small changes, in cddtestapp :: updateFrame (), m_pdddevice-> getrendersurface () -> fill (0); delete, and insert the following line in this location : M_pdddevice-> getrendersurface () -> Fill (0xffffff); CDC DC; m_pdddevice-> getrendersurface () -> getdc (dc); dc.setbkcolor (0x00fffffff); dc.setTextColor; dc.TextOut (10, 10, "Welcome to DirectX Guide!"); DC.ARC (30, 30, 40); DC.Moveto (30, 30); DC.LineTo (40, 40); m_pdddevice- > Getrendersurface () -> ReleaseDC (DC); Friends who are familiar with GDI must feel familiar, yes, almost the same, if you don't care, use DC, but suggestions are still less used. Ok, compile run, do you not think that the frame number is reduced more than the first example? 3) Reading from the file to teach you how to draw a bit drawing to the buffer. The two buffer sizes of Front Buffer and Back Buffer are the same as the resolution you initialized, and there is a buffer to be arbitrary, called OFF Screen Buffer, we can read bitmaps to such OFF Screen. In the buffer, then it is directly to the back buffer, Blit is used directly, and blit means the block transfer. The CDDIBSurface class in DxGuide is specifically used to handle bitmaps. Let's take a look at the basic usage of CDDIBSurface, which is still using an example of the project.

Join in DDTestApp.h in line #include "DDDIBSurface.h" use ClassWizard to add a member variable CDDDIBSurface * m_pDib in CDDTestApp in; use ClassWizard to CDDTestApp :: InitDXObjects (void), the line // add your init code here! After inserting the following line m_pdib = new cdddibsurface; m_pdib-> create (m_pdddevice, "dxguide.bmp"); Go to CDDTestapp :: UpdateFrame (Void), in row m_pdddevice-> getrendersurface () -> Fill (0); Insert under the following line CRECT Rect (0, 0, m_pdib-> getWidth (), m_pdib-> getHeight ()); m_pdddevice-> getrendersurface () -> BLT (Rect, m_pdib, rect, ddblt_wait, null); m_pdddevice-> getrendersurface () -> BLTFAST (100, 100, m_pdib, rect, ddbltfast_wait); Go to CDDTestapp :: DestroyDxObjects (Void), insert the downlink DELETE M_PDIB; m_pdib = null after row // add your destroy code here! Create a Usage called DxGuide.Bmp Blt and Bltfast reference SDK Help IdirectDrawSurface :: BLT and IDirectDrawsurface :: Bltfast's usage. Note: You must CDDTestApp.cpp here to find out the structure, the constructor m_dwAppInitFlags = CDirectXApp :: DXAPPIF_DD; | CDirectXApp :: DXAPPIF_DI | CDirectXApp :: DXAPPIF_DS | CDirectXApp :: DXAPPIF_GUIMANAGER; DirectX decide which components to use, if you do not want Use DirectInput to take CDIRECTXAPP :: DxAppif_di. (Note: To use DirectInput if you want to use GuiManager). CDDTestapp :: getDXinitSettings (Void) is used to get the initial information, such as selecting which device is selected to display the screen or play sound. CDDTestapp :: initdxObjects (void) is used to initialize the member variable. CDDTestapp :: DestroyDxObjects (Void) is used to release the memory space applied for a member variable. CDDTestApp :: UpdateFrame (Void) is used to render the page. Initialization and release of the member variable you join yourself should be done in initdxobjects () and destroydxObjects (). 4) Why pack your files to package the file? The first is to speed up the read speed of the file. If you have dozens of even thousands of files in the same directory, the file lookup is a fee-time operation when opening the file. If you are packaged into a big file, no matter what you want How many files read, only one way to open the file; there is still a role outside to make the directory look clean, the file will not be so intuitive, others will not see your files. What is your files?

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

New Post(0)