In the beginning, there was DOS. People wanted to make video games for computers running DOS that looked really good and ran fast, but the majority of computers were extremely tight on resources compared to the luxuries we have today, and as a result they had a limited color palette and not a lot of raw power to draw an image fast enough.
One of the ways people worked around the limitations was by using dithering. This is a technique used to make a limited amount of colors look like new colors to the human eye, by drawing two or three colors near each other in a pattern, like checkered or alternating. You could also vary the proportions of colors in your dithering to create the illusion of lighting as 3D objects were moving on the screen. This was a great way to get a lot more out of simple hardware and small video memory.
Computers and software advanced, and eventually Microsoft released Windows. This is nothing like the Windows you may be familiar with today, I'm talking about Windows 3.1. If you upgraded a computer that shipped with DOS to Windows, suddenly Windows was using the graphics hardware to draw itself. If you wanted to make a Windows program with graphics, you had to go through Windows' APIs, and if you wanted to run a DOS game that needed to do wizardry on the video card, you usually needed to close Windows (You could do that!) and launch the DOS game directly in DOS. The Windows APIs were great for business applications but dogshit slow for trying to recreate tricks like dithering to use in games.
Microsoft created a library called WinG that included lots of fast graphics drawing routines you could use to implement games and other graphics applications on Windows. It was nearly as fast as the tricks DOS programmers were using before, but you could use it inside Windows.
WinG was the precursor to the first versions of DirectX. Most of what WinG could do was reimplemented a better way and new functionality was added on top, and this evolved into the DirectX Windows has today.
It was still possible to install WinG and play 16-bit Windows games that need it as late as Windows 7! (I have no idea if it still works today on Windows 10 or 11, but Windows is an enormous fucking pile of backwards compatibility hacks like you wouldn't believe so I'm sure 32-bit Windows 10 will still run 16-bit applications. SOMEONE is still running a business application at their company that they will never update.)
But early games used proprietary APIs for hardware-based 3D rendering — If you didn't have the exact line of cards your game was designed for, everything was rendered in software on the CPU. Card manufacturers had competing APIs, and OpenGL was still in its infancy, where Microsoft had yet to support it *fully.
DirectX unified 3D rendering under a single API on Windows systems via Direct3D. Instead of targeting [X] card, you would target DirectX, and the card designer would be responsible for how those calls were carried out on the backend, via drivers.
As a result, you could use any graphics card you want to run 3D software, as long as it is DirectX compatible, which was a very desirable proposition for the average consumer, and even businesses, whilst being a better proposition for Microsoft than OpenGL, which could target other platforms, pushing developers to develop for Windows first with DirectX.
Please do your own reading to learn more; To clarify, OpenGL did exist at the time, Microsoft just wanted to be anti-competitive, and graphics card manufacturers were also being saucy with proprietary APIs in spite of OpenGL.
Edit 3: I am talking specifically about hardware rendering here. Also, please note that DirectX as a whole is a collection of Direct, well, [X], as in [insert name here], technologies, such as DirectDraw, Direct3D, DirectInput, DirectSound, etc. — They all have reasons to exist.
