In particular, DirectX and OpenGL work by invoking the operating system and / or video device driver. The driver, in turn, makes the actual drawing, interacting with the graphics device. The exact details of the interaction vary from one video card to another.
Returning to DOS days, C ++ programmers could work directly with the equipment. This has been achieved in two ways. Firstly, by writing / reading from a special block of memory ("framebuffer") where pixels or text were saved. It was a memory gap at a known address, so to work with it you had to specify an integer constant in a pointer and work with this pointer. The mechanism is pure C ++. Another way to interact is to read / write to I / O ports. Now this is a mechanism that is not directly supported by C unless you want to read the built-in assembly or the internal integrity of the compiler. There were two library functions that would wrap these two operations (literally, wrappers around the two CPU commands - INP and OUTP), but most programmers would simply use a single-line inline assembly fragment.
Even now, most interactions with video equipment boil down to these two paths - framebuffer and I / O ports (DMA and interrupts are usually not used for graphics). But we programmers at the application level do not see them. This is material for drivers.
One modern warning is related to protected mode; in protected mode, the C pointers do not match the underlying physical addresses. Just casting the type 0xA0000 to the pointer will not lead you to the framebuffer even in kernel mode. However, kernel-level code (such as a driver) may ask the memory manager to indicate a pointer corresponding to a specific physical address.
Seva Alekseyev
source share