DirectX programming in C?

后端 未结 5 861
鱼传尺愫
鱼传尺愫 2021-01-02 09:09

In the past I have created DirectX applications in the C++ programming language, however, I would like to know if it is possible to do this using the C programming language.

相关标签:
5条回答
  • 2021-01-02 09:31

    The Open Watcom C/C++ compiler comes with DirectX sample applications in both C++ and C. Both work. They are under WATCOM\samples\directx\cpp and WATCOM\samples\directx\c respectively in OW 1.9.

    This is what the code looks like in C++:

    hr = d3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dcaps9);
    hr = d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm);
    hr = d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, game_window, D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED, &d3dpp, &d3d_dev);
    

    And in C:

    hr = IDirect3D9_GetDeviceCaps(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dcaps9);
    hr = IDirect3D9_GetAdapterDisplayMode(d3d, D3DADAPTER_DEFAULT, &d3ddm);
    hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, game_window, D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED, &d3dpp, &d3d_dev);
    

    You don't need to do anything special with COM in C as there seem to be enough macros defined that you can just use.

    0 讨论(0)
  • 2021-01-02 09:36

    I think that the DirectX libraries have some C++ only components (it's been a while since I've used it and from last I remember it contains classes). Might as well make your life a little easier and do it in C++.

    0 讨论(0)
  • 2021-01-02 09:38

    It is possible, but because you lack the higher level functions C++ provides you are making it harder for yourself.

    0 讨论(0)
  • 2021-01-02 09:40

    You can use DirectX in C. It has specific macros to simplify the use of the COM interface. However, it's much easier to use C++.

    0 讨论(0)
  • 2021-01-02 09:48

    Yes it is possible. DirectX exposes a COM interface and C is capable of consuming them. It won't be a whole boat load of fun though!

    0 讨论(0)
提交回复
热议问题