Sign in to follow this  
3Ddreamer

OpenGL vs DirectX

Recommended Posts

Hi, everyone [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]


The reason why I am opening this discussion is because the information about these issues is so spread and muddled with opinions. My goal is to more centralize the subject of OpenGL and DirectX for convenience. Also given the blistering fast pace of both OpenGL and DirectX changes in games, I want the latest perspectives.

Both OpenGL and DirectX API based games and simulations, some switchable to either by the user, have been enjoyed and modded by me. Also a given is that both seem to be quite powerful and full featured, advantages and disadvantages for both.

Is OpenGL going to involve more advanced work for the game developer, yet greater flexibility in the long term? Doesn't the hardware accelerated 3D nature of OpenGL offer more potential for game features because software processing could be run simultaneously with hardware acceleration to broaden the game engine base - so to speak? Isn't hardware acceleration offering the most potential for game performance and more 3D objects and 2D textures allowable?


Clinton

Share this post


Link to post
Share on other sites
Well, here is an example of the kind of contradiction that I read: Sources are publishing that DirectX is more software involved than hardware accellerated compared to OpenGL, but some such as yourself are not making the distinction, with all respect.


Clinton

Share this post


Link to post
Share on other sites
And which sources would that be exactly?

You might be confusing some concepts here. When a graphics card does not support some features of the D3D API in hardware a so-called 'Reference Device' can be used by developers which emulates those features in software mostly for debugging purposes as a DX SDK installation is needed.
I believe a software renderer can also be used by D3D if you provide one, but it generally isn't recommended.

In normal situations Direct3D is a library for doing hardware accelerated rendering.

Share this post


Link to post
Share on other sites
[quote name='3Ddreamer' timestamp='1348112191' post='4981908']
Okay, but isn't OpenGL more low level programming compared to DirectX? Isn't DirectX more friendly to scripting languages?


Clinton
[/quote]

There's really no relation between scripting languages and either graphics API. It might be so that there are more wrappers for using DirectX in managed languages, I don't know, but this doesn't have anything to do with the DirectX library itself.

OpenGL is a procedural C API, while D3D is a more-or-less object-oriented API, there is no support for any scripting language out of the box for either API

Share this post


