Jump to content
  • Advertisement
Sign in to follow this  
programmermattc

OpenGL DirectX to OpenGL Question

This topic is 3664 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been working with DirectX for a few years and it wasn't until I went and did some XNA that I could really program in it and understand what was going on. I've looked into OpenGL a very small amount but would like to look into it more (what I've done previously was quite simple). What would you say about the programming differences between something like DirectX and OpenGL? Not which is better, but if I were going to program in OpenGL with a DirectX background, what would I find different, what would be very similar, etc...?

Share this post


Link to post
Share on other sites
Advertisement
One thing to get used to is the lack of support functions (the D3DX collection). OpenGL is a rendering API, and a rendering API only. You'll need to seek outside libraries for vector/matrix maths functions and the likes. There's also no support for model formats (.X), you have to again look for a library or write your own format loading functions.

Other than that, things should go quite swimmingly - D3DBegin() is now glBegin(), vertex buffers are now vertex arrays, it shouldn't be too hard to pick up.

Share this post


Link to post
Share on other sites
I don't like how you setup vertex formats on DX, OpenGL is IMO a simpler and more flexiable method. IBO and VBO are similar. GLSL vs. HLSL is just semantics. OpenGL doesn't have the built in math libs, or model, texture loading code, but you can find many libs that are well suited for your needs. And if you use a Physics lib like PhysX it comes with its own math lib, and is a very nice math lib IMO. Texture loading, just code your own or use DevIL or some image loader. There isn't any FX file for shaders in OpenGL like DX has. Some people like it, some don't. Me I could care less. DX is left handed by default where GL is right handed, and the screen coordinates are flipped on Y axis, DX starts upper left, GL lower left.

Share this post


Link to post
Share on other sites
So it seems the biggest difference is that DirectX is more of a 'suite' API for more than just graphics whereas OpenGL is more of the graphical portion of it. If I would want to build my engine using lots of different 'pieces' OpenGL seems better suited for that?

By the way, (keep posting :) ) but thanks for describing it at almost an architecture level instead of like 'Well this keyword is different and...'

Share this post


Link to post
Share on other sites
Quote:
Original post by MARS_999
I don't like how you setup vertex formats on DX, OpenGL is IMO a simpler and more flexiable method.
If you're talking about FVF (D3DFVF_XYZ etc), that stuff has been deprecated for years. The D3D vertex declaration stuff is actually a little nicer than OpenGL, I've found. I usually rewrite the vertex declaration functionality for OpenGL, a task which can be finished off in about half an hour.

Share this post


Link to post
Share on other sites
Quote:
Original post by Promit
Quote:
Original post by MARS_999
I don't like how you setup vertex formats on DX, OpenGL is IMO a simpler and more flexiable method.
If you're talking about FVF (D3DFVF_XYZ etc), that stuff has been deprecated for years. The D3D vertex declaration stuff is actually a little nicer than OpenGL, I've found. I usually rewrite the vertex declaration functionality for OpenGL, a task which can be finished off in about half an hour.


Yeah, thanks for the tip Promit. I will keep that in mind if I use DX again.

To the OP, yes if you want to use GL, GL is nice for using whatever lib you want to with it, DX in essence can use whatever you want also, but many coders who use GL tend to code nice libs to use with it. For me the ability to code once and run anywhere is a huge reason for me.

Share this post


Link to post
Share on other sites
Quote:
Original post by programmermattc
So it seems the biggest difference is that DirectX is more of a 'suite' API for more than just graphics whereas OpenGL is more of the graphical portion of it. If I would want to build my engine using lots of different 'pieces' OpenGL seems better suited for that?

By the way, (keep posting :) ) but thanks for describing it at almost an architecture level instead of like 'Well this keyword is different and...'


Honestly that's how I feel.

A very simplified view of the two API's in my mind is this:

DirectX = an 3D gaming API that can be used to develop generic 3D apps.

OpenGL = a generic 3D API that can be used to develop 3D games.

Some things are easier in DirectX, some things are harder. The same can be true with OpenGL. For years rendering to a texture for example was trivial in Direct X whereas in OpenGL it was like pulling teeth by comparison. It wasn't until things like FBO's etc appeared when OpenGL made rendering to a texture a tad less painful.

Another similar example is with vertex rendering. OpenGL allows you to do this very easy with simple glVertex calls but it is too slow for real-time 3D game performance. There's a faster way in OpenGL but it's more complicated to setup and execute. By comparison DirectX ONLY allows you to do it the fastest way and no other way since no game would EVER do it any way but that way (again this is a simplified view)

Also one other note is OpenGL is a state machine while DirectX is an object based API.

Share this post


Link to post
Share on other sites
Direct3D rapes OO design and leaves it dead.

The only thing that keeps me tied to GL is that it's API is good. If the D3D API was even acceptable to me I might even use it. For everything else (apart from cross-platformability) I think D3D is better, mainly because it's well-defined, unlike GL where you have to write multiple code-paths if X extension isn't supported on Y machine.

Share this post


Link to post
Share on other sites
Quote:
Original post by biggoron
Direct3D rapes OO design and leaves it dead.

The only thing that keeps me tied to GL is that it's API is good. If the D3D API was even acceptable to me I might even use it. For everything else (apart from cross-platformability) I think D3D is better, mainly because it's well-defined, unlike GL where you have to write multiple code-paths if X extension isn't supported on Y machine.



Yes, but those extensions are also what keep OpenGL on par with DirectX, and even better in some parts. And the extensions are also mainly portable across platforms once they get approved by ARB. Which means OpenGL already has geometry shaders just like DX10. DirectX can't do anything that OpenGL can't match on the rendering side.

Share this post


Link to post
Share on other sites
The problem is that extensions are just that ... extensions.
It's not garanteed to be available even when the hw supports it (Intel and ATI).
Maybe some day "we" can figure out how to make a feature available everywhere at the same time. Oh, that's called making it to core. Khronos needs to hurry things up.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!