Short answer
Human-made glass is generally traced to ancient Mesopotamia and Egypt, where craftsmen were making glass beads and small objects by around the third millennium BCE. Natural glass, such as obsidian, formed long before that through volcanic activity, and people used it for tools and ornaments. The glassmaking that later produced stained glass windows grew out of those early Near Eastern traditions.
Natural glass came first
Glass can form without people. When volcanic lava cools quickly, it can become obsidian, a smooth, glassy rock that holds a sharp edge. People used obsidian for tools and ornaments long before they made glass themselves. Lightning can also melt sand into hollow, glassy tubes called fulgurites. These are rare and are not a source of manufactured glass, but they show that glass can form naturally.
Early human-made glass
Making glass from raw materials needs high temperatures and a flux, such as plant ash, which lowers the melting point. The earliest evidence of human-made glass comes from Mesopotamia and Egypt. The oldest objects are mostly small: beads, pendants, and small vessels, often in vivid colors. Later Egyptian craftsmen made core-formed vessels, shaping glass over a core of sand and binder.
Glassblowing and Rome
Glassblowing was developed in the 1st century BC, most likely in the eastern Mediterranean. Blowing made it quicker and cheaper to shape glass, and the technique spread rapidly through the Roman Empire. Roman glassmakers produced colored and clear vessels in large numbers, and that expertise is part of the background to later Western stained glass.
From vessels to windows
Early glass was mostly used for objects, not windows. Some Roman buildings used glass in their windows, but colored glass windows as we think of stained glass came much later, in the medieval period. Glass windows in churches are known from the late 7th century in England. For the first dated windows, see when stained glass was invented.
Why stained glass came later
Making large, flat, colored sheets is harder than making small objects. It needed the blowing and flattening techniques that Roman and medieval glassmakers developed. Lead came, which holds the pieces together, was another step. Together, these methods made stained glass windows possible. For how those methods worked in practice, see medieval stained glass techniques. For glassmaking traditions in the Islamic world, see Islamic stained glass.