system
Given the following post, respond as if you're commenting on Reddit:
human
How do programs draw to the screen?

I have already done a few operating systems classes and know a fair bit of coding, but in the process of writing a GUI program for learning purposes i realized that i have no idea how the GUI is drawn to the screen. There are a lot of libraries for java like swing and javafx that do a lot of the heavy lifting in the background and where most of the actual work of creating the window is abstracted away behind a few functions. But i'd like to know how that happens. How are those libraries build, are they written in opengl, ore something even more low-level? Do these window creations happen with a syscall by the operating system? I have no idea, but i'd like to know. My research did not come up with anything, so this is my last resort.I hope i have asked my question so that it can be understood and thanks for the answers in advance.
gpt
ultimately there is some RAM that represents the content of the screen. It will actually reside on a graphics chip somewhere but the OS memory maps it so it appears to be addressable by the cpu, usually at a fixed address. This portion of memory will be blitted to the sceen 60 times a second or whatever. If you know the address you can read or overwrite any part of what is displayed, and not too long ago if you were making a fullscreen game that is what you would do, and the screen\_base\_address would be part of a public api available for that purpose.

Nowadays, on OSX at least, you really have to be a good citizen and not just go drawing over any part of the display - so there are public api's (not just one.. old, new, different level's of abstraction, hardware accelerated, etc.) that make window buffers available. You draw (i.e. manipulate the memory) into these and the OS will composite those into the (private) screen buffer.

If you want to draw images into there, or polygons, or sprites, or text, or video, or voxels, etc. the OS is going to have an API for that, so you don't have to manipulate the window buffer directly, but you can if you want to.