• FEATURED

View more

View more

View more

\$49

### Image of the Day Submit

IOTD | Top Screenshots

## DirectX 11 + MinGW-w64

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

9 replies to this topic

### #1Chris_F  Members

Posted 26 January 2012 - 10:45 PM

So I'm having a hard time getting DirectX 11 and MinGW to cooperate. MinGW seems to come with some DX11 headers, but I wasn't able to get anything to compile since it couldn't even seem to find a class definition for ID3D11Device.

With some help online I managed to come up with this:

d3d11-mingw.h
#define __in
#define __out
#define __inout
#define __in_bcount(x)
#define __out_bcount(x)
#define __in_ecount(x)
#define __out_ecount(x)
#define __in_ecount_opt(x)
#define __out_ecount_opt(x)
#define __in_bcount_opt(x)
#define __out_bcount_opt(x)
#define __in_opt
#define __inout_opt
#define __out_opt
#define __out_ecount_part_opt(x,y)
#define __deref_out
#define __deref_out_opt
#define __RPC__deref_out

#include <d3d11.h> //from D3D SDK

#ifdef __uuidof
#undef __uuidof
#endif
#define __uuidof(x) IID_##x

#ifdef DEFINE_GUID
#undef DEFINE_GUID
#endif
#define DEFINE_GUID(id, a, b, c, d, e, f, g, h, i, j, k) const GUID id = { a,b,c, { d,e,f,g,h,i,j,k } };

DEFINE_GUID(IID_ID3D11DeviceChild,0x1841e5c8,0x16b0,0x489b,0xbc,0xc8,0x44,0xcf,0xb0,0xd5,0xde,0xae);
DEFINE_GUID(IID_ID3D11DepthStencilState,0x03823efb,0x8d8f,0x4e1c,0x9a,0xa2,0xf6,0x4b,0xb2,0xcb,0xfd,0xf1);
DEFINE_GUID(IID_ID3D11BlendState,0x75b68faa,0x347d,0x4159,0x8f,0x45,0xa0,0x64,0x0f,0x01,0xcd,0x9a);
DEFINE_GUID(IID_ID3D11RasterizerState,0x9bb4ab81,0xab1a,0x4d8f,0xb5,0x06,0xfc,0x04,0x20,0x0b,0x6e,0xe7);
DEFINE_GUID(IID_ID3D11Resource,0xdc8e63f3,0xd12b,0x4952,0xb4,0x7b,0x5e,0x45,0x02,0x6a,0x86,0x2d);
DEFINE_GUID(IID_ID3D11Buffer,0x48570b85,0xd1ee,0x4fcd,0xa2,0x50,0xeb,0x35,0x07,0x22,0xb0,0x37);
DEFINE_GUID(IID_ID3D11Texture1D,0xf8fb5c27,0xc6b3,0x4f75,0xa4,0xc8,0x43,0x9a,0xf2,0xef,0x56,0x4c);
DEFINE_GUID(IID_ID3D11Texture2D,0x6f15aaf2,0xd208,0x4e89,0x9a,0xb4,0x48,0x95,0x35,0xd3,0x4f,0x9c);
DEFINE_GUID(IID_ID3D11Texture3D,0x037e866e,0xf56d,0x4357,0xa8,0xaf,0x9d,0xab,0xbe,0x6e,0x25,0x0e);
DEFINE_GUID(IID_ID3D11View,0x839d1216,0xbb2e,0x412b,0xb7,0xf4,0xa9,0xdb,0xeb,0xe0,0x8e,0xd1);
DEFINE_GUID(IID_ID3D11RenderTargetView,0xdfdba067,0x0b8d,0x4865,0x87,0x5b,0xd7,0xb4,0x51,0x6c,0xc1,0x64);
DEFINE_GUID(IID_ID3D11UnorderedAccessView,0x28acf509,0x7f5c,0x48f6,0x86,0x11,0xf3,0x16,0x01,0x0a,0x63,0x80);
DEFINE_GUID(IID_ID3D11InputLayout,0xe4819ddc,0x4cf0,0x4025,0xbd,0x26,0x5d,0xe8,0x2a,0x3e,0x07,0xb7);
DEFINE_GUID(IID_ID3D11SamplerState,0xda6fea51,0x564c,0x4487,0x98,0x10,0xf0,0xd0,0xf9,0xb4,0xe3,0xa5);
DEFINE_GUID(IID_ID3D11Asynchronous,0x4b35d0cd,0x1e15,0x4258,0x9c,0x98,0x1b,0x13,0x33,0xf6,0xdd,0x3b);
DEFINE_GUID(IID_ID3D11Query,0xd6c00747,0x87b7,0x425e,0xb8,0x4d,0x44,0xd1,0x08,0x56,0x0a,0xfd);
DEFINE_GUID(IID_ID3D11Predicate,0x9eb576dd,0x9f77,0x4d86,0x81,0xaa,0x8b,0xab,0x5f,0xe4,0x90,0xe2);
DEFINE_GUID(IID_ID3D11Counter,0x6e8c49fb,0xa371,0x4770,0xb4,0x40,0x29,0x08,0x60,0x22,0xb7,0x41);
DEFINE_GUID(IID_ID3D11ClassInstance,0xa6cd7faa,0xb0b7,0x4a2f,0x94,0x36,0x86,0x62,0xa6,0x57,0x97,0xcb);
DEFINE_GUID(IID_ID3D11CommandList,0xa24bc4d1,0x769e,0x43f7,0x80,0x13,0x98,0xff,0x56,0x6c,0x18,0xe2);
DEFINE_GUID(IID_ID3D11DeviceContext,0xc0bfa96c,0xe089,0x44fb,0x8e,0xaf,0x26,0xf8,0x79,0x61,0x90,0xda);
DEFINE_GUID(IID_ID3D11Device,0xdb6f6ddb,0xac77,0x4e88,0x82,0x53,0x81,0x9d,0xf9,0xbb,0xf1,0x40);