Link to post
Share on other sites
It sounds that you perceive these APIs as completely different beasts. Actually, these are very, very similar. In the end both need to access the gfx card drivers that do the real work. There are differences, but these can be named best as "slightly". DX is considered slightly faster, slightly harder to learn, has slightly less problems with outdated drivers (and all of these points are contested by numerous people, so even at these you won't get a 100% agreement). I again stress the word "slightly". In the end it's mostly about convenience and personal taste of the coder...

The only big difference I can think of is that OpenGL is extremely crossplatform while DX is tied to MS platforms.

Share this post


Link to post
Share on other sites
[quote name='3Ddreamer' timestamp='1348110774' post='4981900']
Well, here is an example of the kind of contradiction that I read: Sources are publishing that DirectX is more software involved than hardware accellerated compared to OpenGL, but some such as yourself are not making the distinction, with all respect.


Clinton
[/quote]

Direct3D has a larger official support library(D3DX) Which is software only ofcourse but the hardware accelerated features are pretty much equivalent. (OpenGL doesn't have any official software support library anymore, (glu and glaux are software support libraries for OpenGL but both are deprecated and horribly out of date) There are tons of third party support libraries to choose from though if you want and Microsoft is deprecating most of its support library for DX with Windows 8, (Pretty much noone uses it for professional games anyway and since the two APIs have become so similar most of the third party support libraries work just fine with both APIs)

Share this post


Link to post
Share on other sites
I'll preface this by saying I am (almost) exclusively an OpenGL user. I found DirectX cumbersome, as I tried to learn it simultaneously with C++ - this was out of a 10 year old book, so I imagine it was something like DX7 and a lot less streamlined. OpenGL automagically [i]worked[/i] for me at the time, so I never honestly looked back. I still kept up with research, however. Ironically, this automagic property of OpenGL has almost universally been deprecated, but I digress.
[quote name='3Ddreamer' timestamp='1348109369' post='4981895']The reason why I am opening this discussion is because the information about these issues is so spread and muddled with opinions. My goal is to more centralize the subject of OpenGL and DirectX for convenience. Also given the blistering fast pace of both OpenGL and DirectX changes in games, I want the latest perspectives.[/quote]Besides choosing one API over the other due to being unable to use the other (say, D3D for working with your favorite engine, or OpenGL for a wii game) there is no objective means of choosing one or the other, and so all you can [i]ever[/i] hope to get is a wide spread and opinion muddled set of responses. I can say that most major game developers favor D3D because it's the traditional API that has been in use for quite some time. Familiarizing yourself with it from a professional game development standpoint is a wise decision... but OpenGL targets dozens of platforms, whereas D3D is quite limited. If you care at all about portability, D3D becomes a very poor choice.

[quote name='3Ddreamer' timestamp='1348109369' post='4981895']Is OpenGL going to involve more advanced work for the game developer, yet greater flexibility in the long term?[/quote]Arguably. OpenGL is very minimalist, especially since 3.1. There are several "handy dandy" things that it simply does not do for you the way D3D does. It's still just as capable of doing them, but OpenGL does not define a default way of doing it (copying a texture to a texture, for instance, requires you to use framebuffers or pixelbuffers - the closest thing, glCopyTexImage2D, draws from the bound buffer) nor is the ARB interested in adding many convenience features. The difference in difficulty between D3D and OpenGL in this regard boils down to an occasional dozen or so lines of code. Not much, but "arguably" more.

It is also arguably more flexible, but only in that it is significantly more portable. Writing linux or mac games in D3D instantly makes WINE necessary at a cost to FPS (as WINE must redirect D3D calls to OpenGL), and I'm not sure if the Wii and PS3 support D3D at all. But while they had significant differences in the past, now they're both effectively equivalent in features. Games using one API do not suffer graphically over another - however, some designers may prefer the "style" or "approach" one API uses over the other, and like me, find it annoying to use the conflicting style.

[quote name='3Ddreamer' timestamp='1348109369' post='4981895']Doesn't the hardware accelerated 3D nature of OpenGL offer more potential for game features because software processing could be run simultaneously with hardware acceleration to broaden the game engine base - so to speak? Isn't hardware acceleration offering the most potential for game performance and more 3D objects and 2D textures allowable?[/quote]They're both hardware accelerated, and most often have very close benchmarks. One might outperform the other at some specific operation or other, but overall there is no speed advantage to either. This is [i]not[/i] an advantage for OpenGL.

Three questions answer which API to use:
--Looking to be familiar with rendering schemes of major AAA titles ? DirectX : Either //neither is better, but traditionally D3D is used. OpenGL is also used, but much less.
--portability matters ? OpenGL : Either //DirectX has no portability
--Prefer OpenGL Style ? OpenGL : DirectX //Purely your opinion

Remember, however, that DirectX is more than D3D. If for whatever reason you hate all DirectSound alternatives (FMOD, OpenAL, ect) or DirectInput alternatives, then DirectX trumps OpenGL by virtue of your project [i]already[/i] using it elsewhere.

Share this post


Link to post
Share on other sites
[quote name='Zouflain' timestamp='1348145699' post='4982008']
It is also arguably more flexible, but only in that it is significantly more portable. Writing linux or mac games in D3D instantly makes WINE necessary at a cost to FPS (as WINE must redirect D3D calls to OpenGL), and I'm not sure if the Wii and PS3 support D3D at all.[/quote]Wii uses a proprietary API ([i]similarly designed to GL[/i]) called GX, and the PS3 has a proprietary API called GCM, which is much more low level than GL or D3D. The PS3 also has a wrapper called PSGL, but this is different to "Desktop GL" and is a translation layer ([i]like Wine's D3D->GL layer[/i]). The 360 has a proprietary API that's quite similar to D3D9.

IMHO, the portability of OpenGL is a bit of a red herring.
On Windows/Linux, the OpenGL runtime is almost entierly implemented by your graphics driver, and there is no governing authority to ensure standards compliance -- it's industry self policing only. This means that vendors can and do violate the standard in ways to hurt each other -- e.g. nVidia drivers accept HLSL syntax in GLSL shaders, with the hopes that developers may ship such shaders, which will appear broken on ATI/Intel GPUs...
On the other hand, Apple keeps a much tighter grip on things (like Microsoft does with D3D), so OpenGL on Apple OS's is going to be a lot more reliable.
So the 3 platforms that GL gives you portability to -- Linux/Windows and Apple -- all actually may behave slightly differently. You still need to test your renderer separately on each platform, and on Windows/Linux, you also need to test your renderer on GPUs from each manufacturer, as each of these tests is against a completely different implementation of the OpenGL runtimes.

Also, if you want to support the latest SM5 GPU features, but also support scaled-down versions of your renderer for SM4 and SM3 GPUs, then you've still got to "port" a lot of your rendering code no matter the API.
On Windows with D3D, you'd have to maintain a D3D11, D3D11_feature_level_10 and a D3D9 version of your renderer.
With GL, you'd have to maintain a GL2, GL3 and GL4 version of your renderer.

So a "cross platform" renderer has to maintain and test code for:
Consoles: GX + GCM + "D3D360" + any other consoles
Mac: GL2 + GL3 [s]+ GL4[/s][i] [edit]SM5 level GPUs not supported by apple[/edit][/i]
Linux: GL2 + GL3 + GL4 multiplied with ATI + nVidia + Intel
Windows plan A: GL2 + GL3 + GL4 multiplied with ATI + nVidia + Intel
Windows plan B: D3D9, D3D11_10, D3D11
Mobile Phone: GLES1 + GLES2 multiplied with each Android + iOS device

Yes, sharing common GL code paths might be able to save you some time, but no matter which APIs you use, it's going to be a hell of a lot of work. Edited by Hodgman

Share this post


Link to post
Share on other sites
[quote name='SimonForsman' timestamp='1348138996' post='4981986']
glu and glaux are software support libraries for OpenGL but both are deprecated and horribly out of date.
[/quote]
Yeah, that's true, and sure they're not officially supported but freeglut and glee are nice extensions.
I use them both everyday, and they're updated quite often...

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1348148678' post='4982018']
So a "cross platform" renderer has to maintain and test code for:
Consoles: GX + GCM + "D3D360" + any other consoles
Mac: GL2 + GL3 + GL4
Linux: GL2 + GL3 + GL4 multiplied with ATI + nVidia + Intel
Windows plan A: GL2 + GL3 + GL4 multiplied with ATI + nVidia + Intel
Windows plan B: D3D9, D3D11_10, D3D11
Mobile Phone: GLES1 + GLES2 multiplied with each Android + iOS device

Yes, sharing common GL code paths might be able to save you some time, but no matter which APIs you use, it's going to be a hell of a lot of work.
[/quote]

When did Apple add OpenGL4 support ? (Last time i checked they had just added OpenGL 3.2 in Lion and i don't think Mountain Lion added anything new in that area). (Apples tight grip might keep things consistent but they do lag behind quite a bit when it comes to supporting new features)

Share this post


Link to post
Share on other sites
Neither are bad and both have matured well enough, appropriately and look to be continuing to do that. If the platforms you're targeting don't force the decision somewhat, then I'd look into both and make a personal decision based on preference. I'd also say that if you have the time, consider doing both anyway...your own software architecture will be much stronger when based on concepts supportive of both targets.

So...find a reason to rule one or the other out (such as platforms) and make the decision easy for yourself if possible, if that's not an option try both and make a personal decision and if you can afford the time and effort, do both, or at least do one in full and keep your hand in the other anyway.

Either way, never say never. I did that and was never a fan of Mac's, so if five years ago someone was to suggest to me that I'd have spent last year on Open GL ES doing mobile and this year on Open GL 3.2 and Mac, I'd have thought they were on crack yet it's been surprisingly good fun. The Mac is a fairly decent platform for OpenGL development actually.

Direct3D or OpenGL...you'll have good fun on either or both paths regardless. Edited by freakchild

Share this post


Link to post
Share on other sites
They both work, they're both good, they're both fun to use, so choose either but in the longer term aim to learn both.

[quote name='3Ddreamer' timestamp='1348109369' post='4981895']
Doesn't the hardware accelerated 3D nature of OpenGL offer more potential for game features because software processing could be run simultaneously with hardware acceleration to broaden the game engine base - so to speak? Isn't hardware acceleration offering the most potential for game performance and more 3D objects and 2D textures allowable?
[/quote]
[quote name='3Ddreamer' timestamp='1348112191' post='4981908']
Okay, but isn't OpenGL more low level programming compared to DirectX? Isn't DirectX more friendly to scripting languages?
[/quote]

You seem to have some very suspect sources here. As pointed out above, both are hardware accelerated, and both are very low-level (OpenGL is actually a little higher-level than D3D as it abstracts some hardware concepts a little more; I suspect that whatever sources you're using may not have updated their info since sometime around 1996 or 97...)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this