DirectX is a combination of technologies developed by Microsoft Corporation to make Windows an optimal platform for multimedia applications and computer games with full-color graphics, video, 3D animation and surround sound. DirectX technology will become an integral part of future versions of Microsoft OS - Windows 98 and Windows NT 5.0, as well as Internet Explorer 4.0. Already today, DirectX enables developers of gaming software and multimedia applications to create products that are not tied to any particular hardware, users can buy games and multimedia programs for Windows without worrying about their incompatibility with the hardware of their computer.

Prior to the advent of DirectX, almost all games for PC computers were implemented on the MS-DOS platform. Each program had to be completed by developers with a lot of video and audio drivers (in order to cover as many installed hardware components as possible) and at the same time to use DOS expanders to overcome the barrier of 640 Kbytes. Windows environment, which simplified the interaction of users with PC thanks to a convenient graphical interface, did not make life easier for programmers: in Windows graphics programs were too slow. Paradoxically as it sounds, Windows, as a graphical environment, has not been adapted to perform fast graphic operations.

Trying to improve the situation, Microsoft developed WinG technology for the creators of computer games and graphics applications, which provided faster execution of graphic operations than the GDI (Graphics Device Interface) interface of Windows (see the sidebar "WinG or DirectDraw?"). At the same time, the corporation was not just limited to solving performance problems. Developers sought to ensure that programmers could create game and application programs without thinking about what hardware components are available for a specific user. The operating system itself had to contain all the necessary drivers and take over the interaction of the program with PC hardware, such as audio, video cards and printers.

Meanwhile, even after the release of Windows 95, the Microsoft platform still did not comply with the promised promises. Only today with the advent of improved technologies, which have received the generalized name DirectX, the situation begins to change.

DirectX technology, now version 5.0 (version 6.0 passes beta testing), which replaced DirectX 3.0, allows programmers to create applications with built-in access to hardware in Windows 95 (and in future Windows 98 and NT 5.0). In this case, they do not need to know the specific hardware configuration of a specific computer - explicit programming of a specific board is not required. In fact, DirectX acts as an intermediary between the program and the driver, converting generalized commands to commands specific to a particular device.

If initially DirectX was focused on turning Windows 95 into a full-fledged platform for computer games, which always stimulated the development of PC hardware, then as the media technologies penetrate into mass applications, the DirectX programming interface becomes an important part of the operating system. Recall that the browser Internet Explorer 4.0 uses five components DirectX 5.0: DirectDraw, DirectSound, Direct3D, DirectShow and DirectAnimation.

DirectX 6.0 technology will become an integral part of the new Microsoft OS - Windows 98 and Windows NT 5.0, which will allow it to finally conquer the market of mass applications.

The base layer of DirectX

The base layer (DirectX Foundation) provides developers with a single set of APIs that provide direct access to hardware - accelerators 3D graphics, sound cards. These APIs carry out so-called lower-level functions, in particular control of input devices (such as joysticks, mouse and keyboard), mixing and sound reproduction. These functions are supported by four components that make DirectX Foundation: DirectDraw, Direct3D, DirectInput and DirectSound.

HAL and HEL

Prior to the advent of DirectX, multimedia application developers for the Windows platform had to customize their products to work on a wide range of devices and configurations. DirectX Foundation provides the so-called hardware abstraction level (HAL) (Hardware Abstraction Layer). HAL functions as an intermediate between the software and hardware, allowing developers to access these or other components without knowing their brand, model and other details. As a result, they are able to write only one version of the application that interacts with DirectX.

In addition, DirectX Foundation provides tools for developers to achieve the highest performance. This base layer defines the capabilities of the hardware of the computer and sets the appropriate application parameters. It also provides the execution of multimedia applications that use functions not supported in the system at the hardware level. This is achieved through the HEL (Hardware Emulation Layer) level, with which DirectX programmatically emulates functions that are not implemented by the device itself. If the hardware is not compatible with the requested service, the HEL level tries to emulate it in the best possible way. Most often, 3D-graphics tools are emulated. Although emulation is not as effective as hardware implementation, the developer does not have to write several versions of the same program.

