DirectX vs. OpenGL revisited

Add comment!

January 27th, 2010

My post about reasons to use OpenGL instead of Direct3D got a much greater response than I expected, making the front page of Digg, Reddit, Slashdot, and even the OpenGL website! The vast majority of reactions were positive, but there were a few Direct3D users who posted negative comments which I will address in this post. It's clear that I put in too many distractions from my main points, which are as follows:

By supporting OpenGL you reach a much larger desktop gaming audience, avoid getting locked into proprietary standards, and promote healthy API competition.

Even if Direct3D were easier to use and had a head start on features, these reasons would still be sufficient for me to support OpenGL.

Should everyone use OpenGL? No, if you are developing a console exclusive, or an XBox game with a cheap Windows port, then there is little reason to think about OpenGL. However, if you're developing a home computer game, or a console game with a serious home computer port, then OpenGL is the most logical starting point for your graphics abstraction layer. This way you can start testing on as many platforms as possible from the very beginning -- a well-known best practice which enforces a high-quality cross-platform development path, ensuring that compatibility issues show up early and can be easily fixed.

The most common complaint about my article was from programmers who find Direct3D easier to use. I personally find OpenGL to be easy to use, but I acknowledge that this is subjective and opinions vary on this topic, just like Vi vs. Emacs or Mac OS vs Windows. It's useless to debate opinions like this. If we take a larger view, the core functionality of Direct3D and OpenGL are so similar that they are essentially identical, and the differences in the API should be irrelevant to any experienced programmer. The most important differences are that one is an open standard, and the other proprietary, and that one works on every desktop platform, and the other does not.

Here are some more specific responses to comments from DirectX supporters: I'm trying to get to all of them, so this will be long -- feel free to skip this if you're not interested! The large bold-face text shows comments on the last post, and the smaller text is my response.

DirectX has free debugging and optimization tools on Windows, like PIX and NVPerfHUD. OpenGL has no tools!

On Mac OS X, we have a whole suite of free OpenGL tools including the profiler, driver monitor, and shader builder. On Windows and Linux there is the NVIDIA PerfKit, as well as AMD's GPU PerfStudio and ShaderAnalyzer. If anyone has used both sets of tools and is informed about how they compare, please post your experiences in the comments!

While PS3 has an OpenGL wrapper available, developers almost always use libGCM instead! Same for Wii and GX.

You're right! Sorry about that, in my research I was confused by Sony's public statements that OpenGL ES was their standard API which must have been changed by the time it was released, or just been misreported. The developers I've heard from who work on high-performance graphics for PS3 say that they use libGCM because it's closer to the hardware, giving developers complete control of the PS3 hardware and avoiding the CPU overhead of a high-level API. On the other hand, 360 developers all use the high-level Direct3D API, even though it has significant CPU overhead, because there is no alternative. This is irrelevant to the question of whether OpenGL or Direct3D are inherently better; it's an example of the trade-off between low-level optimized code and high-level portable code.

The whole OpenGL vs. Direct3D debate is silly; you should create an abstraction layer that supports all graphics APIs, and use whichever one works better on each platform!

That is definitely the ideal solution! However, if you are aiming for a cross-platform release, it's vital to start testing on all the target platforms from the very beginning. The marginal cost of cross-platform (non-console) development is almost zero if you keep portability in mind from the start, but it's famously difficult to port a finished project. To enforce cross-platform development from the beginning, it often makes sense to start your abstraction layer with OpenGL so you can immediately and frequently test your program on all the desktop platforms, and add the other APIs as needed.

But XBox uses DirectX! If I use DirectX for Windows as well, I save a ton of time!

If you're targeting cross-platform console development, switching between superficial graphics APIs is the least of your worries -- you will be spending much more time dealing with issues like memory management, multiprocessing, streaming from optical disks, optimizing for five-year-old hardware, and meeting vendor certification requirements. In this mountain of work, switching from one API to another is a grain of sand.

On the other hand, the API does make up a significant part of your porting work when porting between identical hardware, such as Windows, Mac and Linux desktop computers. It's significant in this case just because the API is almost the only thing that has to be changed. Supporting Mac and Linux is trivial if you make a habit of using cross-platform libraries like OpenGL, SDL and OpenAL from the start, but very difficult if you use proprietary libraries like Direct3D, DirectInput and XAudio.

OpenGL 3.0 sucked! It was delayed drastically and didn't deliver on its promises!

OpenGL 3.0 was not the revolutionary upgrade that it was hyped to be, but it was still a substantial improvement. OpenGL 3.1 and 3.2 addressed many of the concerns not addressed by 3.0, and it looks like it's on track to keep improving! If more game developers start using OpenGL again, the ARB will have more incentive and ability to keep improving OpenGL's gaming features.

I hated DirectX 9, but DirectX 10 is actually pretty good!

