Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / Game Design & Programming / OpenGL or DirectX? Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
IlyaZ

November 14, 2004, 04:21 PM

Well a few friends and I are going to make a game. But we can't decide if we should use d3d or opengl.

I know there is .x for directx which I can use to export/import animations with 3dsmax. However is the .x a good thing to use? What are the benefits of it contra writing an own format? And how do I write my own format? Why are there almost no tutorials for directx also?

In OpenGL as I understand there is no such thing (built in)?

Could you please recommend what to use?

 
PeacefulKiller

November 14, 2004, 05:40 PM

It really depends on what kind of game you want to do, and what kind of experience you have.
OpenGL is known to be easier to understand. It's also known for it's portability, if you use OpenGL you have a very good chance to be able to port your game to other platforms, like Windows, Linux, MacOS, etc.
DirectX is know to be a bit harder to understand, yet is preferred by most of the professional game developers (with exceptions like for example ID Software).
My opinion is that they both get the job done, and it's really a question of taste. Alse with DirectX you have have support libraries which include math functions and some ready to use data structures like for example to load and render 3D models (the .x you were talking about). The .x models make it easier to start building a game, because you don't have to code stuff related to, for example, loading and rendering 3d models and also you don't have to code exporters and/or importers for your own format. Although it gives you less freedom, because you are restricted to the features of the .x models, that may or may not have what you need.
OpenGL has some support libraries too (glu and glaux), however they are a bit different, they give you support to render Bezier and NURBS surfaces and render primitives and load BMP textures for example, I would say they're not especially directed to game programming as DirectX's supporting libraries and they are more low-level.
The reason why OpenGL has more tutorials in the net is probably because it's easier and is multi-platform, nad also DirectX already comes with a lot of examples in its SDK.
If you just want to build a game and not worry about low-level programming and don't mind using libraries written over one of those APIs (DirectX or OpenGL) which might restrict you but also make things go a lot faster, you could use a 3d engine like Crystal Space, or OGRE, or Illricht or even another one.

Hope this helps.

 
tdenk

November 15, 2004, 07:13 AM

I'd use OpenGL simply because it is a lot easier to understand, has way better up- and downgrade compatibility through extensions rather than incompatible versions, and it runs on practically every machine on this planet without any changes, giving best-possible near-identical results.
OpenGL is cool because it is a lot like Postscript or TeX - you tell it what you want, and it makes the best possible thing out of it (the precise result is not defined, but you would not notice the difference anyway).
OpenGL uses simple c-style functions, is well-documented, offers good quality and performance (surprisingly, sometimes significantly better than DirectX), and it completely misses the Voodoo that you have to cope with in DirectX (why does everything have to be "smart", why do all DXVERYLONGSILLYPTRNAMES have to be capitalized so you can't read them properly, why can you never guess right who owns an object in DX...? Why can't you just guess from a function's name what it does, precisely?). Well... use OpenGL

Also, OpenGL it is non-Microsoft proprietary, so by using it you help to fight evil Babylon.

 
Axel

November 15, 2004, 08:12 AM

I'd use OpenGL simply because it is a lot easier to understand

Why is that? Both offer almost the same functionality (immediate OGL should be avoided at all costs).

I think that's a myth from older D3D Versions. D3D 8 and 9 are very good APIs, that are not harder to understand than OGL.

 
IlyaZ

November 15, 2004, 09:28 AM

Thanks for your answers, they've made things clearer. :)


We're just going to make a simple 3d-FPS-game (one small level) as a project for school. I know all "normal"-c++ programming, but I'm quite new at OpenGL. I've got 8-9 months to learn either OpenGL or D3d, and after that I've got 1 year to make the game.

I think, as it's such a small game, it's better to create an own 3d-engine. But what things are incorporated into the game-engine, all physics (like what ,besides gravity and collisions)?
We're also going to use 3dsmax for the models and animations. I see there is code for importing 3ds files (in OpenGL). But I've not found code for loading .3ds animations.

As I can't use one format for everything I assume it's easier to use an own format? But then the question is: how do I code my own format? Or are there finished formats to find somewhere (for Opengl)? The last questions might be the decisive ones.

 
tokjunior

November 15, 2004, 11:33 AM

Direct3D and OpenGL are as easy to learn. People who claim GL is easier are people who stay in immediatemode and place their vertices one at a time.
I prefer D3D since it's objectoriented, and you don't need to care about all the extensions you'd have to bother with under GL.
The .x format is very good, and it's not just for models. Ascii .x is a lot like a modelling-language, so you can store anything in it, including bitmaps and sounds.

 
Francois Hamel

November 15, 2004, 11:42 AM

I agree, OpenGL is NOT easier to learn anymore. It was true back then, before the second world war or something :) Right now I'd even go and say that DirectX has become somehow easier to learn and to use compared with the now messy OpenGL.