DirectDraw

The DirectDraw interface provides developers with the means to more directly access hardware components than is possible with Windows 95 with its virtual device drivers, which in turn leads to a significant acceleration of graphical operations. With the advent of DirectDraw, developers finally began to view Windows 95 as a serious platform for computer games and other multimedia applications. Many DirectDraw tools are directly or indirectly used in Direct3D.

It is DirectDraw that is the only DirectX component that interacts with HAL. Using DirectDraw applications interact only with DirectDraw and can not directly access the HAL. This interface improves application performance by supporting 2D graphics, fast raster image processing, bluting, transparent object overlay, and multi-layer animation management.

Essentially, DirectDraw is a video memory manager. It allows the programmer to store textures and manipulate them directly in the video memory, taking advantage of the transfer of blocks implemented at the hardware level. This transfer from one area of ​​video memory to another is much faster than transferring from system memory to video memory (especially if 64-bit video cards are used). In addition, these operations are performed independently of the CPU. Thus, the processor is released for other work. In addition, DirectDraw supports other hardware acceleration mechanisms implemented by the video card, such as sprites and Z-buffering.

DirectDraw implements the interface with video memory using four objects: DirectDraw, DirectDrawSurface, DirectDrawPalette and DirectDrawClipper. The DirectDraw object, the display adapter card, is primary. The DirectDrawSurface object represents the video memory where the displayed data is placed. Usually DirectDrawSurface is used as follows. In memory, two buffers are created (for changing images). The displayed fragments are written to the first buffer (rather than displayed directly on the screen), and those that should be displayed next - in the second. Then, the buffers are switched - the second buffer becomes the current one and the image is updated. Direct3D allows you to run the application in full screen mode or in a window, as well as promptly configure the display resolution in the program.

The DirectDrawPalette object allows the use of its own palette of 256 colors for each fragment or the use of common palettes, and DirectDrawClipper allows applications running in the window to work around the GDI, reducing delays in displaying graphics and providing transparent access to hardware accelerators.

Direct3D

The Direct3D component helps to integrate 3D graphics with Windows applications. It is used to develop interactive 3D applications and real-time programs. Undoubtedly its advantages are device independence, a general model of drivers (guaranteeing support for a minimal set of tools and capabilities), ease of inclusion in applications of functions of three-dimensional graphics. The application systems created with Direct3D can run on different hardware platforms, since all Direct3D tools are implemented "on top" of the HAL. In addition, Direct3D offers hardware developers a specification that helps create boards that initially support various Direct3D tools.

One of the most important qualities of Direct3D is transparent access to graphics accelerators. If the hardware platform does not support some function, Direct3D implements its equivalent programmatically. During its execution, the application can determine the availability of hardware components and use their capabilities. In addition, Direct3D implements the fastest software-executed rendering, which uses a full 3D rendering pipeline. If there is adequate hardware support, some of the operations of this kind are performed by the computer hardware.

Direct3D tools are available through the Retained Mode and Immediate Mode interfaces. Retained Mode is based on Immediate Mode and some DirectDraw tools. Together with HAL, these interfaces essentially form Direct3D. Direct3D Retained Mode (the interface for mapping Direct3D objects after grouping them) allows developers to combine multimedia information (for example, graphics and sound) to create three-dimensional scenes and manage these scenes in their applications. For correct playback, the Direct3D file system stores the information necessary for 3D rendering, including textures, the order of objects location, the animation route and other details.

Direct3D Immediate Mode (Direct3D Direct Object Display Interface) is implemented at the DirectX Foundation level and gives developers more direct access to hardware. It provides increased speed and flexibility, but in this case, the rendering and management of the scene must be done by the programmer. In addition, Direct3D works in conjunction with HEL and implements software emulation of 3D graphics rendering tools not supported by hardware. This layer is tightly integrated with DirectDraw HAL and Win32 GDI drivers, which helps unify the driver model to accelerate the processing of 3D graphics.