Using this, I managed to compile a simple 32-bit hello world DirectX 11 program which sets up a device and swap chain and back buffer. However, if I compile it as 64-bits, it crashes when I call:

DXGI_SWAP_CHAIN_DESC scd;
ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));

scd.BufferCount = 1;
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
scd.OutputWindow = hWnd;
scd.SampleDesc.Count = 4;
scd.Windowed = true;

D3D11CreateDeviceAndSwapChain(NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL, 0,
NULL, 0,
D3D11_SDK_VERSION,
&scd, &swapchain,
&dev, NULL,
&devcon); //crash


Any ideas on how I can get these two to work together better? I [b]really[/d] don't want to have to deal with VC++.

### #2Martins Mozeiko  Members

Posted 27 January 2012 - 02:11 AM

I don't think that you can leave 11th argument NULL.
Also - have you checked that debug logging with DirectX Control Panel doesn't display some obvious error message?

But you really should try using VC++. It's nice IDE, especially when you need to debug code.

### #3kunos  Members

Posted 27 January 2012 - 02:16 AM

[b]really[/d] don't want to have to deal with VC++.

smart move.. and very nice results. congrats.

### #4Chris_F  Members

Posted 27 January 2012 - 03:46 AM

I don't think that you can leave 11th argument NULL.

That wasn't the issue.

But you really should try using VC++. It's nice IDE, especially when you need to debug code.

So, I should drop the compiler I'm used to, the one that is free with outstanding support for C++11 and virtually no bugs, and switch to VC++ Express, a non-optimizing compiler with few C++11 features and several bugs that I've personally encountered? I'm not exactly excited about the thought of that.

Edit: OK, I stand corrected, it's supposedly a "fully optimizing" compiler, but I believe GCC still wins by far when it comes to the performance of the code generated by it's auto vectorization.

smart move.. and very nice results. congrats.

Wow. You are incredibly ignorant and arrogant. Thanks for the help buddy.

### #5mhagain  Members

Posted 27 January 2012 - 07:13 AM

