Fog Creek Software
Discussion Board




OpenGL vs. Direct3D

I'm learning a little 3D graphics.  What are the pros and cons of OpenGL vs. the  DirectX Graphics API.

Dell Dude's Doobie
Thursday, February 13, 2003

OpenGL is cross-platform. It tends to change less often. I prefer the API to Direct3D, but that's probably a personal thing. It does tend to support extra features on cards, but they're less easy to use than the core stuff and while it's not too bad getting drivers for cards that support the core, it's hard to get all the extra extensions on all the OSes.

Direct3D has better support for modern chipset features. It's windows only. It tends to have driver issues - some advertised features don't quite work and so on.

Basically, I work with Linux, so OpenGL is the only real option. But for that I accept that I will either find it harder or impossible to support advanced chipsets. On the other hand, I know that pretty much what I ask for will happen, which I find an adequate trade-off.

Direct3D developers seem, from talking to them, to spend a lot of time tuning their apps to work on different cards, sorting out what does and doesn't work on various ones. OpenGL developers (from experience) spend ages waiting for drivers to arrive, but they work when they do.

If you're starting graphics, I'd recommend OpenGL. It seems to have a slightly more orthodox view - it's a general graphics tool and conforms more to the stuff in Foley & van Dam, whereas Direct3D seems more oriented to developing games.

On the other hand, there are a lot more "starting development with Direct3D" books about.

Katie Lucas
Friday, February 14, 2003

First off, both are undergoing furious development at the moment; anything after directx 8 or in opengl 2 is not really worth learning until it settles down.  All talk of pixel shaders and programmable code on the 'GPU' isn't really worth investing your time in any time soon until it has settled down a bit IMO.  The 'stable' parts of both - the basic parts if you like - are pretty comparable.

OpenGL
=====
* Very portable
* Very straightforward

