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.

  • 1
    \$\begingroup\$ Why not just use only OpenGL? Also, what language are you using? \$\endgroup\$
    – Apples
    Jan 31 '13 at 19:00
  • \$\begingroup\$ 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? \$\endgroup\$
    – MichaelHouse
    Jan 31 '13 at 19:00
  • 1
    \$\begingroup\$ 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). \$\endgroup\$ Jan 31 '13 at 19:16
  • \$\begingroup\$ Here is a related question, though more specific. \$\endgroup\$ Jan 31 '13 at 19:17
  • \$\begingroup\$ Why do you net a platform check? If you compile it for windows, allow OpenGL and DirectX (or DirectX only). If compiling for other platforms: OpenGL only. There's no need for a runtime check. \$\endgroup\$
    – Tara
    Nov 30 '15 at 17:09

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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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