46
1 A presentation on A presentation on DirectX DirectX ® ® Alex Brill Alex Brill Emil Elazar Emil Elazar Noam Monheit Noam Monheit

1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

  • View
    223

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

1

A presentation on A presentation on DirectXDirectX®®

Alex BrillAlex BrillEmil ElazarEmil ElazarNoam MonheitNoam Monheit

Page 2: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

2

Contents

What is DirectX? Historical Problem and it’s Solution Terminology Brief Components Description DirectX Versions History

How DirectX really works? Architecture Direct3D in Details

DirectX Alternatives OpenGL Advantages & Disadvantages or: “Why DirectX”?

Installation + SDK Demo + Code Examples

Page 3: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

3

What is DirectX? (1)

The Problem: Dos vs. Windows 3.1 overhead. The PC architecture was never designed as a gaming

platform. Machine can be VERY different from another.

The will: Windows a desirable platform for game development. Fast, low-level libraries to allow the developer maintain

creative freedom over his games. Shift the burden of hardware support from the game

developer to the hardware manufacture. Coexist peacefully with other Windows components.

Page 4: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

4

What is DirectX? (2)

The Solution: DirectX

Direct access to Hardware…

A common standard which all games and multimedia applications could follow – a common interface with whatever hardware is installed in the PC.

Provides real-time multimedia and gaming services to programs: graphics, sound, music, input (mouse / keyboard / joystick / etc), networking, and movie playback.

Done by three Microsoft employees—Craig Eisler, Alex St. John, and Eric Engstrom.

Page 5: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

5

What’s DirectX? (3)

There are two parts to DirectX; the 'runtime' and the 'SDK' (Software Development Kit). Both are free; the runtime is what players need to have on their computers in order to play a game, and the SDK is what a programmer needs to create games that use DirectX.

Windows XP comes with the DirectX 8 runtime automatically installed; it's a 4 MB download if players don't have it.

The SDK, is over 100 MB to download, and it contains all the headers and libraries you need, plus documentation, samples, tutorials, and tools. Players don't need the SDK, only the runtime.

Most games for Windows nowadays use DirectX in some form or another; it is also the technology which powers Microsoft's XBox.

Page 6: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

6

What is DirectX? (4)

Page 7: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

7

Terminology (1)

API (application program interface)- Set of routines, protocols, and tools for building software applications. Saves the programmer from dealing with implementation.

Driver- Program that controls a device. Acts like a translator between the device and programs that use the device.Each device has its own set of specialized commands that only its driver knows. In contrast, most programs access devices by using generic commands. The driver, therefore, accepts generic commands from a program and then translates them into specialized commands for the device.

Page 8: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

8

Terminology (2)

Sound Card- Enables the computer to output sound through speakers connected to the board, record sound input from a microphone connected to the computer, and manipulate sound stored on a disk.

Video Adapter- A board that plugs into a PC to give it display capabilities.Modern video adapters contain memory, so that the computer's RAM is not used for storing displays. In addition, most adapters have their own graphics coprocessor for performing graphics calculations. These adapters are often called graphics accelerators.

Page 9: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

9

Terminology (3)

Graphics Accelerator- Type of video adapter that contains its own processor to boost performance levels.

These processors are specialized for computing graphical transformations, so they achieve better results than the general-purpose CPU used by the computer.

In addition, they free up the computer's CPU to execute other commands while the graphics accelerator is handling graphics computations.

Other characteristics that differentiate graphics accelerators: memory : Amount of memory determines resolution and colors amount.

Two types of memory-DRAM or video RAM (VRAM), which enables the video circuitry and the processor simultaneously access the memory.

bus : 1995: PCI bus, nowadays; PCIExpress bus. register width: The wider the register, the more data the processor can

manipulate with each instruction. 64-bit accelerators are already becoming common, and we can expect 128-bit accelerators in the near future.

Page 10: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

10

Terminology (4)

GDI- Graphical Device Interface, a Windows standard for representing graphical objects and transmitting them to output devices, such as monitors and printers.

HEL, HAL, COM and more to be discussed later…

Page 11: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

11

DirectX Components

DirectX GraphicsDirectX Graphics DirectDrawDirectDraw Direct3DDirect3D

