Programming DirectX in C?

In the past, I created DirectX applications in the C ++ programming language, but I would like to know if this can be done using the C programming language.

Thanks.

+4
source share
4 answers

Yes it is possible. DirectX provides a COM interface, and C is capable of using them. It will not be a full load on the boat, though!

+10
source

The Open Watcom C / C ++ component comes with sample DirectX 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.

Here's 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 have to do anything special with COM in C, as there seem to be enough macros that you can just use.

+5
source

You can use DirectX in C. It has certain macros to make it easier to use the COM interface. However, it is much easier to use C ++.

+2
source

I think that there are some only C ++ components in DirectX libraries (some time has passed since I used it, and from the last moment I remember that it contains classes). It is also possible to make your life a little easier and do it in C ++.

0
source

Source: https://habr.com/ru/post/1335613/


All Articles