Basically, OpenGL is an open source software to make the games run on hardware.
DirectX is closed and is only developed and changed by MS.
They both try to achieve the same purpose, i.e. they both are APIs. Difference lies in their implementation and not necessarily usage. e.g. UNIX is open source and can be changed by anyone, while Windows or Mac may not. They all are same things in the end: OS. Difference lies in their implementation and not necessarily usage. e.g. some or all of them can be used to run Excel to make or edit spreadsheet. Its not an apple to apple analogy, but I hope you are able to understand what I am trying to say here.
Many games use only DirectX therefore only run on Windows. Many games can use any of them and its entirely possible that they still only run on windows. OpenGL has the facility to make a game run on Linux e.g. or Mac. Similarly, there is another API in the market called Vulkan which is also Open source I believe.
What API to use depends on the usage scenario and possibly the game engine used. eg. ID tech can use Vulkan and Open GL to run games in Unix platforms in addition to windows. While, Assasin's Creed, e.g. works only on Windows since it supports only DirectX AND the developers have not ported it to Linux.