DirectInputDirectInput DirectPlayDirectPlay DirectAudioDirectAudio

DirectSoundDirectSound DirectMusicDirectMusic

DirectShowDirectShow DirectSetupDirectSetup

Page 12: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

12

DirectX Components (1)

DirectX GraphicsDirectX Graphics DirectDraw-DirectDraw- A software interface that provides direct access to display A software interface that provides direct access to display

devices while maintaining compatibility with the GDI and for transferring devices while maintaining compatibility with the GDI and for transferring video processing from a PC's CPU to the video adapter.video processing from a PC's CPU to the video adapter.

The standard was first developed by Intel and called the The standard was first developed by Intel and called the Display Control Display Control Interface (DCI)Interface (DCI) and later supported by Microsoft. and later supported by Microsoft.

When the CPU is not busy, the GDI updates the video display. If the CPU is When the CPU is not busy, the GDI updates the video display. If the CPU is busy, the DCI driver allows an application to send update information busy, the DCI driver allows an application to send update information directly to the videodirectly to the video adapter.adapter.

Direct3D-Direct3D- An API for manipulating and displaying three-dimensional An API for manipulating and displaying three-dimensional objects. Developed by Microsoft, Direct3D provides programmers with a objects. Developed by Microsoft, Direct3D provides programmers with a way to develop 3-D programs that can use whatever graphics acceleration way to develop 3-D programs that can use whatever graphics acceleration device is installed in the machine. Virtually all 3-D accelerator cards for PCs device is installed in the machine. Virtually all 3-D accelerator cards for PCs support Direct3D.support Direct3D.

Another 3-D standard offering similar functionality is Another 3-D standard offering similar functionality is OpenGLOpenGL. .

Page 13: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

13

DirectX Components (2)

DirectInput-DirectInput- Enables an application to retrieve data Enables an application to retrieve data from input devices even when the application is in the from input devices even when the application is in the background.background.

Also provides full support for any type of input device, Also provides full support for any type of input device, as well as for force feedback. as well as for force feedback.

DirectPlay-DirectPlay- A media-independent networking API that A media-independent networking API that provides networking services at the transport protocol provides networking services at the transport protocol and session protocol levels. DirectPlay sessions can and session protocol levels. DirectPlay sessions can be run on TCP/IP networks, IPX networks, and over be run on TCP/IP networks, IPX networks, and over directly connected modems and serial cables. directly connected modems and serial cables.

Page 14: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

14

DirectX Components (3)

DirectX AudioDirectX Audio DirectSound-DirectSound- Enables the playing of Enables the playing of

sounds with very low latency and gives sounds with very low latency and gives applications a high level of control over applications a high level of control over hardware resources. hardware resources.

DirectMusic-DirectMusic- In combination with In combination with DirectSound, DirectMusic provides a DirectSound, DirectMusic provides a complete solution for playing music and complete solution for playing music and sound effects in games and other sound effects in games and other applications.applications.

Page 15: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

15

DirectX Components (4)

DirectShow-DirectShow- An architecture for streaming An architecture for streaming media on a Windows platform. It provides media on a Windows platform. It provides high-quality capture and playback of high-quality capture and playback of multimedia streams. Screeen Saver, Camera..multimedia streams. Screeen Saver, Camera..

DirectSetup-DirectSetup- Extremely simple library of Extremely simple library of functions for installing DirectX on a machinefunctions for installing DirectX on a machine..

It also provides a way to check the version of It also provides a way to check the version of DirectX that is presentDirectX that is present..

Page 16: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

16

Versions (1)

For each new version of DirectX, Microsoft updated the technology such that the new dll's can communicate with the hardware faster and more efficiently with minimum latency.

They’re trying to support the latest features of graphics and sound cards that come on the market.

The architecture is updated so as to suit the needs of the day while maintaining backward compatibility.

Page 17: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

17

Versions (2)

DirectX 1.0 released on late 1995.

DirectX 6 2 independent SDK's (DirectX SDK and DirectX Media SDK).

DirectX 7 DirectShow- the significant part of Media SDK, merged into

the DirectX API and DirectX Media deprecated. DirectX 8

