PDA

View Full Version : what the difference between OpenGl & DirectX?who is better?


hus2005
03-26-2007, 08:19 PM
what the difference between OpenGl & DirectX?


who is better?

mummey
03-26-2007, 09:31 PM
Short answer: They're both good. Neither one of them "sux" per-se.

One is for Windows and XBox, the other is for everything, but doesn't get updated as often.

Decide which one to use based on your task. If you end up doing work like this as a career, you'll most likely learn both.

Good luck! :thumbsup:

Robert Bateman
03-27-2007, 10:39 AM
correction. DX is windows specific, however it also features maths libraries, object and animation loaders, joypad/keyboard input, video playback, sound and networking. OpenGL only does 3D graphics, however it's portable.

H3ro
03-27-2007, 12:00 PM
I have been told that if you really want to learn what is happening, openGL is a better choice as it does not do so much for you. You have to manually handle all the math and other more basic operation while direcX mostly does them for you. But if you are more interested in fast results directX is better.

Please correct me if Iím wrong

playmesumch00ns
03-27-2007, 03:35 PM
You're wrong, they're basically the same speed.

But you're right that DX gives you a lot more out of the box than opengl.

UrbanFuturistic
03-27-2007, 08:45 PM
Probably also worth mentioning SDL (again) and OpenAL (for audio) which are increasingly filling the DirectX gap. Not sure if there are any open libraries for the maths stuff though, but there are a lot of extensions being developed (http://www.libsdl.org/libraries.php) for SDL and it integrates quite nicely with OpenGL.

If I come across as slightly obsessive about XPlatform support, it's probably because I am :D

salmonmoose
03-28-2007, 01:29 AM
I have been told that if you really want to learn what is happening, openGL is a better choice as it does not do so much for you. You have to manually handle all the math and other more basic operation while direcX mostly does them for you. But if you are more interested in fast results directX is better.

Please correct me if Iím wrong

That's a bit like saying it's better to code stuff in ASM because it doesn't do as much for you.

Why spend hours on end building code to handle stuff that has already been done by someone else? And probably more efficiently than you'll manage.

There is probably a faster development turn around with DirectX, but if you really want a fast turn around you would probably do well to look into XNA/MDX or a pre-built engine.

H3ro
03-28-2007, 08:12 AM
I am not trying to say that it is better, but if you learn directX you dont have do learn all the undergoing stuff.

Carina
03-28-2007, 09:19 AM
That's a bit like saying it's better to code stuff in ASM because it doesn't do as much for you.


First time I've seen OpenGL compared to ASM :)

Robert Bateman
03-28-2007, 09:22 AM
and if you learn DirectX, you learn 1 way to render geometry. If you learn GL, you can use any of 7 or 8 ways to draw a triangle. Eventually you might find that the vertex buffer object extension is the one you want (ie, the one like DX).

I think the DX API is far nicer to learn these days, it actually shows you only 1 way of doing pretty much anything. In many ways it is a much closer guide to what the hardware is doing than openGL. Of course, if all you do is load and render a .X file, you might not get too see too much - but that's not really a failing of the API.

Whilst I like openGL, these day's i'd recommend learning DirectX first, and then going for GL. The simple reason is that when wading through all of the extensions and old tutorials on the net, you can simply look for the ones that work *most* like DirectX and you've probably found the most up to date and efficient extension.

gga
03-28-2007, 07:00 PM
what the difference between OpenGl & DirectX?


who is better?

DirectX is a microsoft (windows) only api that covers 3d, video, sound, input devices and networking. Input devices and networking portions are no longer updated, thou.

OpenGL is just a 3d library. You need to use other libraries for video (ffmpeg, etc), sound (openal, ao, sdl, etc), input devices (sdl, etc), and networking (opentnl, hawknl, raknet, etc).

A proper comparison is between OpenGL and Direct3d (the 3d component of DirectX). Of those, OpenGL is better in terms of ease of programming, more up to date (sometimes thru cumbersome and non-standard extensions, thou), and efficiency thru marshalling (only available in DirectX10).

Both Direct3d and OpenGL require you to use the OS api to create the windows to draw your 3d graphics on, albeit opengl provides GLUT which is a very bare-bones (portable) windows system.

See:
http://en.wikipedia.org/wiki/Comparison_of_Direct3D_and_OpenGL

For a simple code comparisons, here's what drawing a triangle looks like in each api in C++:


// OpenGL
#include <GL/gl.h>

void drawTriangle()
{
glBegin( GL_TRIANGLE );
glVertex3d( 0, 0, 0 );
glVertex3d( 0, 1, 0 );
glVertex3d( 1, 0, 0 );
glEnd();
}




#include <d3dx9.h> // or 10 or 8 depending...

// this needs to be initialized and released thru a bunch
// of directx calls before using it ( Direct3DCreate#, GetAdapterDisplayMode, CreateDevice ).
IDirect3DDevice9* pDevice = 0;

void drawTriangle()
{
D3DLVERTEX v[3];
v[0]=D3DLVERTEX( D3DVECTOR(0.f, 0.f, 0.f), 0x00FF0000, 0, 0, 0 );
v[1]=D3DLVERTEX( D3DVECTOR(0.f, 1.f, 0.f), 0x0000FF00, 0, 0, 0 );
v[2]=D3DLVERTEX( D3DVECTOR(1.f, 0.f, 0.f), 0x000000FF, 0, 0, 0 );
pDevice->DrawPrimitive( D3DPT_TRIANGLELIST, D3DFVF_LVERTEX, v, 3, 0 );
}

stew
03-28-2007, 11:53 PM
DirectX is cooler because it has an "X" in its name!

Just kidding. There have been enough good answers here, and I think a small web search will turn up more info than you ever wanted. First you should look at your requirements, that would certainly help you making your decision (for example, if it should ever need to run on a system that is not Windows, use OpenGL).

hus2005
03-29-2007, 08:34 AM
thank you all for answering

Novak002
03-29-2007, 02:19 PM
Heres my standpoint!... DirectX is used by most game companies because its quick to develop call all its built in input librarys and sound and math. However Its restrained to Windows & The Xbox, dont get me wrong thats fine. But OpenGL is multiplatform but the input and sound and math you all have to do yourself unless you go like download some other librarys. But hence the fact that OpenGL & DirectX r both good, im using OpenGL for my game engine and gonna add support for DirectX. Only thing ive noticed is well they seem to run about the same speed but im sure there are differences, only thing where i saw a speed up was drawing a Sphere in DirectX with 125 Million faces Rendered at about 5-7 Fps on my pc, and 1-3 fps on my old pc. OpenGL with a sphere at 125 Million faces rendered at 10-16 fps on my pc, and 1-4 fps on my old pc. I dont really think its too much of a sufficient test it could just also be the structure of my engine which speeds it up, but anyhow. I like OpenGL cuz they need to get in the spotlight again. However many game companies now combine the two, they use both. But nevertheless its personal prefrence and at one time your gonna have to learn both. So just take your pick for now.

705
03-29-2007, 03:41 PM
just curious,

I've seen news that NVidia already Support DX10. What does it mean? If I want do some game graphic programming stuff, will Open GL become a problem? Is OpenGL supported optimally by latest Graphic Card hardware? I mean....I never saw a Graphic Card with a label "Open GL xx Supported".

thx 4 any reply
Sorry for bad english

AsydWaters
04-08-2007, 05:28 PM
I am not that much familiar with all such mathematics, etc but I do know that Windows based Games are always better supported by Direct X due to it being a propierty of Microsoft.However in the field of digital design/2d/3d/modelling,architecture/animation/sfx etc softwares there's some conflict on the output render by the two.As I work on Rhino3d Nurbs modeller for character,mecha 3d art and walkthrus,Bryce for organics and Poser for human figures and postures ;and Rhino specifically says that it has problem with OpenGL if using it on Vista or XP.While Bryce demands an nVIDIA OpenGL as an essential to achieve good renders.
So I still can't figure out which is which and who is who?

stew
04-10-2007, 04:45 PM
I can't speak for Bryce or Rhino, but the reason we chose OpenGL for Poser is that Poser needs to run on Mac OS X too. DirectX is a Windows-only API.

705
04-11-2007, 02:38 AM
wew....that's a hard option
okay,quick short question(s)...
1. Game programming, platform free, which should I take?
1.1. And can some1 explain to me what is "cocoa"? <--Mac Things
2. What about the learning curve of both?
3. Does gc with support DX10 label make DX based 3d program faster/better/easier to develop than openGL?

~notThatShortHuh :)
~thx4AnyReply
~sorry4BadEnglish