I'd personally just use the one that is known to work.  In the case of D3D11 that's MSVC (as an added bonus you'll have the best debugger in the business available to you too).

I think your performance concerns are somewhat unfounded.  A huge chunk of your runtime performance is going to be going on stuff running on your GPU, and the compiler used for you C/C++ code is completely irrelevant where that's concerned.  Where stuff does run on the CPU, proper and sensible data and code structures will give you much better results than any amount of compiler-side micro-optimizations.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.

### #6clb  Members

Posted 27 January 2012 - 10:41 AM

But you really should try using VC++. It's nice IDE, especially when you need to debug code.

If the original poster wants to discuss DX11 + MinGW64, then by all means, let him have his topic. There's plenty of room for DX11 + VS2010 threads as well.

So, I should drop the compiler I'm used to, the one that is free with outstanding support for C++11 and virtually no bugs, and switch to VC++ Express, a non-optimizing compiler with few C++11 features and several bugs that I've personally encountered? I'm not exactly excited about the thought of that.

Edit: OK, I stand corrected, it's supposedly a "fully optimizing" compiler, but I believe GCC still wins by far when it comes to the performance of the code generated by it's auto vectorization.

Let's not throw in comments based on FUD. GCC is not virtually bug-free: there are 842 outstanding unfixed bugs in the GCC C++ compiler frontend alone. Visual Studio is not bug-free either.

Believing "GCC wins by far in performance" does not make it a correct statement either. It might. Or it might not. Instead of believing, it is better to profile, but unfortunately, there are not that many great sources available that would accurately profile these compilers. Two sources I found
• http://www.g-truc.net/post-0372.html : VC2010 beats GCC by a large margin.
• http://www.willus.com/ccomp_benchmark2.shtml?p1 : GCC beats VC2010 in 6 out of 10 tests.
I do not mean to derail, now please let's stick to the original topic.
Me+PC=clb.demon.fi | C++ Math and Geometry library: MathGeoLib, test it live! | C++ Game Networking: kNet | 2D Bin Packing: RectangleBinPack | Use gcc/clang/emcc from VS: vs-tool | Resume+Portfolio | gfxapi, test it live!

### #7Martins Mozeiko  Members

Posted 27 January 2012 - 10:43 AM

virtually no bugs

You are being silly:
http://gcc.gnu.org/b...&resolution=---
http://gcc.gnu.org/b...&resolution=---
http://gcc.gnu.org/b...&resolution=---
http://gcc.gnu.org/b...&resolution=---

Every software has a bugs. And GCC is no exception from that. I develop with both - gcc and msvc compilers. And both have bugs. Different ones, of course, but they have bugs. Actually in my experience GCC has far more bugs (and worse ones) than MSVC.

### #8Chris_F  Members

Posted 27 January 2012 - 11:01 AM

Well, I have yet to encounter any serious bug myself in the latest GCC, and with the rate at which new versions and bug fixes are released, I wouldn't expect it to be much of a problem if I did. Visual Studio? Well, if you find a bug (which I have, several), you can wait a couple years and hope their next product comes with a fix. And that doesn't even address the overwhelming lack of support for C++11.

In any case I shouldn't have to defend my personal preference for what is a great compiler. Visual Studio isn't even available on the other platforms I use, and MinGW makes working in Windows easy and consistent. There is really no reason somebody shouldn't be able to compile D3D11 applications with it.

### #9mhagain  Members

Posted 28 January 2012 - 10:22 AM

Visual Studio isn't even available on the other platforms I use

Nor is D3D11. Problem goes away.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.

### #10martycm  Members

Posted 31 January 2012 - 10:54 AM

Hi I have the solution to your problem.

I done the same thing a few months back.
What I had to do was download the official windows dx sdk and put the defines as you have done above.
I then had to get the directx dll files and use this
http://sourceforge.n...w64/wiki/gendef
And then from that I created library files to link with.

Lucky for you ruben seems to have added this to his latest personal build.

http://sourceforge.n...ubenvb/4.7.0-1/
Get the gcc build

Sample Program Follows

http://pastebin.com/QKwyL7Ph

Best of luck.. post back if you run into any problems

EDIT:

forgot to post compile and link parameters..

compile

-municode
-mwindows

-ld3d11
-ld3dx11_43
-lgdi32

Also
http://orwellengine.blogspot.com/

Devcpp for mingw64 if you want a nice old style low memory consumption ide.
Although I use programmers notepad myself

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.