Switching between renderers doesn't make much sense on any other platform that Windows at the moment, so your request for windows, linux, mac, ios and android support sounds strange. Perhaps you're looking for a library that helps you to be portable in general?
To achieve running with one renderer or the other (opengl/d3d), or to achieve portability in general, you need to implement some kind of portability layer.
Basically, you could start by writing two programs: one that draws a rotating cube in OpenGL, and another, completely separate that does the same with D3D. Next, write a third program that combines these, by:
- Abstract differing things from the two applications behind a common interface
- Such as, but not limited to, once you get into various platforms:
- Application control loop
- Renderer (i.e, graphics output)
- File I/O
- User input
- Audio
- System services (threads, etc)
- Such as, but not limited to, once you get into various platforms:
- Implement the common interfaces on all target platforms
- Implement application functionality only through the abstraction interfaces
The D3D and OpenGL on windows can practically be considered separate platforms, but you could pick one or the other during application startup - the choise would probably affect renderer and also the application control loop.
Switching during runtime is also entirely possible, but probably way too much hassle to be worth it.
You may note that SDL actually does a lot of the above.