UrbanFuturistic
04-11-2007, 09:58 AM
1 If by platform free you mean platform independent then that depends which platforms you want to support. If you want to include consoles in that, there is no single API that'll do the job but if you're looking at computers only then it's OpenGL all the way.

1.1 http://developer.apple.com/cocoa/

2. Couldn't say

3. DX10 support means it supports more advanced shader models etc. it doesn't make it any easier than DX8 or 9 as the basics are still much the same. Also, DX10 needs Windows Vista, it won't run on XP.

705
04-14-2007, 12:20 AM
I've seen a lot of Windows games ported to Mac OS(Blizzard's Products, EA's LOTR, Star Wars KOTOR, and even Halo). Are they using OpenGL or Cocoa(or else)? If not, is it easy to port the direct x based game into mac platform?

Ian Jones
04-14-2007, 06:05 AM
Don't confuse Cocoa with the two API's DirectX and OpenGL. Cocoa is a development environment that encompasses objective-c, the model-view-controller design pattern and of course is Mac OsX specific created by Apple themselves.

Porting to Mac OsX would of course neccessitate OpenGL in 99% of cases (there are other software based 3d rendering engines) but DirectX / Direct3D most certainly isn't an option in this environment. Whether a port uses cocoa (native OsX environment) and if it is easy or not is totally subjective, case by case.