That's great that it's improving! However, since less than half of Windows gamers can run DirectX 10, you will need to write a DirectX 9 renderer anyway.

You freetard microsoft-haters can go choke on your tinfoil hats!!!! OpenGL is dead like PS3 and Mac you n00b hobbyists!!! leave the graphics talk to the grown-ups and keep your mouth shut!!! SERIOUS AAA DEVELOPERS LIKE ME HAVE REAL WORK AND DEADLINES AND NEED DIRECTX 12 RIGHT NOW!!!!

If you want to debate with me, please state your points and back them with evidence. I have no agenda here besides sharing the truth as I see it and encouraging a healthy and open game development scene.

You're just comparing OpenGL and Direct3D, not OpenGL and DirectX. DirectX includes many other libraries, such as netcode, video, sound, and input.

This was true at one point. But now almost all of the DirectX libraries have been deprecated. Microsoft's input and sound APIs are still around in the form of XInput/DirectInput and XAudio 2. However, you you can use them with OpenGL just as easily as you can use them with Direct3D, so they are not really relevant to the question of which graphics API to use. If you would rather have a sound and input solution that's cross-platform and open-source, I would recommend SDL and OpenAL.

Direct3D has built-in functions to load .dds textures and .x models! I can't figure out how to load assets with OpenGL!

You can read and write standard image file formats using FreeImage, and read and write compressed formats using NVIDIA Texture Tools. Most model formats have open specifications, and it's straightforward to write a parser for them, or find source code to load them online. If this kind of thing is really a factor in your choice of graphics APIs, then you would be better off starting with a pre-built game engine instead of writing your own.

Are you saying that AAA developers use DirectX just because they're too stupid to see through Microsoft's bullshot comparison ads? You're the only one who's smart enough to figure it out?

No, of course not. That kind of marketing primarily affects game developers via gamers. Since gamers and game journalists are not graphics programmers, they believe Microsoft's marketing. Then, when the gaming press and public are all talking about DirectX, it starts to make rational short-term business sense for developers to use DirectX and ride Microsoft's marketing wave, even if it doesn't make sense for other reasons.

On the other hand, game developers are directly targeted by DirectX evangelists and OpenGL FUD campaigns. At game developer conferences, the evangelists are paid to shake your hand and deliver painstakingly-crafted presentations and well-tested arguments about why your studio should use DirectX. Since nobody does this for OpenGL, it can be hard to make a fully informed decision. Also, not even the smartest developers could have known that the plans for dropping OpenGL support in Vista were false, or that the terrible Vista beta drivers were not representative of the real ones. It doesn't leave a bad taste in your mouth to be manipulated like this? It sure does for me.

Are these the only reasons why DirectX is so much more popular than OpenGL? No, but they're a significant factors. As I discussed at length in the previous post, there are many network effects which cause whichever API is more popular to keep becoming more popular, so small factors become very large in the long run.

D3D11 tesselation is not the same as the old ATI extension, it's a whole new fixed-function pipeline including awesome hull and domain shaders!

At first I was skeptical for a few reasons. First, the proposed tessellation pipeline achieves the same visible results as the older methods. Second, the trend in graphics hardware is towards a more unified programmable pipeline; adding more fixed-function stages seems like a step backwards, not forwards. Third, ATI cards have had fixed-function tesselation for almost a decade now (including the XBox 360), and it was never really used.

However, now that both major vendors are planning to use the same tessellation pipeline, and are both adding dedicated tesselation hardware, it may start to become important in a few years when these graphics cards are widespread. In this regard, OpenGL is lagging behind DX11. However, I would be very surprised if the OpenGL implementation is not ready long before these cards become popular.

Game developers use DirectX because the "big and fast" money is on the XBox. Even Windows support is basically an afterthought, and Mac and Linux support are considered totally unimportant.

I hadn't thought of it that way, but that's a good point! While it's very difficult to port a PC game to XBox, it's relatively easy to take an XBox game and make a cheap Windows port. If this is all you care about, then it's most efficient to just port the whole game from XBox to Windows using Direct3D 9, and then make an even lower-quality port for Mac by wrapping the Windows version with Cider.

However, desktop gamers are pretty savvy. They can tell when they're being treated like second-class citizens, and will vote against low-quality ports with their wallets.

XNA is the easiest way for novice developers to make games.

I usually recommend that novice developers start by modding, because then you start with a fully-functioning game, and can make fun changes immediately. If you want to transition from modding to making your own programs, I would recommend using Unity or Flixel instead of XNA. They are free, cross-platform, and easy to share online. I've spoken to XNA developers who later regretted using it because they could have found their audience better on another platform, and porting from such a proprietary framework is very difficult.

I think that is all of the concerns I read in the comments -- please let me know if I've missed yours!