Demilade Sonuga's blogAll posts
A Few Things About Computer Graphics
So far, we've printed "Hello World", and while that's nice, for a game it's not good enough. Printing text is not all we're doing here. We also need to draw graphics. Before we proceed to the UEFI-specific stuff required to do that, let's take a quick detour to understand some things about computer graphics. Everything that the computer works with all boils down to bits and graphics aren't an exception. A picture in a computer is nothing but a blob of bits that some component in the computer "knows how to display" on a monitor. By "knows how to display", I mean it has been wired to manipulate bits in such a way that the sequence of bit manipulations ends up with the light of different colors being let out through thousands and thousands of really tiny squares (pixels) on the monitor, and these thousands of separate outlets of light, put together, is then interpreted by our brains as something that has meaning, something of significance to us.
The specifics of the format of the blobs of bits or the precise bit manipulations that lead to the display of an image vary. One way of arranging the bits is to group them according to the pixels they represent. A single group of bits can be defined to represent the intensities of the red, green and blue color channels of a single pixel. These groups of bits that represent pixels can then be lined up together in arrays of arrays, to create a full representation of some image. Raster graphics are graphics made of bits arranged in this pixel-by-pixel format. Another way of formatting these bits is to define them as descriptions of mathematical geometries like points, line segments, curves, .... Graphics in this format are vector graphics.
The sort of graphics we're primarily interested in here is raster graphics, so we'll just quietly sweep vector graphics in a corner, under the rug.
Okay, now that we know how the blobs of bits are arranged in the computer, the next question is: what exactly are those manipulations that lead to the display of an image?
A component in the computer system connected to the monitor is the means by which the monitor "knows" what to display. In this post, I'll call this component the video display controller ( but I'm not really sure if that's accurate. It seems to me like there's no real consensus on what to name this component). This video display controller itself is just another component that takes descriptions of pixels (raster graphics), converts them to analog signals according to the description and feeds the monitor with these signals. The monitor then uses some principles of physics to work out the rest. To get the controller to display some image, we need to somehow tell it where the pixel descriptions of that image are. This is done with video memory.
Video memory is just a portion of memory that is dedicated to holding the pixel descriptions of what is to be displayed on the monitor. This is also called a frame buffer.
Getting an image on the screen can be done with the Graphics Output Protocol. This protocol provides
some utilities for changing the video mode and getting info about available video modes.
It also gives the location of the frame buffer.
By default, the video mode is set to a text-only mode which is what we used the Text Output Protocol's
output_string to write to.
To draw images on the screen, we need to change the video mode to one that interprets the bits in the frame buffer as pixels. It's after doing this that we can then start drawing images on the screen.
- The bits in a raster graphic define the color intensities of pixels to be displayed on the screen.
- Video memory is a segment of memory that holds the bits that define the colors of the pixels to be displayed on the monitor.
- The Graphics Output Protocol is a bunch of functions provided by UEFI firmware that facilitates drawing to the screen.
We'll be modeling the Graphics Output Protocol in our code.