Beginning DirectX 10 game programming (Chapter 01 DirectX Introduction)

Source: Internet
Author: User
Tags pixel coloring
DirectX is a game API on Windows. A few years ago, game developers struggled with hardware incompatibility, making it difficult for everyone to play the same game. Later, Microsoft launched DirectX. It provides a single and clean API for game developers to achieve compatibility with different types of hardware. Due to the release of DirectX, the number of games on the Windows platform has increased significantly. This chapter contains the following content:
  • Understand what DirectX is
  • Why is DirectX very useful?
  • How data streams pass through the direct3d 10 Pipeline
  • New Direct3D 10 content
What is direcx? DirectX is a set of Microsoft APIs that provide game developers with underlying interfaces for PC hardware on Windows platforms. Each API component is used to access different hardware, including graphics, sound, and networks. This interface allows developers to use only one set of functions to write games without worrying about the hardware conditions during game operation. Why DirectX? Before the launch of windows, developers developed games for DOS. This single-threaded, non-Gui operating system provides developers with a direct path between their program code and hardware. This is good or bad. For example, because there is a direct path between the game code and the hardware, developers can squeeze every copy of the hardware to allow them to completely control the game execution. The bad side is not only to directly program the hardware, but also to use third-party libraries supported by the hardware, even the graphics card and sound card. Graphics cards do not have a general standard, so they are especially complicated. Even if most graphics cards support a set of general resolutions, developers still need to directly access the video memory. This makes drawing on the screen very difficult. Developers will certainly find a better and easy way. Windows is released, but it still has DoS limitations. Windows runs on the top layer of DOS, which strictly limits the game's available resources and does not allow developers to directly access hardware. Therefore, the games written for the Windows platform were mainly card and board games. However, most games only support dos. The release of Windows 95 still does not solve this problem. Until DirectX 1, also called the release of game SDK. It provides developers with a single library that is located at the general layer between the game and hardware, making it easy to draw on the screen. The first version of DirectX does not support all external hardware, but it brings a good start for game developers. In the next few years, DirectX released multiple versions, each of which upgraded and added new technologies, such as network support, fluid audio, and new input devices. The latest version of DirectX is DirectX 10, which works with Windows Vista. The latest version is directx11.1 in combination with Win8. DirectX is based on a collection of various code libraries. Each Library provides a series of common functions for games or multimedia applications. DirectX is composed of multiple components. You only need to confirm that your game link has the required functions. The API of component DirectX is distributed across multiple components, each representing different aspects of the system. Each API can be used independently of each other, so you only need to add the functions required for your game. In DirectX 10, some components are updated, such as direct3d, while others are still maintained. DirectX components can be upgraded independently due to the addition of new features.
  • DirectX Grophic.This component is used for all image processing. This API provides a function for drawing 2D and 3D images. It not only initializes the game, but also sets environment textures for the game.
  • DirectInput.All user input can be processed through this API. This component supports the keyboard, mouse, handle, game lever, and other devices. DirectXInput also supports power feedback.
  • XInput.New member of the DiretX API. Used to connect to the new Xbox 360 controller.
  • DirectSound.Used to add sound effects or background music. DirectXSound allows you to load and play one or more audio files and has full control over their playback.
  • DirectSetup.After your game is complete, you want to pass it to others. DirectSetup provides functions to install the latest DirectX version on your computer.
