About DirectX
DirectX is the preferred API (application interface) in Windows game design. Before it does not appear, a considerable part of the game developers is used to solve the compatibility problem of the game and various hardware, you can imagine, it is very painful. But now, developers need to face only the efficient, simple API provided by DirectX. Hardware compatibility problem? Let Microsoft and hardware drive developers to solve it. It can be seen that with the development of DirectX technology, the number of Windows games on the market grows at an amazing speed.
You can learn from this chapter:
l DirectX is
L DirectX why is there?
L DirectX API What components include?
What is DirectX?
DirectX is a set of APIs provided by Microsoft for game developers, providing interfaces for hardware operations, the latest version of 9.0. DirectX's various components provide support for each part of images, sounds, networks, etc. Relying on the standard interface provided by DirectX, developers can easily operate hardware and do not have to pay for the specific hardware.
DirectX components
DirectX is composed of multiple parts, respectively corresponds to different aspects of the system. In your program, you can easily call any API.
l DirectX Graphics All image display is implemented by it, which provides 2D and 3D display APIs.
l DirectInput provides a response to user input. It accepts control information from keyboard, mouse, rocker, handle, etc. In the latest version, support for power feedback is provided.
l Directplay It allows you to join the network function in the game, cooperate or compete with each other through the network, and other players. DirectPlay provides all interfaces that you can think of the network part of the network.
l DirectMusic uses it allows you to add background music or sound in the game, and different effects.
l DirectShow needs to join your game music or movie in your game? DirectSHOW can meet your requirements, which can play a local media file with a stream mode without reading it in memory.
l DirectSetUp When you have completed your game, you want to release it to your customers, DirectSetup will help you collect the DirectX components you need and merge them into your project.
// DirectX Graphics Components include all functions of DirectDraw and Direct3D, and DirectX after the 7.0 version will not use DirectDraw as a separate component.
Why do I need DirectX?
Before Windows, all games are DOS-based, single-threaded, and the operating system of the character interface. Therefore, developers have to do their hardware operations directly in their applications. The advantage of this approach is that due to the direct control of hardware, the program can maximize hardware resources, so that software can achieve the perfect effect of hardware, but its shortcomings and advantages are also obvious, developers will not Not for the software you can use, because of this, the software in that age usually supports the most common hardware devices on the market, such as some mainstream sound cards and graphics cards.
What is more headache is that at that time, the standard of sound cards and graphics cards is not uniform, so it is particularly difficult to support 320x240 resolution. For example, in order to reach the display resolution of 640x480, the developer has to go directly to the memory and the graphics register. The released Windows 3.1 also exists with almost the same problem under DOS, because the Windows operating system at this time is more like an application that runs under DOS, almost no user directly operating hardware, which also leads to that period Windows games, basically all chess games, action games, or the only platform for their only platform.
Microsoft has developed a set of WING runs that make developers more convenient to operate the graphics card. It can be said that it is DirectX's predecessor, it is a good attempt. Unfortunately, the functions it provides is too limited, and it is not possible to meet the needs of game development.
After a lot of preparations, Microsoft finally launched DirectX 1, known as the Game Development Kit (SDK). It provides a development library for the author of the game, and this has built a so-called intermediate platform between games and hardware, so that the work of displaying the image on the screen is easy. Although this version of DirectX does not support all hardware, it has let the game developers have found the way they have been looking for and see the future direction. So far, DirectX has experienced 9 versions of more and gradually increased support for network, sound, and multiple input devices.
DirectX constructor
DirectX makes it more simple and simple to develop games under Windows, and developers can get a lot of development libraries from Microsoft.
Over the years, DirectX has continuously upgraded to provide better support for more hardware. Microsoft designs DirectX as a COM component to ensure that each new version of DirectX can be compatible, that is, those developed under low versions can run in the new version of DirectX in the new version without any modifications. .
Component object model
DirectX API is based on CoM technology. The COM object is an interface collection, and various methods are implemented on each interface and is provided to developers. Typically, the entity of the COM object is to exist in the form of registered DLL in the system. For DirectX, its registration process has been completed when you installed it. For COM components, the operation of the method must be performed by an interface, so the advantage is that you can have different versions of the same interface in the COM component, thereby reaching backward compatibility.
That is, every version of DirectX adds a new DirectDraw interface, and the old interface remains, so that it does not destroy the integrity of the previous code. DirectX 7-based game runs in the Direct9 environment can also access the same interface.
Another advantage of COM technology is that language irrelevant. Each developer can develop games in languages they are familiar with, whether C , Basic, or C #.
DirectX structure
DirectX is composed of two layers, the API layer, and the hardware abstraction layer (HAL), the API is performed by HAL through HAL. HAL provides a set of standard interfaces to DirectX, allowing it to direct hardware through hardware drive. Because HAL needs to have a full understanding of hardware work, it is generally done by hardware manufacturers. You will never need to do anything directly to HAL, and DirectX provides a function that allows you to access it indirect. The relationship between the HAL layer and the hardware layer and the DirectX are shown in Figure 1.1.
Game program
↓
Direct3D API
↓
Hal
↓
Device drive interface
↓
Graphics card
In the early versions, in addition to HAL, there is a device imitation layer (HEL), which can simulate the effect of 3D hardware. This allows high-end graphics and low-end graphics cards to achieve the same functions in the DirectX API, although the effect is not the same. Because any effect of HEL is generated by software operations, the consequences of using this technique are far from the game of rapids than those that use hardware acceleration. At present, HEL technology has been basically replaced by some application plugins. Application developers will be responsible for this part to achieve the effect of soft card. Because due to the popularity of 3D graphics cards, all games on the basics are accelerated by 3D hardware.
// Direct3D Device Driving Tool (DDK) can be used to develop "soft devices" to simulate hardware devices.
This chapter section
You have learned DirectX's technology insider and the advantages it can bring. With it, you will start your first DirectX program.