Thread: Is all of DirectX aside from managed, pure C?

  1. #1
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901

    Is all of DirectX aside from managed, pure C?

    I just started reading a book on DirectX 10 and when I get to the code it's mainly C style. While I'll take any DirectX I can get, I don't like the idea of functions acting on structures as disconnected classes, out parameters to functions, typedef structures, etc.

    I was wondering is there a C++ implementation (official, not 3rd party) of directX or is it something I have to live without (or wrap myself).

  2. #2
    Registered User
    Join Date
    May 2007
    Posts
    147
    Any good graphics/gaming engine will provide a C++ interface for the underlying graphics API, often with the feature of choosing DirectX or OpenGL.

    DirectX is a C level API. That's all there is to that.

    Engines like Irrlicht, Oolong, Crystal - some free, some not, many open source, do provide such a wrapper. For a rather thorough discussion of the topic pick up one of David Eberly's texts on making graphics/gaming engines. His WildMagic engine is open source and downloadable, rather complete, supports compile time selection of DirectX or OpenGL (or a software renderer), and exhibits modern engine design techniques (along with physics, special effects, etc).

    The main problem of coding directly to any such API is the general subject of portability. Not all customers are going to have DirectX10 capable OS/Hardware. Portability doesn't necessarily mean Linux/Windows/OpenGL/DirectX, but means, equally, DirectX9 -> DirectXn, OpenGL 1.5 -> OpenGL 3.0.

    You have correctly reacted to a C API, as a C++ developer. You've responded by a desire to encapsulate the C level access - take it to the logical extension and abstract the entire concept.

    Eberly's text is one of many, rather detailed and well reasoned, even if the WildMagic engine has some, perhaps, objectionable choices (like reject the STL). His reasoning is sound, though, and he is an experienced developer in the industry (and a PhD in math).

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    DirectX in it's purest form is not actually C or C++. It is composed of COM objects which is a Microsoft-created binary standard which is like C++ but is not true C++.

  4. #4
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I see. It's no biggie, my main concern are the naming conventions and the whole input as output nature of the basic functions. I've only started rading the book and just getting into it, so I guess it'll grow on me. here's to my second try at 3d programming.

  5. #5
    Registered User
    Join Date
    May 2009
    Posts
    37
    Maybe I'm missing something but I'm using stock DX9 from one of Frank Luna's books and there are definately C++ function calls.

  6. #6
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    Quote Originally Posted by SyntaxError View Post
    Maybe I'm missing something but I'm using stock DX9 from one of Frank Luna's books and there are definately C++ function calls.
    I meant using classes, having member functions. for example the D3DXMATRIX is a struct with some operators defined on it, but to invert, transpose, receive the identity, you must use non-member functions which take a reference to the in and out of the objects and work that way, as opposed to encapsulating.

    I'll just be encapsulating as I see it, adding it to my own helper classes, but I was just wondering.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by SyntaxError View Post
    Maybe I'm missing something but I'm using stock DX9 from one of Frank Luna's books and there are definately C++ function calls.
    It's all Microsoft's COM language, which was intended as a "universal" language, like being able to be used from all of Microsoft's languages (like today's dotNet).
    So as Bubba says, it's technically neither C nor C++. It's COM, simply put.
    C and C++ have slightly different ways of using it, though.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    May 2009
    Posts
    37
    Quote Originally Posted by Elysia View Post
    It's all Microsoft's COM language, which was intended as a "universal" language, like being able to be used from all of Microsoft's languages (like today's dotNet).
    So as Bubba says, it's technically neither C nor C++. It's COM, simply put.
    C and C++ have slightly different ways of using it, though.
    As far as I know COM isn't a language. It's a binary interfaces standard so you can use objects over different processes or even over the network. In any case I'm not sure it matters what happens underneath. If it looks like C++ and acts like C++, it's C++. Here's a quote from one of my old com books:

    "In a fortuitous design decision, the memory layout for a COM interface is the same as the memory layout that the C++ compiler generates for an abstract base class. Therefore we can use abstract base classes to define our COM interfaces"

    As with most Microsoft stuff a lot of COM is just renaming of old concepts.

  9. #9
    Registered User
    Join Date
    May 2009
    Posts
    37
    Quote Originally Posted by indigo0086 View Post
    I meant using classes, having member functions. for example the D3DXMATRIX is a struct with some operators defined on it, but to invert, transpose, receive the identity, you must use non-member functions which take a reference to the in and out of the objects and work that way, as opposed to encapsulating.

    I'll just be encapsulating as I see it, adding it to my own helper classes, but I was just wondering.
    Yeah OK. My guess is they do that because there tends to be extra copying that happens when using classes as first class objects unless you are very careful designing your class and members and are also careful how you use them. Not providing full first class functionality naturally forces programmers to do things more efficiently. I'm not really endorsing the idea but I think that may be the motivation.
    Last edited by SyntaxError; 05-25-2009 at 02:33 PM.

  10. #10
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Not all of D3DX is COM objects but some of it is. Anything with an I preface is a COM interface. The other objects are more likely just C++ objects. But D3DX should not be confused with DirectX nor Direct3D. D3DX is an add-on provided by Microsoft that is quite popular with the hobbyist crowd but not so much with the professionals. The math portions of D3DX were programmed by Intel and AMD for the respective chips and chipsets so to be sure those are fast. I'm not sure how fast the skinning is in relation to professional code but in my estimation D3DX skinning leaves a lot to be desired.

    Direct3D is pure COM and DirectX (DirectSound,DirectInput, etc.) is pure COM. COM is not C/C++. COM is an old solution to the language interop problem and while it is not perfect it does work. It's also known as ActiveX. Most of COM will most likely be replaced by .NET if and when the .NET framework actually begins to take hold.

  11. #11
    Hail to the king, baby. Akkernight's Avatar
    Join Date
    Oct 2008
    Location
    Faroe Islands
    Posts
    717
    The rumour is that DirectX 11 actually moves to C++, and I understood it as pure C++...
    I'm making a DirectX 10 engine (mainly for the learning) and DirectX works fine with C++ code, so I don't see an issue at all, unless you want to mangle with the API code itself...
    Currently research OpenGL

  12. #12
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    DirectX must be COM or adhere to a non-language specific standard.

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I also sincerely doubt DX will move away from COM myself. It would break backwards compatibility, and Microsoft has been burned several times from that already and they probably won't do it again unless there is a seriously good reason.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calling IRichEditOle interface methods
    By Niara in forum C Programming
    Replies: 2
    Last Post: 01-16-2009, 01:23 PM
  2. DirectSound header issues
    By dxfoo in forum C++ Programming
    Replies: 0
    Last Post: 03-19-2006, 07:16 PM
  3. Replies: 3
    Last Post: 09-11-2005, 10:13 AM
  4. Managed DirectX Programming Books (C# only!)
    By Grayson_Peddie in forum Game Programming
    Replies: 0
    Last Post: 05-05-2003, 02:54 PM
  5. Information Regarding Pure Virtual Functions
    By shiv_tech_quest in forum C++ Programming
    Replies: 6
    Last Post: 01-29-2003, 04:43 AM