Note: In earlier versions of DirectX (before directx8), 2D rendering is provided by the DirectDraw component. Because DirectDraw is not updated, 3D is used for all painting. In directx11, 2D painting can be achieved through the new component direct2d. Of course, 3D Painting is still feasible)
The API of the COM component DirectX is based on the COM component. The COM component is composed of a series of interfaces. Developers access DirectX through interfaces. The COM component is generally a DLL file registered to the system to provide support for special hardware on the machine. For DirectX COM components, registration occurs when DirectX is installed. Although similar to the C ++ object, the COM component needs to use interfaces to access functions. A com component may have multiple versions of one interface, which allows backward compatibility. For example, DirectX of each version contains not only the new version of the updated interface, but also the previous version to avoid code decommission. Therefore, games developed using direct7 can run on directx9 with only a small change. Another advantage of COM is that it supports multiple languages, not just C ++. Developers can use VB, C ++, and C # To call the same DirectX library. As Microsoft updates DirectX and adds new functions, the version number of each updated component increases. You will find that all the existing components of DirectX are not of the same level. For example, directsound is still 8.0, while direct3d is 10.0 (Note: d3d is 11.1 now ). Direct3d 10 introduces the new graphic API direct3d 10 (d3d10) in Windows Vista. In this version, direct3d has undergone major changes, streamlining APIs and abandoning a large amount of redundant code. The entire desktop of Windows Vista is based on d3d10, which allows users to go beyond the 2D work zone. Every window on the desktop is 3D. This is because the GPU on the video card becomes a shared resource. The upgrade of the video card provides the functions required by d3d10. In earlier DX versions, video card manufacturers only provided partial compatibility for direct3d, resulting in various confusions. For example, if you have bought the latest game, you cannot determine whether your video card can fully support the features required by the game. In d3d10, all graphics card manufacturers must make the hardware and corresponding drivers compatible with all features. This benefits video card buyers because they do not only support some of the features they consider important. Due to the large number of direct3d changes, direct3d10 cannot be run in earlier windows (Windows XP is not supported ). This will be the first time DirectX is no longer backward compatible. You have to remember this when writing a game with d3d10, because the game is running on the basis that the user has changed to Vista. (Note: The latest directx11 is still available only for Vista and later versions. This is why the XP system cannot play the dx11 game .) Direct3d is not only an API, but also a tool that transforms simple ry and images into a real world. You can use direct3d as a black box without having to worry about the internal implementation details. This is suitable for understanding how it works. D3d processes your scenario in multiple stages, executes specific tasks in each stage, and finally gets the final result. The first stage is the input Assembly stage, which can be imagined as building blocks. At this time, you put the basic building blocks of the project into the d3d pipeline (pipeline ). Next, the vertex is passed into the vertex coloring phase. Each vertex in the scenario is transmitted separately to the vertex coloring machine and changes immediately. You will learn about the coloring ER in the chapters below this book. In this phase, you can configure it through the shader. The third stage is geometric coloring, which is newly added by d3d10. The introduction of geometric coloring allows a complete primitive to be transformed as a whole, such as triangles and lines. In the past, each vertex of a primitive was processed separately by vertex coloring. In this phase, you can also configure it through the shader. The fourth stage is Rasterization. This function is used to convert a 3D scene to an actual pixel representation. Before the image is drawn, any pixels beyond the view will be dropped. The pixel coloring phase is the time when pixels are processed in your scenario. Like vertices, each pixel that forms a primitive will be put into a pixel coloring device. The pixel shader allows you to determine how objects in a scenario will appear in the final effect. You can add illumination, process environment textures, or just transmit pixels. In this phase, you can also configure it through the coloring tool. The final stage is the output merge stage, which is used to pack all packages. In this phase, parts processed from other stages of the pipeline are packaged to generate the final effect and then delivered to the screen. Stages of direct3d Pipeline
  1. Input assembly phase
  2. Vertex coloring stage
  3. Geometric coloring stage
  4. Grating stage
  5. Pixel coloring phase
  6. Output merging stage
  7. Output display stage
Direct3d 10 considerations some people may already be familiar with using DirectX to write games. In this way, you only need to pay a little attention when converting the game to the latest d3d version. The biggest change is the removal of the fixed pipeline function. In the past, you could choose a default method to deal with 3D scenes, and then d3d to deal with cutting, lighting, and coloring. But now, the introduction of d3d10 makes it all need to use programmable pipeline operations for special processing. We will introduce you to the latest situation in the section about the coloring tool. Another major change is the removal of caps. In previous d3d, you must check the potential capabilities of the Video hardware to determine whether certain features, such as pixel coloring, are available. However, none of the features provided by the hardware are simulated by the system using software. In this way, using d3d10 can significantly simplify the game initialization code. To sum up, do not worry about the large internal capacity when learning DirectX. DirectX is a huge API that covers a large number of different systems. Select a system and write code similar to the example as much as possible. Without knowing it, things will become interesting and gradually understood. If you encounter difficulties, remember that you are not fighting alone. gamedev.net and Microsoft's msdn are the best places to seek help.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.