That's too bad since I was a big fan of OpenGL until now...
Honestly I'd go with Direct X if I were you, with the debug version you even have access to a lot of debug infos and warnings which might be usefull to you. With OpenGL you got nothing at all.

 
PeacefulKiller

November 15, 2004, 01:03 PM

A format is simply what and how data is organized.
For example you want a file format to hold simple 3d model information, you'll need the position of each vertex, the texture coordinate of each vertex, the normal to each vertex, for each face the 3 indexes of the vertexes. Now how you organize that information in a file (binary or ascii) is up to you. You can for example decide to have an ascii file which first has the number of vertexes followed in the following line by all the vertexes (3 coordinates each) and so forth. It's also up to you the structures you have in your game to hold that information.
Of course if you need animations and possibly other features then you will need more information. And then make an exporter for a modeler which converts that modeler's data structures into the file format you've created.
About finding code using other formats, you might want to check code using the MS3D format which is the format of the "Milkshape" modeler or the MD2 or MD3 formats which are the formats used by the Quake2 and Quake3 games for example. Since you're going to do an FPS you might want to check those formats.
Now if you should do your own format or use one that already exists, that's really up to you, you must see if there are formats that have all you need, and if there are then if you have all the tools to manipulate files in that format, or if all the formats you find have missing features you want and have to make your own.
About using one format for everything, usually several formats are used: in an FPS for example you have formats for textures (i.e. .bmp, .tga, .jpg, .png, etc.), formats for maps (.bsp, .map, etc.), formats for models (.md2, .md3, etc.), formats for sounds (.wav, .ogg, .mp3, etc.), etc.

 
IlyaZ

November 15, 2004, 04:25 PM

Oh first a correction I have to do:
"As I can't use one format for everything I assume it's easier to use an own format?"

"Everything" in that moment seemed to be just models and animations ;)
Okay I got to write a converter if I need a custom format, but I've seen plug-ins for 3dsmax which allows you to directly export using a custom format, how are those done?

Some final questions anyway.
What are the features of the .x format?

I also read this in MSDN: "Important The exporter may not build with Visual Studio .NET/Microsoft Visual C++ .NET.". Don't know if it's a stupid question, but does this really mean that I can't use Visual Studio .Net 2003 to compile the game?

And the last one, is it true that the directx versions differ greatly? Like a tutorial for an old version, would it work for directx 9? Is the SDK help/tutorials updated for the latest directx version?

 
Axel

November 15, 2004, 04:44 PM

I also read this in MSDN: "Important The exporter may not build with Visual Studio .NET/Microsoft Visual C++ .NET.". Don't know if it's a stupid question, but does this really mean that I can't use Visual Studio .Net 2003 to compile the game?

I assume that that relates to the 3D Studio Max plugin. The Max plugin SDK states that you should use VC++ 6.0 to compile your plugins for it, because 3dsmax was built with it aswell. But that DOES NOT mean you have to build your game with VC++ 6.0.
But last time I made a plugin for 3dsmax I had no problems with .NET, so I think they just say that because they don't want give you support if you use .NET.

And the last one, is it true that the directx versions differ greatly? Like a tutorial for an old version, would it work for directx 9? Is the SDK help/tutorials updated for the latest directx version?

DirectX 8 and 9 are almost the same (DirectX 9 has more features, but the API structure is the same). DirectX 7 and older versions were crap and you shouldn't find tutorials anymore that deal with them.

The DirectX documentation is very good, and naturally it's updated for the latest version. How should we program an API without documentation?

 
PeacefulKiller

November 15, 2004, 04:45 PM

If you take a look at the 3dsmax sdk it has example of exporter plugins, also there are several projects to simplify building exporter plugins for 3dsmax like flexport (I think this is the name).
I don't really know the features of .x format, because I haven't used DirectX in a while and when I did I never used that format.
About the MSDN message I think they ment you may not be able to build the exporter plugin with MSVC 2003 .NET, just the exporter plugin, anyway it's just a guess.
About the changes of DirectX I know that DirectX has in fact changed a lot through out its versions, and you should look for a DirectX 9.0 (I believe this is the current version) tutorial, or just look at the DX9.0 SDK examples.

 
IlyaZ

November 16, 2004, 12:17 AM

Okay, I'll give D3d9 a try. Thanks everyone. :)

 
tdenk

November 16, 2004, 08:20 AM

>People who claim GL is easier are people who stay in immediatemode and place their vertices one at a time.

Really... :)

Well then compare this Voodoo from MSDN

