PDA

View Full Version : Porting from Direct3D to OpenGL...



savage
24-06-2007, 02:31 PM
Does anyone have any experience porting from Direct3D to OpenGL?

If so what pitfalls should I look out for? Any Hints/Tips welcome.

technomage
24-06-2007, 10:16 PM
Hi Dom

I've not ported stuff from DirectX to OGL before, but I have tried to write a single API to work with both.

One of the main differences I found is that there does not seem to be any way in DirectX to save the current state like you can in Opengl with glPushAttrib and glPopAttrib.

Other differences come when setting colors for Verticies, in opengl if you use Immediate mode to send your data (I would recommend you don't , but it is very useful to start off with), you must remember to send data such as color, texcoords , etc BEFORE sending the glVertex call.

DirectX does not have an immediate mode as such , you have to use Vertex buffers / Arrays.

My main problems however have been in dealing with textures, and the fact that DirectX works in the Right Hand coordinate system while OpenGL works on the Left (or the other way round) . Basically they are different, so if you want to make use of built in functions like gluLookAt you have to keep that in mind. I decided to force OpenGL to use the same coordinate system as DirectX but if you do that you have to code most of the glu style functions yourself.

Hope this helps :wink:

Galfar
24-06-2007, 11:40 PM
One of the main differences I found is that there does not seem to be any way in DirectX to save the current state like you can in Opengl with glPushAttrib and glPopAttrib.


You can use IDirect3DStateBlock9 interface to capture current render states and apply them later
(although Push/Pop attrib is easier to use).
http://msdn2.microsoft.com/en-us/library/bb205887.aspx