Beginner OpenGL vs DirectX
category: code [glöplog]
Hi, I am almost new to 3D and I have to choose the API, I know you can do anything in both. I have modern GPU 7870 so I am not limited to DirectX 9 or old OpenGL. So what do you recommend me? I think OpenGL is much easier(also less code) than DirectX, but you need n-libraries for sound, input, window, or SDL/SFML for all of that. Thanks in advance.
Disclaimer: I still haven't made the jump from DX9 to DX11 and I only kinda brushed with OpenGL3+ so some of this stuff may be inaccurate/outdated.
It depends on your choice of flavor really. Here's a few pros/cons:
- Basic OpenGL (ie. just drawing colorful triangles) can be super-simple, but it leads you into a trap once you want to start with interesting stuff.
- DirectX can be a bit fiddly at the start but once you got the hang of it it's pretty much the same all the way down.
- OpenGL documentation is rather sketchy, DirectX is considerably more professional.
- The API design is debatable: OpenGL is rather "loose" (no enums, dynamic extension loading, no return values, etc.) whereas DirectX is stricter.
- OpenGL is multiplatform, DirectX limits you to Windows.
- OpenGL shader compiler is a LOT faster than DirectX when it comes to loops or branching.
- DirectX debugging facilities used to be inarguably better, unsure how they are now: OpenGL has gDebugger now for free but it was still kinda sketchy I last checked, DirectX PIX got integrated into Visual Studio so that might've gone down the drain since. For DX9 at least, there was no contest between the two.
- DirectX also has debug runtime + reference rasterizer, which helps a lot when it comes to compatibility testing.
- DirectX has a stricter hardware-abstraction layer, which means you get a better chance of your stuff working and looking the same on any computer config. With OpenGL a lot of that is at the mercy of the drivers: ATI shader compilers stick stricter to the standard so some shaders that work on NVIDIA (whose compilers are more lenient) might just break on ATI during compilation.
- OpenGL basically hands you WebGL for free.
- Microsoft has made a pretty unpleasant DLL hell with D3DX (in DX9 at least), so if you use that, you might want to ask people to install the full runtime or supply the DLL yourself.
So I suppose it all depends on your mileage and what you expect from an API. There's plenty of source code going around for both so I'd recommend just taking a look at both and deciding which flavor you prefer.
It depends on your choice of flavor really. Here's a few pros/cons:
- Basic OpenGL (ie. just drawing colorful triangles) can be super-simple, but it leads you into a trap once you want to start with interesting stuff.
- DirectX can be a bit fiddly at the start but once you got the hang of it it's pretty much the same all the way down.
- OpenGL documentation is rather sketchy, DirectX is considerably more professional.
- The API design is debatable: OpenGL is rather "loose" (no enums, dynamic extension loading, no return values, etc.) whereas DirectX is stricter.
- OpenGL is multiplatform, DirectX limits you to Windows.
- OpenGL shader compiler is a LOT faster than DirectX when it comes to loops or branching.
- DirectX debugging facilities used to be inarguably better, unsure how they are now: OpenGL has gDebugger now for free but it was still kinda sketchy I last checked, DirectX PIX got integrated into Visual Studio so that might've gone down the drain since. For DX9 at least, there was no contest between the two.
- DirectX also has debug runtime + reference rasterizer, which helps a lot when it comes to compatibility testing.
- DirectX has a stricter hardware-abstraction layer, which means you get a better chance of your stuff working and looking the same on any computer config. With OpenGL a lot of that is at the mercy of the drivers: ATI shader compilers stick stricter to the standard so some shaders that work on NVIDIA (whose compilers are more lenient) might just break on ATI during compilation.
- OpenGL basically hands you WebGL for free.
- Microsoft has made a pretty unpleasant DLL hell with D3DX (in DX9 at least), so if you use that, you might want to ask people to install the full runtime or supply the DLL yourself.
So I suppose it all depends on your mileage and what you expect from an API. There's plenty of source code going around for both so I'd recommend just taking a look at both and deciding which flavor you prefer.
Quote:
- Microsoft has made a pretty unpleasant DLL hell with D3DX (in DX9 at least), so if you use that, you might want to ask people to install the full runtime or supply the DLL yourself.
Or, download an older version of the DX9 SDK, which still includes a static D3DX library (in which case you obviously miss out on newer functionality and compiler stuff, but in practice it's not such a big deal, considering the fact that you're stuck to DX9 anyway).
raymarching pixel shaders in D3D9 are 3 times slower than the same in model4 with D3D10. OpenGL follows the evolution of upgrades. Moreover, compilation of shaders in pure D3D9 is 10 times slower than compiling with D3D10. So you are obliged to supply modified DLLs with your program.
Quote:
- Basic OpenGL (ie. just drawing colorful triangles) can be super-simple, but it leads you into a trap once you want to start with interesting stuff.
So it is more complicated to do complex stuff in modern OpenGL (3.3+) than in DirectX 11?
OpenGL ES is another reason to learn GL, if you intend to do mobile/embedded stuff later on.
I don't know about DirectX, but yes the OpenGL 3.3+ (or even OpenGL ES 2.0) level stuff can be a royal pain in the ass.
As far as OpenGL not having the other libraries, there is SDL?
Personally I'm using OpenGL 3+ with GLEW, and am trying to stick to stuff that is also available in OpenGL ES2.0 to aid portability. I chose this purely because some of the ideas for interactive things I have, I want to on tablets.
AMDs CodeXL (used to be callked gDEBugger) really helps with debugging GL.
However, I think its important here to say, If I were just working on Windows I'd stick to Direct X.
As far as OpenGL not having the other libraries, there is SDL?
Personally I'm using OpenGL 3+ with GLEW, and am trying to stick to stuff that is also available in OpenGL ES2.0 to aid portability. I chose this purely because some of the ideas for interactive things I have, I want to on tablets.
AMDs CodeXL (used to be callked gDEBugger) really helps with debugging GL.
However, I think its important here to say, If I were just working on Windows I'd stick to Direct X.
Quote:
So it is more complicated to do complex stuff in modern OpenGL (3.3+) than in DirectX 11?
Yes, once you want to optimize your code, or use newer features, you need to start using all sorts of extensions/modifications to the original OpenGL API, which don't always make sense. Things like shaders and vertex/index buffers were literally hacked into the API at a later stage. So getting a triangle on screen with OGL is one thing. Getting it on screen using shaders and buffers means you have to rewrite your code, and the same functions take on different meanings as soon as some extensions kick in... sometimes makes it hard to figure out what is going on.
DX11 was designed from scratch with the latest hardware in mind, so you get a streamlined API that is only meant to be used with programmable shaders, buffer objects etc. More difficult to get triangles on screen, but once you get that far, you know you're already doing it the right way. It's the only way.
Quote:
OpenGL ES is another reason to learn GL, if you intend to do mobile/embedded stuff later on.
Unless you want to target Windows Phone/RT of course. Those use D3D11, and don't support OpenGL.
The upside is, it really IS D3D11, where OpenGL ES is a mobile derivative of OpenGL, which is similar, but not entirely compatible. You'll need to rerwrite some parts of your OpenGL code and shaders to make them work in OpenGL ES.
Quote:
- OpenGL documentation is rather sketchy, DirectX is considerably more professional.
Nope, the last version of the DX doc (DX10 or DX11) I checked was a complete mess.
The DX9 doc was really nice compared to DX10+.
The OpenGL spec is a bit different. ;)
Quote:
- DirectX debugging facilities used to be inarguably better, unsure how they are now: OpenGL has gDebugger now for free but it was still kinda sketchy I last checked, DirectX PIX got integrated into Visual Studio so that might've gone down the drain since. For DX9 at least, there was no contest between the two.
The DEBUG extensions for GL are quite nice + you can do per pixel shader debugging with NSIGHT (Breakpoints in shaders and so on... Supported up to now OpenGL 4.2 core iirc).
Debugging is pretty ok with both APIs if you know your shit.
If you want to learn something for the "future" I would recommend to go with one of the current APIs - that is DirectX 11.y (y >= 0) or OpenGL 4.x (where x >= 2).
In case you want to do mobile programming bullshit afterwards, well than take OpenGL. Otherwise just pick one of the two.
There is no best API for Beginners.
Another thing: If you don't initialize a profile for your OpenGL rendering context, you will get a compatibility profile with the most current GL version supported by your driver. Using a compatibility profile is sometimes quite nice for debugging, fast prototyping (you still can use all the old and ugly things e.g. glBegin/glEnd) and also for sizecoding.
P.S.: I assumed nobody wants to target Windows Phone/RT.
If you do, than well it's DX. Mobile devices are not powerful enough anyways.
If you do, than well it's DX. Mobile devices are not powerful enough anyways.
Quote:
Mobile devices are not powerful enough anyways.
Context realted though.. it depends what the goals are really.. Next gen 3d? maybe, but for a guy like the OP one thats starting out and doesn't want to learn something that may be 'old'.
If he wants to learn 3d and possibly also make games.. then its all about platform, and he might have a desire to make an 'app'.
It suits people differently, IMO everything non M$ related in the linux / apple and embedded world uses a form of GL..
Go with OpenGL. Main reasons are because you probably will want to play around with WebGL sooner or later and its more or less OpenGL. If you ever want multiplatform you want OpenGL. If you want to work on any larger mobile platform you want OpenGL.
Quote:
added on the 2013-11-17 13:40:57 by Canopy Canopy
Go with OpenGL. Main reasons are because you probably will want to play around with WebGL sooner or later and its more or less OpenGL. If you ever want multiplatform you want OpenGL. If you want to work on any larger mobile platform you want OpenGL.
To be honest, I don't think it's an answer to the question.
The easiest API to learn, in my opinion, is DirectX 9, with D3DX. You have good documentation, a reliable runtime and driver implementation, and it's a complete solution, including shader compiler, texture loading functions, math library and all that. You can start out with simple fixed-function code, and then work your way up to shaders with the same API.
Once you have learnt enough about 3D coding with D3D9, it is easy to move to OpenGL, because you already know how GPU programming works, and what you are looking for in OpenGL. You still need to find your own texture loading and math libraries though (or roll your own). The biggest problem with OpenGL is that there are so many versions of it, and so many extensions. It's very hard for a beginner to find the right tutorials, rather than outdated/archaic stuff that may not be relevant at all to what you want to do. It helps to have some experience under your belt.
Or you could stick to Windows and move to D3D11 from there (which is a very difficult API for beginners, but if you already know how to program with shaders and buffers in D3D9, it should not be too hard to get D3D11 working).
Either way, I think D3D9/D3DX is the best place to start, even if it's not the API you end up using once you're ready for serious productions.
I recommend an Nvidia GPU.
I recommend listening to yzi.
msqrt: your mother tells you that.
So the DirectX is the better way for advanced stuff but DirectX 9 is best for start? I have basics of OpenGL and also with buffers and shaders, and I have made few simple games in SFML, Allegro, also few programs using OpenGL(but they are not there). http://redoportfolio.ic.cz/?page_id=8 So I should be ready for DirectX 11, right?
If you have no problem using buffers and shaders then yea, might as well go DX11.
no point in spending time on learning legacy APIs
Quote:
no point in spending time on learning legacy APIs
So the question is, if you'd like you simple gamews and programs to run on 'other' hardware (iPhone, iPad, Raspberry Pi, Android..) learning "modern" OpenGL might be the way forwards.
Just render everything in software, can't get more portable than that :)
I used to be all for DirectX but today I'd just learn OpenGL and be done with it. OpenGL ES 3.0 on mobile is a pretty nice subset, if you stick to it on desktop too then you will be able to trivially port to modern mobile devices, and by restricting yourself a little more to OpenGL ES 2.0 you'll run on pretty much anything and you get an easy port to WebGL.
The one drawback is shitty OpenGL drivers for older Intel GPUs. The API design is a matter of taste but I found that it's just about getting used to either of them.
The one drawback is shitty OpenGL drivers for older Intel GPUs. The API design is a matter of taste but I found that it's just about getting used to either of them.
My disclaimer: I only know OpenGL so I can't tell you anything about DirectX
As some people already said: go with new API. If you use old fixed function openGL and mix it with new stuff you'll have a lot to learn. Throwing a triangle on screen is impossible without buffers and shaders if you stick to a core profile.
So basically, this argument is invalid.
Other nice goodies you get besides portability and stuff: you can use shadertoy to prototype your effects :)
As some people already said: go with new API. If you use old fixed function openGL and mix it with new stuff you'll have a lot to learn. Throwing a triangle on screen is impossible without buffers and shaders if you stick to a core profile.
So basically, this argument is invalid.
Quote:
So getting a triangle on screen with OGL is one thing. Getting it on screen using shaders and buffers means you have to rewrite your code
Other nice goodies you get besides portability and stuff: you can use shadertoy to prototype your effects :)
Quote:
So basically, this argument is invalid.
Is it? It seems to be exactly the same thing as what you said:
Quote:
If you use old fixed function openGL and mix it with new stuff you'll have a lot to learn. Throwing a triangle on screen is impossible without buffers and shaders if you stick to a core profile.
Which is what I meant with finding the right tutorials and such. A lot of OpenGL tutorials are outdated, and teach you how to get something on screen with old fixedfunction code. Which is quite simple.
But if you want to go for a modern core profile OpenGL solution (or OpenGL ES 2.0+), you need to drop the fixedfunction stuff and rewrite everything to use buffers and shaders. Which is a similar problem as D3D10+ has: you need to implement pretty much all the math yourself, because there's no fixedfunction pipeline to help you.
If you know how to do that, you can start with D3D10+ or modern OpenGL. If you don't, then a fixedfunction API is an easier way to learn about 3D and mathematics. And in that case I suggest D3D9+D3DX, as I already explained above.