if(FAILED(hr = m_lpVB->Lock(m_dwBase * sizeof(VERTEX_PARTICLE), m_dwFlush * sizeof(VERTEX_PARTICLE), (VOID **) &pVertices, m_dwBase ? 3DLOCK_NOOVERWRITE : D3DLOCK_DISCARD)))
{
...
}


to this:
glGenBuffersARB( 1, &myVertices );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, myVertices );
if(glGetError())
{
...
}

Which is easier? You decide.
When given 20 seconds to look at each piece, I have to say that I am not able to understand what the first piece of code is supposed to do (actually, not even after 2 minutes).

 
sebarnolds

November 16, 2004, 09:40 AM

Yes, this thread is going to receive a lot of bulk posts because some people don't like OpenGL and other people don't like Direct3D.

You should really ask yourselves where is the point about telling "OpenGL is better !" or "Direct3D is better !".

If someone is willing to learn a graphics API, he'd better try both of them before picking one. Choosing D3D is choosing a programming style and choosing OpenGL is choosing another one.

D3D is MS-specific and OpenGL is platform independant.
D3D is part of a bigger library (DirectX) and has a lot of helping functions (D3DX) and OpenGL has less of them (I don't have many details about GLUT and GLU).
Both of them have many tutorials on the net.
... the list of pros and cons can be extended...

So I suggest trying both of them...
Hope it helps...

By the way, tdenk, I think you exagerate a bit. The DX code you posted can be rewritten so it would be more readable. Besides, if you ignore the last parametre of the call (which is present for performance purpose), it's easy to understand. Even, ten minutes of documentation reading and a 12-year old child understands its purpose.
And NO : I'm not a DX fanatic. I used to program DirectX and now I'm using both of them.

 
Luke Hodorowicz

November 16, 2004, 09:57 AM

Both API's can do the same things. Both API's have failings. It doesn't matter which one you use. Once you know them, they both make sense.

Just looking at the MSDN docs for 2 min does not give you any idea about the overall way of doing things in DX. And for those who don't know, to use glGenBuffersARB, there had to be some "voodoo" to get the function pointers by name and checking for support of the extension.

If you want to work in the real world making games you better know both inside and out. PC can go both ways. Xbox is DX-ish, GameCube is GL-ish, and PS2 you write your own device drivers so you're screwed anyway.

-Luke

 
davepermen

November 16, 2004, 11:59 AM

if you know how to use MSDN and you know the language you program in, you should not have any issues with reading and understanding dx code. very well documented what each method does in the msdn, and how to call it, how to give parameters, is part of the language (and well documented, too).

so your failing in reading dx code is not a failing of d3d, merely a failing of your capability to read code.

i for myself still use opengl. but i have no problem with d3d.

 
djbuzzkill

December 11, 2004, 11:04 AM

OpengDirectGXL is the best api. its got every feature you will need and completely co-dependent of any platform.

 
b34r

December 11, 2004, 11:50 AM

I've used Direct3D from version (revision) 3 to 8, immediate mode only. With EACH new versions I had MASSIVE changes to make, most of them unjustified. These guys just love to rename every single render state, class member or class and pointers to class.

Direct3D is a pain to update. But if that wasn't enough, it's:

- Windows only,
- Most of the time extremely unclear (render state hell and obscure undocumented case, yet you REALLY wonder what will happen when the case triggers),
- Dead (you can be pretty sure you're in for a complete rewrite once they finish the successor),
- Fixed architecture (Granted, OpenGL extensions are a pain too. Still the approach is much nicer and the API is stable),
- From the devil (and I mean it, why do you need to give more areas of influence to these people? What exactly have been the exclusive breakthrough of D3D so far?).

Since I took some hours to learn OpenGL I just can't believe I suffered this **** of D3D API for so long. Oh YES it's becoming better. Now you can create a texture in two lines of code. On D3D7 it used to be a chunk of 50 lines if you wanted to be sure you'd have textures everywhere. Heck, the initialisation stuff only was hundreds of lines of code with its share of callbacks.

Direct3D might get better, it's a crappy API and I just don't understand why, with a perfectly competitive API available (I should say better would it only be for the cross platform ability but I'll refrain), people keep on going feeding the beast.

I really don't agree that it depends on what application you want to make. Both API are perfectly working in any domain. Well, I'm lying since for example resizing output to a window (I mean, not with a BitBlt()) in, let's say, your editor with Direct3D just require that you reupdate all of your resources to the monster after you reset its device (ok, it's easier in Dx9 so they say). In OpenGL, guess what... nothing to do. Multiple window rendering is also *slightly* more straightforward in OpenGL. In fact, I just CAN'T see any upsides to Direct3D. None.
Even compiling D3D with a non Microsoft compiler requires a lot of involved work.

And .X format is a JOKE, so are the exporters for it.
If you are looking to gain some time by not writing this kind of stuff you might aswel directly go for an open-source engine. See DevMaster 3d engine list if you don't know wich one to pick.

 
Chad Austin

December 11, 2004, 12:26 PM

One advantage of Direct3D is that rendering to a texture is more straightforward than it is in OpenGL. (Why can't the ARB hurry up and get that done? They were claiming they'd have uberbuffers done last year!)

One advantage of OpenGL is that batchiness isn't such a large factor. It's still pretty cheap to render small primitives in immediate mode. (Although I've noticed that my Radeon has a higher fixed overhead per batch than nvidia cards seem to.)

GLSL is still pretty rough around the edges. ATI doesn't implement the #version directive, the ATI compiler crashes on some large shaders, the ATI optimizer sucks (can you see that I use an ATI card? :) GLSL is horked on the Mac, and I've witnessed some people having trouble getting it to work in Linux.

Personally, I prefer OpenGL's straightforward API over DirectX. And those early years of DirectX were especially bad. ;)

 
abdulla

December 11, 2004, 08:04 PM

I think what he may be referring to is the clarity of the code itself. Arguably that can be resolved by the person who writes the code, but the reference documentation is generally a good indication of how the creators expect code to be written. As sebarnolds said, it's almost like choosing a coding style, though I agree that you should be well aware of both.

 
[-WD40-]

December 11, 2004, 08:55 PM

Go for DirectX. Simpler, easier, and gets the job done faster and cleaner!

OpenGL is now totally bloated and the companies that maintain it keeps fighting each others so no significant progress is being made. Render targets are a PAIN in OpenGL where in D3D they are soooo much easier to use.

I've used both at the same time, even wrote a D3D emulation using OpenGL and all I can say is OpenGL as it is *right now* is more pain in the ass than anything else.

If this doesn't still make up your mind, 1 or 2 years back I kept telling people how OpenGL rocked and all that stuff... only idiots don't change their minds as we say ;)

If you don't need PC portability (Linux, MacOS), go for DirectX! If you want console portability (XBOX) go for DirectX! Else, go for OpenGL but you've been warned.

 
[-WD40-]

December 11, 2004, 09:01 PM

You should really ask yourselves where is the point about telling "OpenGL is better !" or "Direct3D is better !".


My point as of now is to show the ARB that people are fed up with them and the non-progress and the so minimal OpenGL 2.0 that everyone was waiting for. They blew it big time. They need to do something about it.

One way to protest is to move from OpenGL to DirectX.

 
Lennox

December 11, 2004, 11:34 PM

I know this is like feeding the beast, but just abstract your rendering calls. You go with Direct3D, you are pretty much tied to the PC and XBOX. You go with OpenGL, you have cross platformability but no support in the Windows community. I don't know how many bug cases my company had where we had to tell people to updgrade their GL drivers. XP installs the crappiest compaibility drivers possible for OpenGL support.

Me myself, I got into D3D around 5.0 and met OpenGL soon after. I have never really gone back to D3D ever since. I see they made D3D 8/9 a lot more like OpenGL now, but what was the point? There was a perfectly good API out wayyy back when, and instead of furthering it, they decided to create their own (not getting it right till many revisions later). Can't be too mad at them though. I remember when acceleration was first coming in, I was angry because it was going to put an end to the number crunching to get the perfect software rendering loop. Change is inevitable.

Instead of being angry about it, learn from your mistakes. Going back to what I said earlier. Since they are both really just graphics API's, you can easily get around the confusion now by abstracting. Mostly everything is done in vertex buffers these days anyway, so your abstraction wouldn't even be too lengthy (depending on what you are doing). Plus by abstracting, you can add all kinds of new functionality to your rendering. Especially useful in Scenegraph related applications.

http://vprat.alrj.org/programming.php?id_prod=8 (former flipcode COTD)
http://www.ogre3d.org/ (complete abstraction but bloated IMHO)

 
Monsterman

January 03, 2005, 02:46 AM

I am (another) linux programmer
I only know OGL
I've learned about 3 times over 2years now... think I get a better understanding each time. (Learned C about 2 times and C++ i'm still learning.. for the xth time ;)
I always hated windows but sorta made peace with XP.
Cannot claim to have something against DX9 because I REALLY like all the kewl games it runs for me... never mind the fact that my hardware are stuck on DX7 or something :(
I hate it when a game refuses to run simply because my card doesn't have a shader version blabla... AARGH!! but I think that was the game programmer and not DX.

I would like to learn DX also.. never got to it. And then I presume a "good" library out there will be able to compile for both API's and optimize both to max.
Half-life 1 came out with drivers for DX and OGL.. 2 bad the DX framerates was next to useless. hehe

ok so I added another meaningless post to this thread.. yeah ... back to work


 
This thread contains 24 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.