Directx Is Implemented As a Collection of COM Objects to Use A

Directx Is Implemented As a Collection of COM Objects to Use A

GAM666 – Introduction To Game Programming DirectX Programming Introduction ● 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 GAM666 – Introduction To Game Programming COM Overview ● 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 GAM666 – Introduction To Game Programming COM Overview ● 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) GAM666 – Introduction To Game Programming COM Overview 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) GAM666 – Introduction To Game Programming COM Overview ● 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 GAM666 – Introduction To Game Programming COM Overview 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 GAM666 – Introduction To Game Programming COM Overview ● 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 GAM666 – Introduction To Game Programming DirectX 7 Overview ● 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 GAM666 – Introduction To Game Programming DirectX 7 Overview ● 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.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    9 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us