DirectDraw and Direct3D merged into a single DirectX Graphics API for graphics programming.

DirectSound and Direct Music merged together as DirectX Audio for sound programming.

Programmable Pixel Shader and Vertex Shader introduced.

Page 18: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

18

Versions (3)

DirectX 9 HLSL (High Level Shader Language), a powerful new

programming model that offers the easiest to use graphics creation toolset for developers introduced.

DirectX10– Part of Windows Vista. No backward compatibly except via a software layer. Much faster DLL’s Departure from driver model of DirectX 9.0, with the addition

of a scheduler and memory virtualization system. DirectX 10 will forego the current DirectX practice of using

"capability bits" to indicate which features are active on the current hardware. Instead, DirectX 10 will define a minimum standard of hardware capabilities which must be supported for a display system to be "DirectX 10 compatible".

Page 19: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

19

Versions (4)

Which version of DirectX do various versions of Windows come with?

95 None95B DX 3(Supports up to DX8)NT DX2NT w/SP 4 DX398 DX598SE DX6ME DX7.12000 DX7.1XP DX8.1

Page 20: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

20

ScreenshotsWolfenstein (3D Realms 1992 –> no HAL):

Page 21: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

21

DirectX in details

Page 22: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

22

DirectX – COM objects

DirectX is a set of APIs, available as COM objects. Component Object Model (COM) is a Microsoft

platform for software componentry introduced by Microsoft in 1993. It is used to enable cross-application communication and dynamic object creation in any programming language that supports the technology.

All DirectX Interfaces inherit from IUnknown and are COM compliant.

IUnKnown: AddRef() Release() QueryInterface()

Reference counting

Page 23: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

23

Backward Compatibility (1)

COM allows Microsoft release an enhanced set of DirectX components that are completely compatible with earlier versions of DirectX.

With COM’s independence of a programming language, developers are free to choose whatever COM compliant language and development environment they wish.

With COM’s programming model, the programmer is assured that even if the user upgrades or changes hardware configuration and DirectX drivers, the software will work without reconfiguration.

Page 24: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

24

Backward Compatibility (2)

For example, even though DirectDraw was erased from the DirectX API components after DirectX 7 even in DirectX9, you can access the old interfaces through a DirectDraw7 call.

This backward compatibility plays a significant role in DirectX's position as a leading API, as it helps the applications written in older versions to still work smoothly in the newer versions.

Page 25: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

25

How it really works?

DirectX provides the interface to access the advanced features of the display adapter, which are not provided in the standard Windows GDI graphics interface.

It accesses the hardware abstraction layer in Windows directly.

When DirectX was introduced, display adapter vendors were quick to develop DirectX drivers that would expose low-level functions of their hardware to the application.

Page 26: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

26

Architecture

Each chip manufacturer, board producer, or OEM implements a HAL which implements only device-dependent code and performs no emulation.

The HAL is implemented using 32-bit code with Microsoft Windows XP, Microsoft Windows NT, and Windows 2000. Windows 98 and Windows Millennium Edition (Windows Me) use a combination of 16-bit and 32-bit code.

The HAL can be part of the display driver or a separate dynamic-link library (DLL) that communicates with the display driver through a private interface that the driver's creator defines.

HAL is based around the hardware support, and is very fast but might not support everything

Page 27: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

27

Architecture

When DirectX is initialized, it checks the hardware to see if the hardware supports certain capabilities. If the hardware does support a certain capability, then the HAL will be used to access that hardware function; otherwise, the HEL will be used to emulate the capability through software.

HEL bypasses the hardware and implements its own functionality.

HEL uses no hardware acceleration. It uses the CPU, software, and normal system RAM. It is usually MUCH slower, but much less problematic

Page 28: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

28

Architecture

Page 29: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

29

3D - Graphics

Rendering - the process of generating an image from a model, by means of a software program .

Page 30: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

30

3D - Graphics

The Application is your game and is where you do any scene management and any tessellation of mesh etc.

You then feed the graphics card with vertices and other data.

The graphic card processes the vertices by transforming and lighting them using the matrices supplied by the application.

The card then culls any invisible polygons and clips to the viewport.

This transformed data is then rasterized and passes through the pixel operations