A better goal to strive towards is cross platform and multi engine support, because of the adaptability and flexibility your program will be able to achieve. Vendors and API's come and go and change in quality, to achieve a longer lifetime for your software and a larger audience it's better to design cross platform and to offer capabilities for either systems Opengl or Direct3D and DirectX. You can do this by abstracting your rendering pipeline from the data handling, networking and control structures of your program using design patterns such as MVC (model view controller) and basically isolating the aspects of your software (eg the rendering) into a discrete module which can be easily modified, supplemented or removed.

It can mean some more work, but is a satisfying ideal to work towards. That's my opinion though. Simply read as much as you can on the topics and make up your own mind.

NB: One of the core philosophies of Object Oriented Programming is encapsulation, ie hiding data and implementation and separating the interface (connections and messages, not GUI). Using an OOP language to your best advantage will naturally aid a modular engine design.

Ideally you want for example a software architecture that allows you to make simplified abstract statements like "draw a square" rather than an esoteric interface eg, Draw a vertex, move, draw vertex, move, draw a vertex.... and so on. Of course you will have to write this level of process for each API (or use an existing one) but if your overall interface to creating a square is abstracted (read simplified, void of esoteric attributes) then you can at least modifiy your rendering API to a specific platform or technology without having to worry about the consequences it has on the rest of your program. That's the beauty of OOP, you can reuse functionality, discard, modify or replace modules (classes / objects) without too much concern as to how it affects other modules.

Robert Bateman
04-14-2007, 09:04 AM
I wouldn't care too much about whether you use D3D or OpenGL. The only caveat to that, is encapsulate all rendering code into one lib. That is, don't allow openGL or D3D calls to be littered throughout your program. Wrap the calls up so you have funcs like setCamera(), drawMesh(), bindMaterial() etc. Make sure that if the code is not to do with rendering, it does not exist within the renderer.lib.

We have basic renderers for PS3, Wii, 360, Windows and Linux. All of those are seperate static libs with the same interface. It's probably the easiest way of doing it.

