Archived

This topic is now archived and is closed to further replies.

2-API 3D engine

This topic is 5530 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

What if I wanted to make my engine OpenGL as well as DirectX "compatible"? How would you approach the coding? Not sure exactly where to start.. Ideally, you do something like SetRenderAPI(OPENGL); At the beginning of your code. [EDIT] Of course this is to make the player have to choose between openGL and d3d rendering before starting the game... Not just the coder! [/EDIT] But what about the rest of the program, if you were to call different functions API respective, even though you set the renderer the whole thing just seems useless.. But then again, how would you write general functions useable with both API:s? Gah I'm sure there's a simple answer to this fairly simple question, since the answer is out there somewhere! I just need to see the light /Sandman [edited by - Saandman on October 19, 2002 5:31:42 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You can use a generic class CGeneralAPI with abstract members. If you derive two classes, CDirectXAPI and COpenGLAPI, you can refer with pointers to an object of CGeneralAPI type. Your instruction

SetRenderAPI(OPENGL)

becomes

CGeneralAPI *myAPI=new COpenGLAPI()

In the rest of the program if you call

myAPI->Render()

you will call the method of COpenGLAPI class.
Instead, if you declare

CGeneralAPI *myAPI=new CDirectXAPI()

myAPI->Render() will call the method of CDirectXAPI.
Of course you have not to change your code each time! You can read the choosen API from a file where you put your configuration settings, for example.

I hope this help you.

Fil (il genio)

Share this post


Link to post
Share on other sites
Thats exactly what I''m doing in my current project...

The most important thing is to devise a standardized way to render geometry (of ANY type). preferably with 2 variants for static and dynamic data.
I chose to use vertex and index buffer objects, that the current renderer object controls behind the scenes.
Also to have a standard way to setup things like blending/shading/camera/lights etc AS OBJECTS. And, importantly, let the renderer it''self manage states. Don''t allow the rest of the app to do this, This leads to absolute disaster.

If you can write things like text renderers, etc, only once in the base class, then your on the right track. Once you find you have to write something again that doesn''t need to be, then you know you have made a mistake in your design. Basically, the only code that ends up in the derived renderer objects should be API calls. No maths, etc, at all. (unless it''s api specific, say, like the projection matrix setup)

<-- smile :-)

Project-X

Share this post


Link to post
Share on other sites
This is what I''ve been running through my head recently. I''m working on a FPS and am going to use Quake3 BSP and MD3 files, and pretty much all the demos or tutorials are in OpenGL, since Q3 was in openGL. I have only studied DirectX and would like to just use OpenGL to load the map and model, but use DirectX for the rest of the game. Would this work? It would let me forego learning a totally new API...and that would be good.

Thanks!

It is coming...8 years in the making and It is finally coming...

-Beavt8r

Share this post


Link to post
Share on other sites
OpenGL has nothing to do with loading the maps and models. That''s called file I/O, which is completely unrelated to graphics API''s. Before you tackle this project, I''d suggest you go back to a good C/C++ book and read up on the basics first.

Share this post


Link to post
Share on other sites
Whoops. I guess I wasn''t clear on my post. What I meant was that I was going to use OpenGL to load AND display the maps and models, and use DirectX for the rest of the graphics. There are a ton of resources and tutorials on MD3 and BSP Q3 files and how to load, etc...so I figured it''d be easier if I could use OpenGL to load and display them and use DirectX for the rest. I was just wondering if it would be easier to use OpenGL for the maps & models (displaying) and use DirectX for the rest than it would to convert the OpenGL code for displaying to DirectX.

It is coming...8 years in the making and It is finally coming...

-Beavt8r

Share this post


Link to post
Share on other sites