If this page looks like garbage then you need one of these browsers...Please sign my programmer's page guestbook. |
Understanding GraphicsIn order to write good games, or to write any program that takes advantage of the graphics system of a computer, we need at the very least a basic understanding of graphics. Most C compilers come with graphics functions that you can incorporate into your C programs without having to learn a lot of low level details of the graphics sub-system itself. However, these graphics functions are sometimes limited as to how they take advantage of your graphics card and they are usually specific between company's products. Another bit of frustration that I have had in the past was that the graphics functions that come with Borland's Turbo C++ compiler are somewhat confusing and hard to use. Since we want everybody to be able to follow along, we will kind of reinvent the wheel by using more common functions that everyone can use. If you are using a strictly ANSI C compiler, you may have some trouble following along in these examples. These examples require the use of some DOS specific instructions that Turbo C++ supports. If you are a Microsoft user, you should easily be able to port the code to your product with little to no modification.
|
Do not confuse the number of 'onscreen' colors with the 'total' number of colors. For example VGA's mode 13h can display a maximum of 256K (262,144) different colors, but only 256 of them can be shown 'onscreen' at once. |
The Graphics ScreenYou can pretty much use any graphics screen that your system is capable of, but for many beginner's (such as myself). I would highly recommend that we start off using a linear mapped screen. Those of you who have read the Basic programming pages know that I am referring to the screen mode 13h. This screen mode is the simplest to program and understand, which is important since a lot of your programming efforts can be spent on the actual program logic and not on how to program the graphics card itself. Mode 13h, is a VGA 320x200 resolution with 256 on screen colors. Before we delve into using this particular graphics mode, let's look at some of the alternatives. Let's look at CGA (Color Graphics Adapter) perhaps the oldest graphics card in existance for the PC. What can I say about it, you have your choice of between 2 or 4 onscreen colors. For most games, this is not enough to do diddly squat with. The graphics resolutions range from medium (320x200) to high (640x200) and depending on the number of onscreen colors the pixels will either occupy 1 or 2 binary bits to store. |
Did you notice that the CGA memory map begins at B800:0000 and that the VGA memory map begins at A000:0000. Strange? Did you also know that the text screen is mapped at memory locations starting at B800:0000? Interesting... |
The EGA was next to come on the scene sporting up to sixteen colors onscreen. At sixteen colors, each pixel consumed 4 bits but they were not laid out in memory like CGA. While 16 colors were a lot better than 2 or 4, game programmer's still found it hard to generate stunning graphics so another mode came out on the horizon. Finally, the VGA came into existence and was a God send to many game programmer's, even to this day. Standard VGA graphics could display as many as 256 onscreen colors and had resolutions as high as 640x480. Of course, that kind of pales by today's high resolution 1024x800 at 16 million or more on screen colors. But for most games, it was more than enough to create realistic looking games. In order to maintain backwards compatibility with EGA, the VGA modes are mapped in a planar, rather than a linear fashion. This planar mode allows both the EGA and the VGA cards to be altered using memory locations A000:0000 to A000:FFFF. That's 64K of memory, however, it is possible to have EGA cards with more than 64K of video RAM and the VGA cards sport 256K or more. (The mainstream as of this writing is 1 to 4MB standard.) How can we address all this VRAM? The answer lies in its use of planes. This video RAM (VRAM) is accessed in chunks (planes) of up to 64K. Selecting a desired plane is accomplished using a plane select mask illustrated below.
Send your questions, comments, or ideas here. This page hosted by
Get your own Free Home Page |