Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DirectX programming in C?

Tags:

c

directx

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.

Thanks.

like image 794
Fouf Avatar asked Jan 14 '11 21:01

Fouf


People also ask

Can you use DirectX in C?

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++.

Is DirectX written in C or C++?

A Windows desktop app with DirectX is an app developed using native C++ and DirectX APIs. This model is more complex than an app written in a managed framework, but it provides greater flexibility and greater access to system resources especially graphics devices.

How do I use DirectX?

To get started, click the Start menu and type “dxdiag.” Press Enter to open the DirectX Diagnostic Tool. The first time you run the tool, you will be asked whether you want to check to see if your video drivers have been signed by Microsoft. Go ahead and click Yes. The tool will not change the drivers you're using.


2 Answers

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.

like image 84
Alexey Frunze Avatar answered Sep 28 '22 06:09

Alexey Frunze


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!

like image 32
David Heffernan Avatar answered Sep 28 '22 08:09

David Heffernan