One of the most important elements of Direct3D is the rendering engine, which is responsible for defining the scene (as a set of points in three-dimensional space), various specifications for textures, light sources and cameras. Functionally, the rendering engine is implemented using three modules: transformation, illumination and rasterization (see the sidebar "Rendering in Direct3D"). The operations performed by each of them can be accelerated by hardware, and this acceleration is transparent to the user and application. The developer only needs to provide in the application the function of identifying the corresponding hardware components.

Components DirectInput and DirectSound DirectInput implements support in applications such peripheral control devices as joysticks. It allows developers to program interaction with these devices using the HAL or HEL level. At the same time, DirectInput is not limited to gaming controllers and implements an input interface from devices such as graphics tablets.

The DirectSound component acts as an interface with hardware intended for audio playback. It provides playback of .WAV files and allows the use of buffers of different types (basic, auxiliary, static and streaming). The main buffer (currently used by the computer) contains files from the auxiliary buffers (allocated for each .WAV file). Small files for speeding up access can be placed in static buffers, and longer ones can be cyclically loaded into stream buffers in parts. In addition, DirectSound provides a mixer that controls various playback parameters (from volume to surround effects applied to auxiliary buffers).

Multimedia layer DirectX

Above the basic level of DirectX (DirectX Foundation) is a multimedia layer DirectX Media. If DirectX Foundation implements the functions of the lower level, then DirectX Media provides high-level tools to support animation, multimedia streams (viewing and listening to video and audio files downloaded from the Internet), as well as interactive functions.

DirectX Media, like the DirectX Foundation, consists of several integrated components: DirectShow, DirectModel, DirectAnimation, DirectPlay, Direct3D Retained Mode (sometimes it includes VRML support). In particular, DirectShow and DirectPlay are built into the latest versions of Microsoft Internet Explorer. Using a set of interrelated filters (interacting with the data stream through the filter manager), DirectShow performs the functions of playing audio and video streams in various formats (MPEG, QuickTime, AVI and WAV). This component is one example of the implementation of embedding in the operating system of the tools that were previously offered as integrated modules and software add-ons, supplied by independent developers.

Other components of the multimedia layer provide other high-level functions, each of which helps developers fully utilize the capabilities of multimedia hardware. DirectModel implements rendering and interaction with large objects of 3D-graphics. DirectAnimation allows developers to combine sound with motion of two- and three-dimensional images and associate them with temporary and user-triggered events in order to create complex animations. The DirectPlay component is designed primarily for interactive games involving multiple partners and applications that use interactive communications between network users. It allows you to play multimedia while working on the network, exchanging information about the progress of the game and messages between its participants. Virtual Reality Modeling Language (VRML) uses DirectX to implement three-dimensional "virtual worlds" in Web browsers, which significantly increases the speed of their display.

In general, the multimedia layer DirectX helps developers solve one of the most difficult tasks that arise when creating high-quality game programs for Windows and multimedia applications - to coordinate various types of multimedia effects. This is done using a set of APIs that synchronize different effects within a single application. Prior to the advent of DirectX in this situation, we had to use APIs from different manufacturers (video, audio or animation), which made it difficult to combine elements. The DirectX Media layer helps developers also synchronize media playback by linking its elements to a single timeline.

The component library and other high-level elements DirectX Foundation and DirectX Media provide developers with another important tool - a component library that can be used to create computer games and multimedia applications. Such a library simplifies the development process, because it allows programmers to apply a large number of standard interfaces and elements. In addition, high-level operations implemented by DirectX Media are used in the next, component layer, consisting of applications built on the base and multimedia layers. Such components are, in particular, ActiveMovie, NetMeeting and NetShow, which are part of IE 4, Windows 98 and Windows NT 5.0. DirectX gives the opportunity to develop a whole system of similar components, the number of which continues to increase. In addition, the components that make up DirectX provide developers with a flexible platform for using the latest technology.

Conclusion

