Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Supporting both DirectX and Opengl

  1. #1

    Supporting both DirectX and Opengl

    Hi guys and gals

    I'm busy writing the basic framework for the InfinitEngine for the InfiniteSpace-online project.

    Now I would like to be able to support both Opengl and DirectX. The current idea is that the correct dll is loaded a runt-ime based on which rendering engine you want to use. this works very well, and I have a very basic triangle appearing in both Direct and Opengl.

    Opengl




    DirectX




    Now some of you will be able to spot the problem. Because DirectX used a Left Handed coordinate system, the triangle in the DirectX looks different. Also the triangle looks further away in the DirectX window, dispite having the same eye location and look at points.

    Now I have read some documents about this problem , the solution M$ give is to revers the vertex order on every vertex you send to get the same results and to scale the view matrix by -1 in the z direction. This is the document I found

    http://msdn.microsoft.com/library/de...te_Systems.asp

    Now there has to be a better way than this. I'd rather not have to put in extra processing to sort out my verticies for all calls to directX. And to be honest I haven't done any directX coding for about 6 years so I wouldn't know how to scale the view matrix by -1 in the z direction.

    Has anyone tried to support both opengl and directx before? If so how did you resolve this problem?

    Any ideas?

    Dean
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  2. #2

    Supporting both DirectX and Opengl

    don't bother with this, just support one GFX library.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  3. #3

    Supporting both DirectX and Opengl

    I haven't ever tried to support multiple rendering engines before :shock: (Hope that works out )

    But having dealt with multiple co-ord systems, typically thats the easiest option, reversing the view matrix and vertex orders.

    Which would you pick as your 'Main' renderer (Most strong at coding in)? OGL?
    What about keeping the DX Left handed system, and flip it in OGL instead?

    ---

    Instead of modifying the vertex order, would flipping the backface around work?

    glEnable(GL_CULL_FACE);
    glCullFace(GL_Front);

    Or something to that effect. It's a littke hackish, but it's all visual in the end.

  4. #4

    Supporting both DirectX and Opengl

    I think that it is easier to change OpenGL to work with D3D coordinate system. Use glFrontFace(GL_CW) to set clockwise polygon orientation as in D3D. This way you can use same vertex layout for both apis. To scale world space call glScalef(1.0,1.0,-1.0) before any view transformation.

    You can also take a look at Irrlicht engine. It supports D3D, OpenGL and even software renderer.

    But to be honest I agree with Defi.

  5. #5
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Supporting both DirectX and Opengl

    Hmm... well to be honest. If you had to slow one or the other down lets look at who you'd be slowing down if you choose one or the other.

    DirectX: Some Windows users that prefer DirectX.

    OpenGL: Some Windows users that prefer OpenGL. All Linux, MacOSX and BSD users.

    Now this isn't really taking into account Vista, but then again who cares about that now. It's not even out yet and I doubt that MS will get a away with slowing down another API just to boost their own for very long. [size=9px](Vista sales will suffer for it and there'll be more new Linux users in the world.)[/size]
    Jason McMillen
    Pascal Game Development
    Co-Founder





  6. #6

    Supporting both DirectX and Opengl

    To be clear on this, with opengl you are actually on better in vista, you will have full hardware acceleration as long as you'll have proper gfx drivers installed. on vista opengl runs in like 2 or 3 modes:

    - DX wrapper, see: http://www.delphi3d.net/hardware/vie...hp?report=1566
    - opengl drivers from windows xp driver model (no aeroglass in windowed mode, but full speed)
    - fully accelerated opengl driver from a graphics card vendor (nv & ati)

    so yeah, opengl is working well on vista.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  7. #7

    Supporting both DirectX and Opengl

    I found out how to do it. Basically you need to trow away calls to gluPerspectrive and D3DXMatrixPerspectiveFovRH etc. and do your own Perspective calculations and set the matrix manually.

    You also need to ensure that the vertex order mode is the same i.e CCW or CW.

    I just need to find some good matrix classes now that support in built functions like Perspective and Orthographic, or find a reference on wikipedia.
    <A HREF="http://www.myhpf.co.uk/banner.asp?friend=139328">
    <br /><IMG SRC="http://www.myhpf.co.uk/banners/60x468.gif" BORDER="0">
    <br /></A>

  8. #8
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Supporting both DirectX and Opengl

    Thanks for correcting me Delfi. I have no desire to jump on the Vista bandwagon so I'm a bit outta touch with the specifics.

    However for matricies... what about those libraries that Daniel was talking about earlier in another thread? Those of any use to you?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  9. #9

    Supporting both DirectX and Opengl

    Quote Originally Posted by WILL
    Thanks for correcting me Delfi. I have no desire to jump on the Vista bandwagon
    yeah same here, but i would pay a full price of vista ultimate to have DX10 on my XP to play some cool games like alan wake & crysis...
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  10. #10
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Supporting both DirectX and Opengl

    Well the new next gen games are tempting no?

    So in supporting both OpenGL and DirectX which functions are unique to one and not the other?
    Jason McMillen
    Pascal Game Development
    Co-Founder





Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •