Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am currently developing my engine with DirectX, but I want to make it cross-platform in the future, using OpenGL.

How can I check which platform my engine is running on? And can I use an if statement after I've checked the platform to say which renderer to use?

I currently have an abstract renderer and a DirectX9 renderer as it's child.

share|improve this question
    
Why not just use only OpenGL? Also, what language are you using? –  DBRalir Jan 31 '13 at 19:00
    
Platform check is going to be language dependent and should be pretty easy to find in Google. Though I'm not sure why you included all the other information about switching between OpenGL and DirectX unless you were looking for a discussion related to that... Why not just go full OpenGL? –  Byte56 Jan 31 '13 at 19:00
    
Plenty of reasons to not go GL only and two of them are "AMD" and "Intel" (a third is "NVIDIA" but for a different class of problem). –  Jimmy Shelter Jan 31 '13 at 19:16
    
Here is a related question, though more specific. –  Sam Hocevar Jan 31 '13 at 19:17
add comment

1 Answer 1

Advice: Don't do this. It is a complete waste of time. You will have to rewrite your engine after the 1st time doing this. If you're just starting out in graphics development, wasting time with low level API functionality equivalences is not going to teach you much, it's just going to be very tedious work.

That said, if you have to, then design a bunch of abstract interfaces to interact with a graphics API. THen write concrete classes underneath that, that actually interact with the specific API chosen.

Examples are: abstract classes for GraphicsWindow, VertexBuffer, Surface (frame buffer in OpenGL, surface in D3D). You then write concrete implementation classes D3DWindow : public GraphicsWindow, OpenGLWindow : public GraphicsWindow.

Example of a method: In GraphicsWindow you would provide a pure virtual method void flipBuffer()=0. Implementation would be different for OGL and D3D, and the implementation code would be in their respective classes.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.