Every programmer hits this moment. You draw your first rectangle, nudge it "up" by increasing Y, and it slides down instead. You flip the sign, it works, and you move on. Almost nobody stops to ask why the screen disagrees with every math class they ever took.
Here is the answer, and it is older than you think.
In a math class, the origin sits where the axes cross and Y climbs upward. Open almost any graphics API and (0, 0) is the top-left corner, with Y falling as you move down the screen. Beginners assume someone made a bad call. Nobody did. The screen has carried two different origins for decades, and both are still in use, because they come from two different machines.
Why the screen counts from the top-left
The top-left origin is a fossil of the cathode-ray tube. A CRT draws a picture by sweeping an electron beam across the glass one line at a time, starting at the top-left, moving left to right, then dropping to the next line down. That is a raster scan, and video memory was laid out to match it: the first byte is the top-left pixel, the next is the one to its right, and the last is the bottom-right.
So the "first" pixel is top-left, and Y grows downward because that is the direction both the beam and the memory travel. Text terminals inherited the same idea: line 1 is at the top, and the cursor moves down. The convention is not a preference. It is the shape of the hardware.
The other lineage: math kept its origin
Meanwhile, the mathematical world never gave up the Cartesian origin: bottom-left, Y up. Pen plotters drew like a person doing geometry on graph paper. And the systems built on top of that math kept it. PostScript and PDF place the origin at the lower-left of the page with Y increasing upward. OpenGL's window coordinates put (0, 0) at the bottom-left.
The best part: PDF's device space, the actual pixels, flips back to the top-left with Y down. One file format quietly carries both conventions, one for the page and one for the screen.
The myth, gently corrected
It is tempting to say early computers used Cartesian coordinates and then everyone switched to top-left. That is not quite what happened. There were two lineages from the start: raster displays, which count from the top-left because that is how they physically scan, and the math and vector world, which counts from the bottom-left. Top-left won for everyday UI and 2D graphics because raster displays won. Bottom-left survived wherever staying aligned with mathematics mattered.
Why you still feel it
This split is why you flip Y so often without thinking about where the habit came from. Load an image, whose rows run top to bottom, into OpenGL, whose window origin is bottom-left, and the picture is upside down until you flip a texture coordinate. OpenGL and DirectX disagree on which way texture Y runs. A game engine keeps screen space and world space pointing opposite ways and translates between them on every frame. The two origins never merged. Your code just negotiates between them, forever.
So the next time Y points the "wrong" way, it is not a bug, and it is not a bad decision from 1975. It is a standing disagreement between a cathode-ray tube and a geometry textbook, and your code is the treaty that keeps the peace.
by Eugene Egoroff · egoroff.me


Top comments (0)