DirectX5.0 Latest Game Programming Guide

zhaozj2021-02-11  193

DirectX5.0 Latest Game Programming Guide Overview] Zhu Chunxi & Wuhan, Wuhan

For numerous game makers, the launch of Microsoft's DirectX 5 is not an excellent news. It contains the latest technologies and tools to prepare next-generation computer games and multimedia applications, providing a wide range of application interface APIs to make programmers to design high-performance real-time applications. DirectX makes the game running under the Microsoft Windows operating system than the game running under the MS-DOS operating system with higher performance, even more than a dedicated gaming machine. The primary purpose of Microsoft Development DirectX is to improve the easiness of game development in the Windows environment. Prior to this, most of the games on your computer are based on MS-DOS, and the game developers must prepare different programs for different hardware interface cards, although the code is similar, but it is inevitable that there are many repetitive labor. With DirectX, the game developers can get the advantages of DirectX's hardware independence, but also directly access hardware. The most important goal of DirectX is to provide direct hardware access features in MS-DOS, while deraving hardware identification issues brought by adding new hardware in your computer. Because the hardware upgrade is inevitable, DirectX actually provides another method for plugging. Therefore, using DirectX can develop high performance real-time applications, you can directly access hardware and future hardware devices in the computer. DirectX provides a consistent interface between hardware and applications to reduce the complexity of installation and configuration, and make the hardware utilize optimal. With interface provided by DirectX, programmers can take advantage of hardware features without considering their specific details. A excellent Windows-based high-performance game should be able to utilize the following technologies:. To improve performance, specially designed acceleration cards. Plug and Play PNP (PLUG AND PLAY). Communication services embedded in Windows, including DirectPlay DirectX 5 Includes seven parts, the following parts are made in a brief description. (1) .directDraw By supporting the hardware and hardware acceleration technology of the memory in the middle of the memory, it is quickly accessed, and the bit block transmission and buffer flip function of the hardware is quickly directly accessed by supporting the access screen. (2) .directSound provides a hardware and software sound mixing and recording and reproducing. (3) .directPlay makes the game more simple and convenient to the connection between the modem and the network. (4) .direct3D provides a high-level retention mode interface and aimediate-mode interface. The former allows the program to easily complete a complete three-dimensional graphics system, which makes the program fully controlled colored pipes. .DirectInput provides an API and driver based on Windows game-based input, which not only supports current keyboards, mouse, and joysticks, but also supports future Windows-based input devices. .DirectSetup provides a disposable installation process for DirectX. (7) .autoplay It is the feature of Windows 95, when you put the disc in the optical drive, it automatically runs the installer or game. In fact, AutoPlay is also part of the Microsoft Win32 API, not only in DirectX SDK. . By querying the various DirectX object interfaces, you can detect which version of DirectX is installed in the system, and the getDxversion function in the DirectX SDK getDXVersion.cpp can complete this task. This function creates some key DirectX objects-a DirectDraw object, a DirectDrawSurface object, and a DirectInput object - to detect the version of DirectX installed in the system.

If the old version of DirectX SDK is installed in the system, you must make sure not to include its Include and Lib path, using the DirectX 5 header compiled code with the DirectX 3 library link will appear unpredictable errors. Because C languages ​​are more directly accessible to computer hardware, DirectX uses C languages ​​as the development of the main language. DirectX is designed specifically for Visual C , so writing DirectX programs is best performed under Visual C . Of course, Borland C 5.0 is no problem, but the configuration is different, and this problem will be mentioned below. In order to reduce the difficulty of programming, some companies also develop controls running in different programming environments, such as Arakelian Soft's ActiveX control Directstudio98 For Visual Basic5.0, Tegosoft's Tegosoft ActiveX for Visual Basic, and John Pullen, PAUL Bearne and Jeff Kurtz have been developed in Delphi Games Creator, etc. under Delphi. Considering compatibility issues, it is best to use Visual C .

I. Most of the APIs in DirectX and Parts Objects Com (Component Object Model) DirectX are composed of COM-based objects and interfaces. COM is the foundation based on object-based system, which is a core model of COM programming, which is also an interface specification. At the operating system level, it is another object model. Many DirectX APIs are created as an instance of a COM object. You can see an object as a black box, the object communicate with objects through the interface, sending a command received by the COM interface to an object or from an object being called a method. For example, the iDirectdraw2 :: getDisplayMode method obtains the current display mode from the DirectDraw object through the iDirectDraw2 interface. Objects can be bundled with other objects at runtime and can use the interfaces of these objects. If you already know an object is a COM object, and you know the interface supported by the object, your application or other object can determine the service that the first object can perform. One way to inherit all COM objects is the Query interface method, which allows you to determine an object supported by an object and create a pointer to these interfaces. 1.2, all COM interfaces of the IUNKNOWN interface are derived from a interface called IUNKNOWN, which provides DirectX's control and operational multi-interface capability of an object survival. IUNKNOWN contains three methods: .addref When an interface or another application is bundled up to an object, use the AddRef method to add the index value of the object to 1. .QueryInterface is queried by the characteristics supported by pointer to a specific interface. .Release reduces the index value of the object, which is released from memory when the index value is 0. The addRef and the release method are responsible for maintaining the index value of the object. For example, if you create a DirectDrawSurface object, the index value of the object is set to 1, each time there is a pointer to the object, the function must be added to the index value of the object by returning the normally. 1. Each ADDREF is called must have a Release call to it. When the index value of the object reaches 0, the object is revoked, and all interfaces of the object are not reused. QueryInterface method Determines whether an object supports the specified interface, if support, QueryInterface returns a pointer to the interface. Then you can use the method to communicate with the object. If QueryInterface successfully returns a pointer to the interface, it automatically invokes the AddRef method to increase the index value of the object. Release Release must be called to reduce the index value of the object before revoking the interface pointer. 1.3, the interface in DirectX COM interface DirectX is created with considerable basic COM programming. Each interface characterizing the object of the device is derived from the IUNKNOWN COM interface, such as iDirectdraw2, IDirectSound, and IDirectPlay. The creation of the basic object is handled by the special function in the dynamic link library DLL. Typically, the DirectX object model provides a primary object for each device. Other support services are derived from the primary object. For example, the DirectDRAW object is characterized to display the adapter. You can use DirectDraw to create DirectDrawSurface objects that represent memory and behave the DirectDrawPalette object that characterizes the hardware palette. The same truth, DirectSound object characterizes the audio card and uses it creates a DirectSoundBuffer object that represents the source. In addition to enabling sub-objects, the main object of the device can also determine the performance of the device it characterizes, such as the size of the screen and the number of colors, whether the sound card supports wave form synthesis.

