Writing Windows Games with Fastgraph for Windows In general, Windows graphics programming in the past has involved using the Windows Graphics Device Interface (GDI) functions from the Windows API. The GDI functions support other output devices besides the video display, but the price of this generality is speed. This translates to the sluggish performance often associated with Windows graphics applications. This problem was partially addressed by two alternative blitting mechanisms, WinG and DirectDraw. By streamlining the screen blit, WinG and DirectDraw are able to achieve frame rates faster than that available through GDI. This improved performance allows the potential for reasonably fast Windows games. However, WinG and DirectDraw do nothing to simplify the process of creating animations. In fact, they are both quite complicated to use. The problem, you see, is not how to blit a buffer to the screen, but how to build the buffer in the first place. How, for example, do you write a background to a WinG buffer and then superimpose a sprite on the buffer? This is where Fastgraph for Windows fits in. Fastgraph gives you a set of fast, intuitive low-level functions to write to the buffer. It is intuitive because it closely resembles direct screen writes. Fastgraph for Windows provides the "moves" and "draws", the bitmap manipulations, the palette management, the double buffering, and other capabilities game programmers are accustomed to using. In fact, Fastgraph is so intuitive, it almost makes Windows programming resemble programming in DOS. With a small mental leap, a virtual buffer closely resembles off-screen video memory, and may be manipulated exactly the same way. Using Fastgraph for Windows --------------------------- Developing a Fastgraph for Windows application typically involves these steps: 1) Create the Windows "framework" code common to all Windows programs -- namely, the WinMain() and WindowProc() functions. WinMain() typically registers the window class, creates the window, initially displays it, and includes the message loop code. WindowProc() processes the Windows messages such as WM_CREATE, WM_PAINT, and WM_DESTROY. You can also use an application framework such as OWL or MFC, or visual tools such as Delphi or Visual Basic, to handle these tasks. 2) Perform the necessary palette management tasks. This is normally done in the WM_CREATE section of WindowProc(). Fastgraph greatly simplifies palette management by allowing direct palette manipulation and on-the-fly color reduction. 3) Set up the virtual buffer(s). This is normally done in the WM_CREATE section of WindowProc(). Virtual buffers are very easy to initialize. The fg_vbinit() function must be called first, before any virtual buffers are created. Then you can create up to 32 virtual buffers by calling the fg_vballoc() function like this: handle = fg_vballoc(width,height); This will both allocate memory for the virtual buffer and determine the size and shape. A virtual buffer becomes active when the fg_vbopen() function is called, as shown here: fg_vbopen(handle); You can only write to the active virtual buffer, and only one virtual buffer may be open at a time. 4) Write to one or more virtual buffers. Use the Fastgraph for Windows functions for writing to a virtual buffer, just as you would when writing to video memory or a virtual buffer in Fastgraph DOS programs. 5) Painting the screen from the active virtual buffer. Use fg_vbpaste() or fg_vbscale() to display the virtual buffer in the client window. This might be done in the message loop for applications that perform animation, in the WM_PAINT section of WindowProc(), or both. Double Buffered Animation in Windows ------------------------------------ Double buffering is a favorite trick of game programmers. Fastgraph for Windows allows gamers to accomplish double buffering in a highly intuitive manner. It works like this. First, a graphics file, such as a PCX or BMP file, is loaded into a virtual buffer. This buffer is then designated the "storage" buffer. Another buffer, called the "work" buffer, is rebuilt and blitted each frame. To rebuild the work buffer, you simply copy some or all of the storage buffer using the fg_vbcopy() function. Then you apply sprites as needed, usually in the form of bitmaps using the fg_drwimage() function. You may also add other items to the work buffer, such as text, and you may do transparent or non-transparent copies from other virtual buffers. When the work buffer is fully built, it is drawn or "painted" to the screen using the fg_vbpaste() or fg_vbscale() functions. Then the process is repeated for the next frame. Doing this in a continuous loop creates smooth animation. The flexibility of the process allows almost anything to be animated, and it is possible to create stunningly playable games. Other Fastgraph Features ------------------------ Separate DOS and Windows versions of Fastgraph are available, with most functions working identically under both platforms. This allows DOS programs to be quickly ported to Windows, and vice versa. It should also be mentioned that Fastgraph is very flexible. The DOS version of Fastgraph supports real mode, 16-bit protected mode, and 32-bit protected mode. Fastgraph for Windows supports Windows 3.1, Windows 95, Windows 98, Windows NT, DirectDraw, WinG, and Windows GDI blitting. While WinG and DirectDraw are recommended for fast program execution, they are not required. As a game developer, you have the option of providing the WinG or DirectDraw files on your distribution disk for the user to install. If you want your game to use WinG or DirectDraw, you should have the user install them as part of the game installation process. If you don't want to bother with installing WinG or DirectDraw, Fastgraph will autodetect the optimal blitting mechanism and use whatever it finds on the system. Fastgraph for Windows supports a number of compilers, including most C/C++ compilers, Borland's Object Pascal, Delphi, Visual Basic, and Microsoft Fortran PowerStation. It is written in highly optimized assembly language for maximum speed. The price is a modest $299, making it affordable for even casual game programmers. Source code is available at an additional cost. This toolkit will potentially shave weeks or months off a game development project, and is well worth looking into. Contact Information for Fastgraph: ---------------------------------- Ted Gruber Software, Inc. PO Box 13408 Las Vegas, NV 89112 (800) 410-0192 orders only (602) 483-0192 orders outside the US (702) 735-1980 voice (702) 735-4603 fax email: fastgraph@aol.com web: http://www.fastgraph.com ftp: ftp.fastgraph.com/fg/windows