From experiance, I'd say that D3D is easier to use on Windows than OpenGL - no horror of having to deal with the extension mechanism and the plethora of problems that arise with cheap and nasty graphics cards with shonky OpenGL drivers. On linux and mac, you don't really have any choice, you will be using OpenGL. OpenGL on Mac and Linux is however far easier to deal with. With linux, you are pretty much guarenteed that the user will have an Nvidia card (ATI linux drivers suck, so no one buys them). On Mac, the hardware is more standardised so again you pretty much know what graphics cards are likely to be installed.

I'd also point out that a lot of this discussion revloves around the graphics API's. DirectX does far more than just graphics - video, sound, user input etc. There is a very good chance that a windows version will be using some portions of directX - joypad input for example. Again, that shouldn't really be a concern, just make sure that it's encapsulated well and put together a different version of your wrapper lib for the other platforms.

Robert Bateman
04-14-2007, 09:13 AM
I've seen news that NVidia already Support DX10.What does it mean?

D3D10 is the newest version of the Direct3D API. This isn't *too* different from DX9, with a couple of notable exceptions :

1. The Fixed function pipeline has been removed, so you have to use shaders for everything now.
2. DX10 now has an additional shader stage, geometry shaders. This allows you to do stuff on a per-triangle basis, rather than just the per vertex basis available in vertex shaders.
3. It only runs on Windows Vista. It is not available for XP.

If I want do some game graphic programming stuff, will Open GL become a problem?

nope.

Is OpenGL supported optimally by latest Graphic Card hardware?

Yes and no. Nvidia have brilliant OpenGL drivers for linux and windows. ATI have fairly decent OpenGL drivers for Windows, though terrible drivers for linux. As you then descend into the catagory of onboard and cheapio graphics cards, the quality of the openGL drivers tends to vary from average to terrible. None of this however is in any way affected by DX10.

mummey
04-14-2007, 03:34 PM
I've seen a lot of Windows games ported to Mac OS(Blizzard's Products, EA's LOTR, Star Wars KOTOR, and even Halo). Are they using OpenGL or Cocoa(or else)? If not, is it easy to port the direct x based game into mac platform?

Cocoa is the Objective-C framework used in Mac OSX. Carbon is the C++ framework used for Mac OSX. Either one can be used with OpenGL (though I tend to prefer Cocoa.) Neither one is used to replace OpenGL; they are used to allow OpenGL to work with the OS (similar to how MFC would do on the Windows side.)

Novak002
05-08-2007, 01:46 PM
What a noob question, both are capable of incredible things. However its all up to the programmer. This question is mainly called the noob question because so many people ask it. Dont worry, I did too when I started learning proramming. And the real answer is that neither are better. Mainly people dont care about if they used directX or OpenGL because most of the programmers code is just using small parts of it and abstracts it out as much as possible. So really thers no need to ask this question. The only differences are DirectX is stuck on windows you cant put it on any other operating system, as for OpenGL is multiplatform. It pretty much runs on everything.

polywrangler
05-09-2007, 04:37 PM
just wondering if there is an implementation of a shader language like HLSL under opengl? and if so does it support geometry instancing?

mtartist
05-09-2007, 04:46 PM
just wondering if there is an implementation of a shader language like HLSL under opengl? and if so does it support geometry instancing?

GLSL - OpenGL Shading Language

As for geometry instancing, I think not (not sure though).

Ian Jones
05-10-2007, 07:59 AM
perhaps geometry instancing is be part of OpenGL 2.0 ?

stew
05-10-2007, 08:21 AM
What would geometry instancing do that display lists can't do?

UrbanFuturistic
05-10-2007, 09:49 PM
Well, for starters you can't have dynamically moving/altering/reacting geometry in display lists and this opens the possibility of speeding things up greatly by only having to blit the data across to the GPU memory once.

GL_EXT_draw_instanced is available as for OpenGL 2.0 but will only work on G80 based cards as of yet. There is also the older NVX_instanced_arrays extension but it's difficult to say how much that was actually used and, as it was an experimental extension, will probably not be used in the future.

Apparently (or so I've read) it wasn't considered as urgent for OpenGL because it doesn't have the huge overhead of doing API calls through COM but talks direct to the driver.

CGTalk Moderation
05-10-2007, 09:49 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.