1.4, C and COM interfaces For C programmers, the COM interface is like an abstract base class. In the base class of C , all methods are defined as pure, which means that there is no code to be associated with methods. The purely virtual C function and the COM interface use a device called a virtual table (VTABLE). A virtual table contains a declaration for all functions applied to the interface. If you want the program or object to use these functions, you can check the interface where the object exists with the QueryInterface method, get the pointer to the interface, after calling queryinterface, the application or object actually receives the pointer of the virtual table from the object, by which The pointer can invoke all interface methods applied to the object. Another similarity of COM objects and C is the first parameter of the method is the name of the interface or class, and C is called this parameter. Because COM objects and C objects are completely binary compatible, the compiler is equipped with the COM interface as the C abstraction class, and has the same syntax, which makes the code simple. 1.5, get the new interface component object model is not the functionality of the object by changing the method in which the existing interface is expanded by extending a new interface containing new features. In the case where the existing interface status is retained, the COM object is free to expand the service and maintains the same old application. DirectX components follow this principles, for example, the DirectDraw part supports three versions of the IDirectDrawSurface interface: iDirectdrawsurface, IDirectdrawSurface2 and IDirectDrawSurface3. To use the features provided by the new interface, you must call the object's iUnknown :: queryinterface method, specify the global unified identity of the interface to get the global unified identity of GUID (Global Unique Identifier). The GUID of the interface is declared in the relevant header file. The following example illustrates how to query a new interface: lpdirectdraw lpdd1; lpdirectdraw2 lpdd2; ddrval = directddrawcreate (null, & lpdd1, null); if (Failed (DDRVAL) Goto Errorout;

// Query for the IDirectDraw2 Interface ddrval = lpDD1-> Query Interface (IID_IDirectDraw2, (void **) & lpDD2); if (FAILED (ddrval)) goto ERROROUT; // Now that we have an IDirectDraw2, release the original Interface lpDD1- > Release (); new interface does not support the method provided by the previous version of the interface, the iDirect3ddevice2 interface is just such an interface. If your application requires the feature provided by an earlier version of the interface, you can use the old interface of the GUID, use the above-described routine to query the interface. 1.6, access to any COM interface method can also be called with C language using C language. Calling an interface method with a C language requires main two things:. The first parameter of the method is always the object (ie, this) that has been created. The method is used. Each method in the interface is referenced by the pointer of the object. The following example uses the C language call IDirectdraw2 :: createSurface method to create a surface of the same DirectDRAW object: RET = LPDD-> lpvtbl-> createssSurface (LPDD, & DDSD, & LPDDS, NULL); where the LPDD parameter is associated with the new surface DirectDraw object, at the same time, this method fills a structure & DDSD that describes the surface (SURFACE), returns a pointer to the new interface & lpdds. Call the IDirectDraw2 :: createSurFace method, first point to the virtual table of the DirectDRAW object, then get the method in the virtual table. The first parameter provided in the method is the index of the DirectDRAW object already created. The following code illustrates the differences between C and C calls to the COM object method: Ret = LPDD-> CreateSurface (& DDSD, & LPDDS, NULL) II, DirectX 5 New content, DirectX 5 is the latest version of DirectX, Prior to this, Microsoft issued DirectX, DirectX2, DirectX3 (no DirectX4). Obviously, DirectX 5 provides more features and services than DirectX3, but programs written by DirectX3 API can successfully compile and run. Below is the main differences between DirectX5 and DirectX3: 2.1, DirectDraw DirectDraw extends new video port capabilities, allowing applications to control data streams from the hardware video port to the DirectDRAW surface in memory. In addition, the DirectDraw hardware emulation layer Hel (Hardware Emulate Layer) can utilize the acceleration performance provided by the Pentium MMX processor. DirectDraw detects whether the processor is MMX processor when you create a surface, on the non-Pepsc processor's computer, which will cause the debugger to report an event, which does not affect the performance and stability of the program. . DirectDraw supports a wide-screen surface (OFF-Screen Surface) than the primary surface, as long as the hardware allows, you can create a sufficiently wide surface.

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

New Post(0)