GAM666 – Introduction To Game Programming ● DirectX is implemented as a collection of COM...
-
Upload
francine-burns -
Category
Documents
-
view
214 -
download
0
Transcript of GAM666 – Introduction To Game Programming ● DirectX is implemented as a collection of COM...
![Page 1: GAM666 – Introduction To Game Programming ● DirectX is implemented as a collection of COM objects ● To use a DirectX program, the user must have the correct.](https://reader036.fdocuments.in/reader036/viewer/2022082714/5697bf711a28abf838c7e402/html5/thumbnails/1.jpg)
GAM666 – Introduction To Game Programming
●DirectX is implemented as a collection of COM objects●To use a DirectX program, the user must have the correct (or later) version of DirectX installed (e.g. by doing Windows Update)●To program a DirectX program, the programmer must have the correct (or later) version of the DirectX SDK installed (from MSDN) in addition to the compiler
DirectX Programming Introduction
![Page 2: GAM666 – Introduction To Game Programming ● DirectX is implemented as a collection of COM objects ● To use a DirectX program, the user must have the correct.](https://reader036.fdocuments.in/reader036/viewer/2022082714/5697bf711a28abf838c7e402/html5/thumbnails/2.jpg)
GAM666 – Introduction To Game Programming
●COM (Component Object Model) is one of Microsoft's ways of making objects at the operating system level [the other way is .NET]●COM builds on DLL (dynamically linked library) technology, which is a way to store precompiled functions for linking at runtime rather than compile time●COM objects can be accessed from any language supporting COM
COM Overview
![Page 3: GAM666 – Introduction To Game Programming ● DirectX is implemented as a collection of COM objects ● To use a DirectX program, the user must have the correct.](https://reader036.fdocuments.in/reader036/viewer/2022082714/5697bf711a28abf838c7e402/html5/thumbnails/3.jpg)
GAM666 – Introduction To Game Programming
●Every COM object exposes one or more Interfaces (collection of methods to control the object)●Usually, when a new version of a COM object is released, the old interfaces are retained, and new features are implemented by creating new interfaces●This allows the object to be upgraded while still allowing programs that use the older versions to run correctly (assuming the new version doesn't break the old interfaces)
COM Overview
![Page 4: GAM666 – Introduction To Game Programming ● DirectX is implemented as a collection of COM objects ● To use a DirectX program, the user must have the correct.](https://reader036.fdocuments.in/reader036/viewer/2022082714/5697bf711a28abf838c7e402/html5/thumbnails/4.jpg)
GAM666 – Introduction To Game Programming
Every COM interface implements at least the following three methods:●QueryInterface() – allows you to get any of the other interfaces, using the interface's ID●Release() – tells COM that you are finished using this instance of the interface so that it can be removed from memory if nothing else is using it (like C++ delete)●AddRef() – tells COM that you have just made a copy of the interface instance (which will later be Released)
COM Overview
![Page 5: GAM666 – Introduction To Game Programming ● DirectX is implemented as a collection of COM objects ● To use a DirectX program, the user must have the correct.](https://reader036.fdocuments.in/reader036/viewer/2022082714/5697bf711a28abf838c7e402/html5/thumbnails/5.jpg)
GAM666 – Introduction To Game Programming
●Every COM object has an interface IUnknown with the three required methods [QueryInterface(), Release() and AddRef()]●This allows the programmer a predictable way to get any interface the object has (presuming the programmer knows the interface ID), in case a specialized function to obtain the interface doesn't exist
COM Overview
![Page 6: GAM666 – Introduction To Game Programming ● DirectX is implemented as a collection of COM objects ● To use a DirectX program, the user must have the correct.](https://reader036.fdocuments.in/reader036/viewer/2022082714/5697bf711a28abf838c7e402/html5/thumbnails/6.jpg)
GAM666 – Introduction To Game Programming
Libraries (such as parts of the DirectX SDK) often have functions to instantiate desired interfaces. Alternately:●CoInitialize() can be used to initialize the generic COM access library●Then, CoCreateInstance() can be used to instantiate a particular interface of a particular COM object●If CoInitialize() is used, then CoUninitialize() must be called before the program ends
COM Overview
![Page 7: GAM666 – Introduction To Game Programming ● DirectX is implemented as a collection of COM objects ● To use a DirectX program, the user must have the correct.](https://reader036.fdocuments.in/reader036/viewer/2022082714/5697bf711a28abf838c7e402/html5/thumbnails/7.jpg)
GAM666 – Introduction To Game Programming
●When a COM object is installed on a computer, GUIDs (Globally Unique Ids) for the object (CLSID) and its interfaces (IID) are stored in the system registry●A GUID (aka UUID – Universally Unique ID) is a 128-bit number●There are utilities to create a GUID that will [probably, to a high degree of certainty] be unique●GUIDs are used to identify much of the hardware and software installed on your PC
COM Overview
![Page 8: GAM666 – Introduction To Game Programming ● DirectX is implemented as a collection of COM objects ● To use a DirectX program, the user must have the correct.](https://reader036.fdocuments.in/reader036/viewer/2022082714/5697bf711a28abf838c7e402/html5/thumbnails/8.jpg)
GAM666 – Introduction To Game Programming
●DirectX 7 still often used for 2D games●DirectDraw (2D graphics) was rolled into DirectX Graphics (mostly 3D graphics) starting with DirectX 8 to encourage developers to move to 3D●DirectX 7 uses some techniques that were simplified starting with DirectX 8 but which you should be prepared to encounter if maintaining legacy code
DirectX 7 Overview
![Page 9: GAM666 – Introduction To Game Programming ● DirectX is implemented as a collection of COM objects ● To use a DirectX program, the user must have the correct.](https://reader036.fdocuments.in/reader036/viewer/2022082714/5697bf711a28abf838c7e402/html5/thumbnails/9.jpg)
GAM666 – Introduction To Game Programming
●Sample1 shows how to create a DirectDraw7 object and query it for available resolutions●The user is presented with a choice of resolutions, after which the screen resolution is changed●Technique of querying the DD7 object is a typical Windows “enumeration”, where the logic for handling one possibility is coded in a function whose address is given to Windows, and which Windows calls as many times as necesary
DirectX 7 Overview