So difference between coding in OpenGL and DirectX?

Started by
21 comments, last by johnnyBravo 19 years, 11 months ago
Hi i''m so far using directx for coding stuff, and I find that i don''t like their coding styles, eg calling one of those ugly names such as: LPDIRECT3DDEVICE9,LPDIRECT3DVERTEXBUFFER9 etc and the fact that they use pointers for some reason.. why? So basically what I see in direct3D is that you have to declare objects for everything. BUT! Open GL is more method based, you just put points into methods etc to draw stuff eg

  glColor3f (1.0, 1.0, 1.0);
    glBegin(GL_POLYGON);
        glVertex3f (0.25, 0.25, 0.0);
        glVertex3f (0.75, 0.25, 0.0);
        glVertex3f (0.75, 0.75, 0.0);
        glVertex3f (0.25, 0.75, 0.0);
    glEnd();
But this is just speculation, ive been trying to find gl code examples and this is the first thing ive so far found. What I''m wondering is, which is nicer to code in, and is opengl more method based than directx? or at all? Thankyou,
Advertisement
I chose OpenGL over DirectX a year ago for my project, and haven''t regretted it yet.
The capitals hurt my eyes too, and make the code look awful.
That code is valid OpenGL - IMO it''s a lot easier to learn and more intuitive (flame war starts here ).

One thing to remember though, is that DirectX has the D3DX utility stuff though, which can help a great deal further on into your project (e.g. helps loading 3d meshes and displaying them efficiently (LOD)).

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndrive/html/directx11192002.asp
Hi
Example that you posted is one of the ways of declaring obiects using OpenGL.
At http://nehe.gamedev.net/ in Lesson 45 there is an example of Vertex Buffer Objects.

The most important difference beetwin OpenGL and DirecX is that OpenGL has C syntax (structural), when DirectX is more Obiect Oriented (C++).



"The Gods Made Heavy Metal And They Saw That It Was Good They Said To Play It Louder Than Hell We Promised That We Would
When Losers Say Its Over With You Know That It’s A Lie The Gods Made Heavy Metal And It’s Never Gonna Die"

THE GODS MADE HEAVY METAL/by ManOwaR
"The Gods Made Heavy Metal And They Saw That It Was Good They Said To Play It Louder Than Hell We Promised That We WouldWhen Losers Say Its Over With You Know That It's A Lie The Gods Made Heavy Metal And It's Never Gonna Die"THE GODS MADE HEAVY METAL/by ManOwaR
1.) Learn both. They both have advantages and both arent hard.
2.) You are right in that its more method based but your comparison is utterly wrong.
Your OpenGL example is way slower than the DirectX one. Dont you think a little effort of a vertexbuffer is worth the extra work. As has been mentioned, if you choose to learn OpenGL first, sont forget to look into VerteXBuffers for OpenGL as well.

-CProgrammer
First of all, that LPDIRECT3DDEVICE9 names are just typedeffed. The original name is IDirect3DDevice9*, so you don''t have to use that capitalized names everywhere. Indead for constants you have, but opengl has capitalized constants too. For small things OpenGL is definately nicer, but for larger projects, you will probably put everything in a vertex buffer for both opengl and directx, so you won''t be using those nice functions any more. And with OpenGL you will have to initialize all those extensions. But you can do that with Benjamin Bunny''s glee.

My Site
Personally, I think my biggest issue is, OpenGL is portable, DX isn''t. The OpenGL style has been used by a few other real time media API projects as well. OpenAL (Open, 3D, portable audio library) and DevIL (Open, portable image library) as use SGI''s sytax style.

In reality, most engines wrap up the rendering code in more help objects so you won''t see a lot of the API''s code in the game code. Personally, I find the lack of pointers and things in OpenGL makes in easier to debug too.

But, graphics API, like religion, is a very personal choice.
ive learned all the basics of dx eg vbs, basic lighting etc.

zoggo has pointed out the ultimate point in this typical question on DX-OGL. Any well written larger project writes helper classes. In the end of the day it will be irrelevant what you use and the best is you choose one and write nice helper classes enabling you to add support for the other easily.
-CProgrammer
I''ve learnt D3D, but we''re doing OpenGL in uni, and i''ve been reading Daves book - OpenGL Game Programming because i want to learn OpenGL. From what i''ve seen so far, I prefer D3D. I miss the D3DX library in OpenGL, and the extensions are a pain in the ass, since you need to write codepaths for card that don''t have an extension. D3D has the device caps which are neater IMO, and D3D is able to emulate some features in software.

Although, the mighty Carmack uses OpenGL, so that gives me more insentive to give it a fair try
Let the flame war commence...

Seriously though, both opengl and directx are good at what they do and are just as capable as each other. They are both widely support by professional companies so it is just a matter of PERSONAL preference. Don''t bother trying to indoctrinate the ''disillusioned'' just choose one you like for your own reasons and use it. Or if you are undecided how about going down the paths of others and try to implement an interface that can allow you to use either.

This topic is closed to new replies.

Advertisement