DirectX technology was necessary due to the openness of the PC platform, which is equipped with all new and more complex multimedia peripherals from different manufacturers. Although with appropriate video and audio standards developers could create their own programs, focusing directly on the hardware and not using any layer of DirectX type, this would contradict the underlying principle of the Windows and Windows NT platform to exclude direct access to hardware resources (to prevent failures OS because of incorrectly written applications).

DirectX provides developers with new creativity: they do not have to worry about which display adapter, sound card or 3D graphics acceleration processor is installed on the user's PC. Since DirectX technology is initially designed for the development of software and hardware improvements, developers and users can be confident that their applications will optimally use new hardware technologies.

Orientation of DirectX to the Windows platform and full control by Microsoft are not all encouraging. However, undoubtedly, this product will greatly simplify the implementation of multimedia applications for Windows and will provide an even wider distribution of this platform.

How to purchase DirectX You can get DirectX at your disposal by subscribing to the Microsoft Developer Network program or by purchasing one of Microsoft Press books (such as "3D Graphics Programming for Windows 95") with a CD containing DirectX software or by downloading it From the Microsoft Web site (www.microsoft.com/directx).

WinG or DirectDraw?

Prior to the advent of DirectX, programmers used WinG to create animations in Windows. It guarantees direct access to the raster image in the system memory, which allows to use optimized subroutines to output raster graphics. WinG provides better performance than the GDI interface.

After the scene is prepared using WinG, the bitmap is placed in the video memory and displayed on the screen. Unlike WinG, where you need to exchange images between RAM and video memory, in DirectDraw for presentation on the screen the scene is rewritten from one area of ​​the video memory to another, which significantly improves performance. Because video memory resources are limited, in complex games or applications, DirectDraw and WinG technologies can co-exist and be used together.

What's New in DirectX 6.0

The recently introduced beta version of the DirectX 6.0 programming interface suite (which may be renamed DirectX 98) is the sixth generation of the Microsoft Direct API. The new version of DirectX will be implemented for the first time in Windows 98 and NT 5.0. The funds appearing in it are focused mainly on the preparation of multimedia presentations and expanded support for computer games. In DirectX 6.0, the Direct3D APIs have been improved (to support graphics accelerators such as ViRGE from S3 and Permedia2 from 3Dlabs). A new set of APIs - DirectMusic provides access from Windows-based applications to MIDI files and other musical instrument formats. Direct3D includes a more advanced software rasterizer, provides support for compressed texture formats, template buffers, as well as multi-text effects, texture caching management, extrusion, and DMA access optimization. Improved performance of operations with polygons. There is also an improved support for DVD technology in the DirectShow component.

In the next versions, Microsoft plans to improve rendering accuracy, improve the relief and operations with the 3D environment, add support for printers that is important for business applications.

DirectX and OpenGL

OpenGL, once developed by Silicon Graphics, implements a three-dimensional graphics interface, mainly in modeling and rendering applications. The OpenGL interface will be included in Windows 98, Windows NT 5.0 and is already available in existing versions - Windows NT 4.0 / 3.51 and Windows 95 OSR2. In the Windows 98 / NT 5.0 architecture, it is at a higher level than DirectX, and uses DirectX for optimal hardware support. Functionally, OpenGL is similar to a DirectX component like Direct3D, but some analysts believe that OpenGL has a more sophisticated architecture. Microsoft duplicated many OpenGL functions in some DirectX components. Developers do not fully understand why this is needed, but according to Microsoft, Direct3D is an important additional link between software and hardware, providing compatibility with a wide range of display devices.

DirectX components

DirectX - a set of libraries and interfaces for developing multimedia and computer games for Windows 95 and Windows NT, which includes five basic APIs: DirectDraw, Direct3D, DirectSound, DirectInput and DirectPlay.

DirectDraw provides direct bit-by-bit access to video memory, allows you to store image fragments directly in it, quickly move bit blocks and switch pages of screen memory. It is used to perform 2D graphics operations and is used directly or indirectly by the Direct3D component.

Direct3D is a 3D rendering subsystem that provides a low-level API with basic Immediate Mode and a high-level API for supporting sophisticated Retained Mode.

DirectSound implements a hardware-independent interface for audio playback and allows applications to take full advantage of the computer's audio capabilities. Performs mixing and some basic operations, such as volume control and frequency response.

DirectInput is actually part of Windows 95 and provides a hardware-independent input system, implementing an interface with existing devices, mostly game controllers, a keyboard, a mouse, joysticks and other controls. Supports up to 16 joysticks, 32 buttons and manipulators with six degrees of freedom.

DirectPlay allows you to create game programs designed for multiple participants, whose computers communicate via modem, cable, local or other networks (including the Internet). In all cases, the same interface is used, which implements an independent communication protocol.

The fifth version of DirectX was supplemented with components DirectShow, DirectAnimation and DirectModel (for managing animation, video, graphics and other elements of interactive multimedia), and in the sixth there will be a component DirectMusic.

What version of DirectX do you use?

To determine which version of DirectX is installed on your Windows 95-based computer, follow these steps:

Click the Start button, select Find and Files. In the Named field of the dialog that appears, specify Draw.dll, and in the Look In field, type C: (or the drive where the system is installed). Then click the Find Now button.

As a result of the search, a single Ddraw.dll file should be found (usually located in the C: WINDOWSSYSTEM folder). If such a file is not found, then probably no DirectX software is installed on your system.

Right-click the Ddraw.dll file and select Properties from the menu. Click the Version tab.

And now pay attention to the version number: 4.02.0095 means version 1; 4.03.00.1096 - version 2; 4.04.00.0068 - version 3 or 3a, and any other values ​​indicate that the fifth version of DirectX is installed on the system.

Information about updating DirectX can be found on the Microsoft Web site (www.microsoft.com/directx).

DirectDraw: what is needed for programming?

The DirectX interface implements the principles of the COM model (Component Object Model), which allows you to design the necessary functions in the form of components or objects. A significant number of DirectX APIs are a set of OLE objects. All functions supported by the COM object can be used as an interface when interacting with this object. Such an interface is simply a group of related functions used to access various methods of the object. The use of COM objects in DLLs gives a number of advantages over exporting conventional APIs. Use the specified COM objects in a C ++ or Object Pascal application is not more difficult than any other API. The DirectDraw header file describes C ++ classes for various DirectX objects. Instances of these classes are created by calling the corresponding create functions. Naturally, the creation of Windows-based applications using DirectX requires skills in working with the SDK or MFC.

What does it take to compile and link a program using DirectX? First of all - a set of DirectX SDK. It comes with a help file and useful examples of programs. In addition, the system must have the DDRAW.DLL library installed. To create or import such a library, you can use the utility IMPLIB.EXE. Since DirectX is a 32-bit technology, you need a compiler capable of generating Win32 applications (such as Borland C ++ 4.52 or C ++ 5.0). To run the program, the drivers must be installed on the system.

Rendering in Direct3D

The Direct3D component performs rendering of 3D-graphics with the help of transformation modules, rendering of illumination and rasterization.

The transformation module performs geometric transformations by means of three matrices: representation transformations, world coordinates transformation and projection matrix. The module based on these matrices builds one composite, which is used in calculations (in the latest versions of Direct3D, MMX technology is used to speed up the calculations).

The lightness calculation module uses the data received from the transformation module to work. It takes into account the position of the light sources, the level of scattered illumination and the optical properties of the materials. This allows the implementation of two models: monochrome and RGB. In a monochrome model, only a monochrome intensity is taken into account for each light source and then a single penumbra value is calculated for a given area. The color components of the light flux are ignored. The RGB model helps make the scene more realistic by taking into account the color characteristics of the light source and the material of the illuminated object.

The rasterization module is responsible for directly displaying the received data. He looks through the list of vertices and generates their transformed images for final rendering, taking into account the cut-off parameters and the presence of hidden surfaces.

Thus, the rendering mechanism reduces to the following: the points of the three-dimensional model are transformed by the transformation module into equivalent two-dimensional data, which are transmitted to the module that calculates the intensity of the light incident on them, and then directed to the rasterization module that determines transparency and imposes textures.