The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

OpenGL and DirectX

G'day, just wondering if any Graphics Gurus lurking here at JOS can quickly explain the relationship between OpenGL and DirectX.

The way I read OpenGL's web site, they are basically competing API's that do more or less the same thing, but I'm not sure if I'm reading this correctly.
NetFreak Send private email
Thursday, October 13, 2005
I haven't dabbled in this field for a few years now, but here's the nutshell explanation:

DirectX (at least the last few 100000 versions of it) is more or less a complete framework on which to build a multimedia application. The components of the framework (which used to be named DirectInput, Direct3D, etc) give the developer the ability to work with the graphics layer independently of the underlying hardware, to work with the sound hardware, to deal with keyboard/mouse/joystick input and all the other nonsense.

OpenGL is used (mainly) on non-Windows platforms as pretty much the only alternative to implement high-quality graphics application (such as ports of commercial video games to the Linux platform). As far as I remember, it provided no support for sound or input...just graphics.

That beign said, when I was in the game (pun intended), OpenGL was infinitely easier to program against, and has the backing of anti-Microsofties everywhere. I don't know if this has changed since, but I assume DirectX has matured with the years.
Andrey Butov Send private email
Thursday, October 13, 2005
OpenGL's site says Doom 3 is programmed in it, which I take to mean OpenGL can be depended on to run on Windows PC's without too much grief. Maybe that's a bad conclusion.
NetFreak Send private email
Thursday, October 13, 2005
OPen GL runs across platforms, DirectX doesn't.  OpenGL is a collection of mostly c libraries and is highly usable.  I think the learning curve is steep at first( think OMG ), but a 3d game can be written with a little thought and practice.
Doc Send private email
Thursday, October 13, 2005
DirectX has Direct3D, DirectInput and DirectSound.  It used to have DirectPlay but last I heard even Microsoft says you should just do your own networking and DirectMusic is scheduled to be replaced. (I have no idea why, though.)

OpenGL exists for the same reason as Direct3D (abstract interface to video hardware), OpenAL for the same reason as DirectSound/DirectMusic (abstract interface to audio hardware), and for user input and networking you're on your own.

DirectX is great if PCs and the XBox are your target platform. OpenGL & OpenAL are great if your target market is PC/Mac/anything UNIXy.  For other consoles you generally have console-specific APIs (and that shows how retarded they are - Microsoft was smart enough to leverage all their PC tech, everyone else is being proprietary. Where have we heard that before?)

Frankly, I'm not convinced that either is remarkably easier to learn or to use - the things that actually matter are higher-level concepts that are the same regardless of implementation, though of course the details still matter.

In practise, most stuff should be API-agnostic anyway so that it's easy to switch platforms as desired, and if you're a small company anyway you're probably not going to be doing console stuff and having large numbers of competitors do the "we don't care about the Mac market" is probably an advantage.

Incidentally, John Carmac is the number one reason why it's still possible to run OpenGL applications on Windows today - because Microsoft knows that killing Quake/Doom would kill their market share. Bill doesn't like the idea of seeing "Doom 4 system requirements: free copy of Linux and installation instructions in every box".  ;)  (And other assorted places)

"Warning: DirectPlay has been deprecated. Deprecated components of DirectX 9.0 for Managed Code are considered obsolete. While these components are still supported in this release of DirectX 9.0 for Managed Code, they may be removed in the future. When writing new applications, you should avoid using these deprecated components. When modifying existing applications, you are strongly encouraged to remove any dependency on these components.
DirectPlay enables you to write network applications such as multiplayer games."

Well, it used to allow you to do that, up til you were told not to use it.  ;)

Thursday, October 13, 2005
Thanks very much to all!
NetFreak Send private email
Friday, October 14, 2005
Another kind of difference:

It's dead easy to write OpenGL code that will still work on the oldest OpenGL 1.0 implementations (from 94, I think?). The shader programs and a few other things won't be available, but you can exclude them in runtime and actually get something decent.

The MS toolkits, on the other hand, are changing in a way that forces you to always commit to the latest version, and although backward binary compatibility is maintained, the forward source upgrade path is nontrivial and often costly (has been 4 times in 10 years). Welcome to the microsoft treadmill.
Ori Berger
Friday, October 14, 2005

May be you got all advice, still being in graphics are
i could not resist.

Academia mostly uses OpenGL and same goes with Industry.
OpenGL is only graphics API no sound, no multimedia. And
it is real good at what it is.

DirectX is very crypting if you have never programmed.
Whereas OpenGL has lot of example tutorials, starting from NeHe to Nate's.

OpenGL runs on all the platforms without any issue. DirectX binds you to platform.

Now if you plan to work on real cutting age, like SM 3.0 on just released GPUs then you might want to use DirectX.. since drivers in Windows for DirectX are 3 months advance than anything. That said, since u can use GLUT+OpenGL + drivers from ATI/Nvidia on windows you still get same benefit.

Finally it is your intended purpose - it will define manything.


Friday, October 14, 2005
DirectX is a game / multimedia programming toolkit for Windows. Comes pre-installed with Windows these days, and I believe XBox runs some subset of it. Consists of 2D raster blitting library (DirectDraw), two 3D drawing libraries (primitive drawing Direct3D IM and high-level Direct3D RM with object model, kinematics, its own file format etc.), sound library (DirectSound), and a network multiplayer library (which appears to be not supported any more). MS also "adds" the unrelated Win32 joystick API, dubbing it "DirectInput", to it. DirectX has COM-based interface.

OpenGL is a cross-platform API for 3D graphics. In terms of DirectX analog, it is closest to Direct3D IM - it is a primitive-based library. If you need sound or input or kinematics, you need to add your own (or use corresponding DirectX components on Windows.)

Both have been used successfully to make graphics engines for games, including major titles. Practically all video card drivers support hardware-accelerated OpenGL.

Personally, I think that OpenGL is a better library. It requires much less code to set things up and maintain them;  it also is very scalable - you can fall back to older versions easily, or you can use an "extension" to do very advanced things; it is essentially modular. It also offers a lot of generic raster and geometry processing routines; it can transform points or convert pixel data for you.

One advantage of DirectX is the uniform buffer format. You can read and write textures using the same routines as the output or off-screen buffers, and blit between them. With OpenGL, at first, it was a little harder to do, and you're still limited with what you can blit to what. But the current versions offer practically the same freedom with rendered textures and (newer) support for custom output buffers.

If you need to draw 2D graphics, it is a little trickier than DirectDraw, but then you get automatic alpha bliending, rotation, scaling, mirroring at no cost - whereas not all DirectDraw drivers support all of these even on hardware-accelerated cards, and you have to "fall forward" to Direct3D anyway. Not worth the bother.

What is Really good about OpenGL (with a capital R) is that it is not a proprietary library. It evolves with the practices developed in the industry: things are standardized in it as they appear in the hardware, after a while. So it is very no-nonsense, and by now extremely flexible and powerful.
Friday, October 14, 2005
There is now a sound version of OpenGL called OpenAL which has a very similar API style.

User input is usually abstracted by using GLUT or SDL, both of which provide you with system independent control of the windowing system and input systems.

D3D, for the small bit I've used it, tends to revolve around setting up a bundle of structures, all pointing to each other and full of settings. You then throw all this in one go at D3D, which renders it.

OpenGL on the other hand, tends to contain a lot more function calling because the primitive operations seem smaller.

I think, in general, you can be equally productive with either. Don't believe the hype about them presenting nice flat playing fields -- you STILL end up with slight variations in 3D cards producing different results -- the abstract of the card is very leaky.

The caution I'd offer is that OpenGL is less featureful but more stable. I think it's easier to learn and tends to conform more to what graphics textbooks consider a 3D API to be, whereas D3D is much more games oriented.
Katie Lucas
Friday, October 14, 2005
OpenGL manages to be cross-platform without being clunky or unpredictable. It accomplishes this by not only focusing on "3d graphics" in general, but by focusing further to include only the interface between renderer and client app.

OpenGL does not include sound and input APIs. It also doesn't attempt to directly support concepts like a camera, a character, or a scene.

I think that's a good thing and makes OpenGL clean and almost instantly understandable. It's just a standard interface for interacting with a hardware or software renderer.
Saturday, October 15, 2005
"a bundle of structures, all pointing to each other and full of settings. You then throw all this in one go at D3D, which renders it. OpenGL on the other hand, tends to contain a lot more function calling because the primitive operations seem smaller."

OpenGL has another set of functions that allow you to define arrays of data (or pointers to data) and then make a single call on them (or parts of them) to render whole series of primitives. It's all about preferred programming style and uniformity of the data.
Saturday, October 15, 2005
Technically, OpenGL uses a procedural model, while Direct3d is object based.What that means is that in Direct3d, you start by defining the objects to be rendered and tell direct3d to render tham , but in OpenGl, its more analogous to building the current visible scene polygon by polygon.
The way you program in OpenGL makes more sense.

Also OpenGL is supposed to have more accurate and consistent rendering across platforms.Its supported on everything from amigas to supercomputers.
Vivek Send private email
Saturday, October 15, 2005
Well, you build the scene polygon by polygon in Direct3D, too -- you just hand all the polygons to the graphics card at once. There's actually not much difference between the two APIs, once you get down to it.

The 'extra' that OpenGL provides is its handly glVertex (etc.) API, but, handy though it is, it isn't very efficient.
Sunday, October 16, 2005

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
Powered by FogBugz