can opengl and d3d play nicely together?

Started by
5 comments, last by xtrmntr 21 years, 5 months ago
The title is a tad misleading but but i thought it might attract more attention (good and bad). This is not a post about which is better, in fact its almost the exact opposite. With that said let me tell you what my question is. Me and a friend our writing a game. This will be my first time writing one in 3D. I have been spending my time reading and playing with openGL while the other guy has only done 3d programming in Direct3D. We have agreed to do it in both languages since our schedules are sort of hectic with our lives/work. So right now i have the initial windowing code and a settings dialog to let the user initial choose which 3d lib to use and what resolution they wish to play in. I have also studied and modified one of the articles here that allows you to dynamically load either openGL or D3D at runtime. Both of these portions are working just fine but i have hit a wall so to speak. My question: is there a way/design method to make the different calls to either library? The way it is now the programmer is given a pointer to a renderer. This pointer could signify either OpenGL or Direct3D. Is their some other way to structure this without having to wrapper every call that would be similar to each library into a function that this pointer can call? Is there a different OO ideology to handling something of this nature? Thanks for listening. And by all means ask me as much as you need to try to help me out here.
Advertisement
You'll need wrappers for all functions. There's no way around that. From a design point of view, you'd have some abstract base class and then derive an OpenGL-specific class and a Direct3D-specific class.

For a proof of concept see my engine http://xengine.sourceforge.net which pretty much does all that.
Note that the engine is still in alpha stage of development, although the core render system works pretty well already. Thus there is no downloadable release yet and you'll have to get everything out of CVS.

Cheers.


[edited by - Asgard on November 3, 2002 11:05:33 AM]
----------------------XEngine - The Platform- and API-Independent 3D Engine with Programmable Pipeline Support: http://xengine.sourceforge.net My Music on MP3.com: http://www.mp3.com/GroovingArts
Thank you very much for the link Asgard. Though your implementation is more complicated than I need to make it, It will definitely be a good reference for me.
I used a dynamic .dll file for mine. Basically, the main engine loads a given .dll file, and sets the appropriate pointers to functions. The benefits of this, is that I can have any type of .dll file... direct x, opengl, glide, software, etc... and you can add/modify them without changing the main program at all. I had mine doing the creation of the window, drawing of primitives, display of vertex buffers, multi-texturing (automagically did single or multi-pass based on some params, so my program didn''t have to worry about it), setting the colors, etc.

Billy - BillyB@mrsnj.com
I think that the best is to choose only one API (I choose OpenGL because of portability), but you can use a wrapper that emulate DirectX calls with OpenGL or OpenGL calls with DirectX...
If you're pressed for time the last thing you should do is program for both APIs. Unless there's some other reason why you'd like to support both APIs just pick one and stick with it. Decide which one of you will do the graphics programming and choose the API accordingly. Let the other person work on a different part of the game.

[edited by - chronos on November 8, 2002 12:04:22 AM]
I agree with chronos. My engine supports both DLLs through an abstract wrapper, and while I think it''s great fun writing the wrapper, it does certainly slow things down. Programming it isn''t the hard part, designing it is - the wrapper has to be fairly high-level to support both APIs well.

~CGameProgrammer( );
~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.

This topic is closed to new replies.

Advertisement