The data is displayed.

Page 31: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

31

3D - Graphics

Page 32: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

32

Some terms…

Rasterisation - The task of taking a two-dimensional image described in a vector format and converting it into pixels or dots for output on a video display or printer.

A tessellation (tiling) of the plane is a collection of plane figures that fill the plane with no overlaps and no gaps. A shader is a program used to determine the

final surface properties of an object or image.

Page 33: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

33

Programmable Pipeline

One of the most important new features in DirectX Graphics is the addition of a programmable pipeline.

It provides an assembly language interface to the transformation and lighting hardware (vertex shader) and the pixel pipeline (pixel shader).

This programmable pipeline gives the developer a lot more freedom to do things, which have never been seen in real time applications before.

The shader code is loaded into the graphics card memory and plugged directly into the graphics pipeline. Shader code is in assembly however nowadays there are a number of higher level 'C' type languages that can be compiled down to the assembly and making them much easier to program.

Microsoft have HLSL (High-Level Shading Language) for use with DirectX and OpenGL has the GLSL (OpenGL Shading Language).

Page 34: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

34

Programmable Pipeline

When you push vertices through the pipeline, they need to be transformed and lit.

This processing stage is known as T&L.

Hardware vertex processing means this is done in hardware, if hardware supports it;

Software vertex processing is done in software.

The general practice is to try creating a Hardware T&L device. If that fails try Mixed, and if that fails try Software. (If software fails, give up and exit with an error).

Page 35: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

35

DirectX - Conclusion

DirectX gives multimedia applications greater access to advanced features of high-performance hardware such as 3D graphics acceleration chips and sound cards.

It controls 2D graphics acceleration; 

Support for input devices: joysticks / joy-pads, keyboards, mice, controls sound mixing and sound output on a vast range of audio hardware, controls networking and multiplayer gaming, and control over various multimedia streaming formats.

Page 36: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

36

DirectX Alternative (1)

Open Graphics Library is a specification defining

a cross-language cross-platform API for writing applications that produce 3D computer graphics (2D computer graphics as well). The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives.

Page 37: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

37

DirectX Alternative (2)

The OpenGL specification is overseen by the OpenGL Architecture Review Board (ARB), which was formed in 1992. The ARB consists of a set of companies with a vested interest in creating a consistent and widely available API.

Page 38: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

38

DirectX Alternative (3)

OpenGL- platform Independent; supported on Windows, Mac, Linux, and several other UNIX variants.

Direct3D- only Windows.

OpenGL- function oriented interface. Direct3D- object oriented interface.

Page 39: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

39

DirectX Alternative (4)

Direct3D- updated very frequently (once a year) and supports the latest card features (Microsoft).

OpenGL- takes some time to reach a new standard (open-standard and a community product, Silicon Graphics).

Performance : Equal performance!!

Page 40: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

40

Where do I start?

If you're worried about which one to learn, and which one the pros use, the answer is that more often than not they'll use both.

Apart from Direct3D, all the DirectX components can be used alongside OpenGL. If you want to use DirectInput for joystick input and OpenGL for your graphics, that's fine.

Page 41: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

41

Games(1)

The 3D engine of the game Battlefield 1942 sits solidly on a DirectX 7 foundation.

Page 42: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

42

Games(2)

Unreal Tournament 2003 uses a number of DirectX 8 shader effects. As a result, the game's graphics look much better than that of older games, and the in-game world seems more alive.

Page 43: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

43

Games(3)

FarCry can be considered the first game that makes consistent use of shaders. Thanks to DirectX 9, the surfaces look very realistic and react to changes in lighting.

Page 44: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

44

Further Reading - Web Resources

General International Game Developers Assoc. - www.igda.org GamaSutra - www.gamasutra.com Game Developer - www.gamedev.net

Direct X MSDN - www.msdn.com/directx Newsgroup -

microsoft.public.win32.programmer.directx.managed The Z Buffer - www.thezbuffer.com Tom Miller (main coder/designer) - blogs.msdn.com/tmiller

Page 45: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

45

Further Reading - DirectX Books

Page 46: 1 A presentation on DirectX® Alex Brill Emil Elazar Noam Monheit

46

The End