Direct3D
======
* windows only (who is your 'consumer'?  maybe this doesn't bother you)
* Very straightforward

I think that the concepts they both use is so close that you could learn one and apply your underlying understanding and learn the syntax of the other very fast.  There is no fundemental difference in approach to get your head around.

Personally I like OpenGL and I just love display-lists, but can't honestly say any reason _not_ to use Direct3D if you really want to.

Nice
Friday, February 14, 2003

Check http://www.xmission.com/~legalize/d3d-vs-opengl.html

Here’s a general take.  Although I’ve been exposed to OpenGL as of late, I have MUCH more experience programming in DirectX. 

DirectX
Pros:
* DirectX supports a greater set of features.

* DirectX gives programmers a great deal of control over the rendering pipeline if they want it.  DirectX 9.0 features programmable pixel and vertex shaders via a high-level C-like shader language.

* Microsoft works closely and aggressively with hardware vendors to ensure a high level of compatibility with the latest hardware.

* DirectX 8.1 and up provide programmability via VB 6.0 through automation objects. 

* DirectX 9.0 provides Common Language Runtime support; it's programmable from C# and other Dot Net languages. 

Cons:
* DirectX is a proprietary standard.  Microsoft will determine its future and direction. 

* DirectX is not portable and probably never will be.

* DirectX is a somewhat lower level API than OpenGL and is more complicated.

* If you’re not used to COM and Windows programming, DirectX is going to take some getting used to if you want to use straight C/C++. 

OpenGL
Pros:
* OpenGL is an open standard.  A review board consisting of a consortium of different companies governs its specification and direction. 

* OpenGL is very portable.

* OpenGL is higher level and easier to understand.

* From a skillset perspective ... usage of OpenGL is commonplace in a variety of industries, from computer games, to CAD, scientific apps, visualization, etc.  DirectX is used almost exclusively for games. 

* OpenGL features greater levels of software emulation. 

Cons:
* Umm … well, it’s an open standard.  Because a review board governs its specification, OpenGL is bound to evolve more slowly. 

* OpenGL is extensible, and different hardware vendors have their own hardware specific extensions.

* DirectX seems to have gained greater support from PC graphics hardware vendors in recent history. 



OpenGL 2.0 will feature a more programmable pipeline from what I understand.  Will OpenGL 2.0 will be supported by the latest hardware from vendors like Nvidia and ATI?  Probably I think.  Furthermore, they will likely continue to provide their own OpenGL extensions. 

Microsoft seems to be investing heavily in DirectX; their API has made great strides in recent years.

IMHO, consider DirectX first if you primarily care about programming for PC's or X-Box.  Otherwise consider OpenGL.

Nick B.
Friday, February 14, 2003

In all the graphical abstractions the damn graphics programmers always want to end up hitting the metal, cos its the fastest way and any layers in between just get in the way.

That said, OpenGL protects the developer willing to use an abstraction more from underlying hardware changes.  DirectX seems designed to infuriate and perplex and positively make the developer get involved in hardware specirfic issues.

Simon Lucy
Friday, February 14, 2003

Interesting thread.  I'd like to hear what y'all use 3D rendering for anyway.  I've had to do some DRI (Linux glue layer between OpenGL like layers and device driver) work lately (though not 3D related) and was curious about what other people use 3D for outside of the game world.

Nat Ersoz
Friday, February 14, 2003

> OpenGL is higher level then DirectX

Not really.  They have different features.  OpenGL draws polygons. You can provide them one at a time or in lists. That's about it.

DirectX3D supports skinned models, 3d models, loading textures from various image formats, model animation, all in the API.  They even define a file format for loading/saving all that info. the .X format and most 3D programs save or export to that format.

OpenGL does not have any such high level features.  If you want to get a model up on the screen you will need to find another library or write it yourself.  If you want to get a texture into memory you will have to write your own image loading routines.

If you want to see DirectX in action download the SDK from http://msdn.microsoft.com.  Type "directx" in the search box and it should come up.  It comes with tons of examples.

If you need C++ you can get the standard edition for about $100 at Amazon.com which is plenty fine for making games.

Also, the reputation for DirectX being hard is from version 1 through 3.  Now a days they give you harnesses so you can just pick one from the SDK and it will deal with setup for you.

Yes, it is (or was) more low-level than OpenGL in that you can check for various card features and adjust your renderer for if they are there or not.  OpenGL used to require many features that were not standard on PCs until about 1999 which made it more generic but not compatible with many machines.  Now-a-days though there are so many extentions like vertex-shaders, pixel-shaders, cubic environment mapping and multi-texturing that even using OpenGL you have to check for all those features making it just as hard as DirectX *if* you want to use those features.

Gregg Tavares
Friday, February 14, 2003

I'd like to fill in some of the gaps left by previous posts. First it's not DirectX he asked for, but D3D. DirectX is a set of APIs that cover a set of funcionalities of use to "multimedia" applications. OpenGL is a graphics API so it is only fair to compare it to D3D. 

D3D used to have two modes, inmediate mode (which is a polygon crunching part of the API) and retained mode which was a scenegraph, that's what Gregg refers to in his post. The fact that you can load up .X files with very little code, and create a 3D app with a few API calls isn't that groundbreaking. Similar APIs have existed for OpenGL for years. OpenGL is only comparable to D3D in inmediate mode. There are plenty of scenegraph libraries for OpenGL that are far better than anything the D3D retained mode has to offer (see OpenInventor).


[Gregg Tavares]
"OpenGL does not have any such high level features.  If you want to get a model up on the screen you will need to find another library or write it yourself.  If you want to get a texture into memory you will have to write your own image loading routines."

You'll have to do that in D3D too, unless you use BMPs in which case you can use the win32 API to load them up. I am not aware of any means for loading PNGs, TGAs or JPGs using the bare D3D API.

D3D used to be heavily criticised for its overly complicated API (the fact that it was a COM interface didn't help either), it was cumbersome for developers. And the learning curve was a bitch. It improved on each release but it wasn't until DX8 that it could be considered on a par with OpenGL as far as ease of use and learning curve goes.

[Gregg Tavares]
"Yes, it is (or was) more low-level than OpenGL in that you can check for various card features and adjust your renderer for if they are there or not."

Via DEVCAPS. This is one of the main points of friction between proponents of any of these two APIs. There's a function call in the OpenGL API that provides info on what extensions the driver supports. Namely:

glGetString( GL_EXTENSIONS );

Unlike D3D when a feature is missing, OpenGL will not attempt to emulate it. This might sound like a bad thing, but it really isn't as bad as it sounds. When D3D emulates the missing features its very likely your performance will drop dramatically. And eventually you are gonna have specific codepaths for different feature sets, be it OpenGL or D3D. So this really isn't an advantage on the side of D3D.

I must admit that the recently released DX9 pulls comfortably ahead of OpenGL 1.4 in terms of features. However OpenGL2 looks like it will blow DX9 out of the water, making the API simpler to use, reducing complexity and increasing programmability.

Many card vendors implement OpenGL2 capabilities in their OpenGL 1.4 drivers in the form of extensions. So although the spec for OpenGL2 isn't yet closed you can get a taste of it with relative ease.

If your interest in the field of computer graphics is serious (meaning it goes beyond the occassional hobby game) I'd recommend you get familiar with both APIs. It is possible to be fluent in both.

In the field of computer graphics most literature is OpenGL centric, and a few common terms in computer graphics relate to OpenGL-speak, such as "GL lights", when talking about cards it is often said "this card can deal with these many GL lights", etc.

For a beginner I still think that OpenGL is just a tad easier to understand, but this is just my personal opinion.

Beka Pantone
Tuesday, February 18, 2003

*  Recent Topics

*  Fog Creek Home