Tricks of the Windows Game Programming Gurus:Advanced Windows Programming

All ITKnowledge Source Code Search Tips Advanced Search |

| Tricks of the Windows Game Programming Gurus by Andre LaMothe Sams, Macmillan Computer Publishing ISBN: 0672313618 Pub Date: 09/27/99

Search this book:

Previous | Table of Contents | Next

If `bErase` is `TRUE`, the call to `BeginPaint()` fills in the background brush; otherwise, it doesn’t.

Simply call `InvalidateRect()` before the `BeginPaint()`—`EndPaint()` pair, and then, when you do call `BeginPaint()`, the invalid region will reflect the union of what it was and what you added to it with the `InvalidatRect()`. However, in most cases, you will use `NULL` as the `lpRect` parameter of `InvalidateRect()`, which will invalidate the entire window. Here’s the code:

    PAINTSTRUCT    ps;   // used in WM_PAINT

    HDC        hdc;   // handle to a device context

    case WM_PAINT:

        {

             // invalidate the entire window

            InvalidateRect(hwnd, NULL, FALSE);

        // begin painting

        hdc = BeginPaint(hwnd,&ps);

        // you would do all your painting here

           EndPaint(hwnd,&ps);

           // return success

           return(0);

           } break;

In most of the programs in this book, you’ll use `GetDC()`—`ReleaseDC()` in places other than the `WM_PAINT` message, and `BeginPaint()`—`EndPaint()` solely in the `WM_PAINT` handler. Now let’s move on to some simple graphics so you can at least print out text.

#### Video Display Basics and Color

At this point, I want to take time to discuss some concepts and terminology that relate to graphics and color on the PC. Let’s start with some definitions:

  • Pixel—A single addressable picture element on a raster display, such as a computer monitor.
  • Resolution—The number of pixels that the display card supports, such as 640×480, 800×600, and so forth. The higher the resolution, the better the image, but the more memory required too. Table 3.2 lists some of the most common resolutions and their various memory requirements.
  • Color depth—The number of bits or bytes that represent each pixel on the screen—bits per pixel (bpp). For example, if each pixel is represented by 8 bits (a single byte), the display can only support 256 colors because 28 = 256. On the other hand, if each pixel is made of 16 bits (2 bytes), each pixel can support up to 16,384 colors or 216. Again, the greater the color depth, the greater the detail, but memory usage also goes up. Furthermore, 8-bit modes are usually palettized (which will be explained shortly), 16-bit modes are called high color, and 24- and 32-bit modes are called true color.
  • Interlaced/noninterlaced displays—Computer displays are drawn by a scanning electron gun one line at a time—rasterization. Standard television draws two frames for each image. One frame consists of all the odd-numbered scan lines, and the other frame is all the even-numbered lines. When these two frames are drawn in quick succession, your eyes fuse them together and create a single image. This only looks acceptable for moving images and therefore is not acceptable for static imagery like a Windows display. However, some cards can only support high-resolution modes if they interlace. When interlacing occurs, you will usually see a flicker or shake in the display.
  • Video RAM (VRAM)—The amount of onboard memory on a video card for representing the video image(s) on the screen or in texture memory.
  • Refresh rate—The number of times per second the video image is refreshed, measured in Hz (hertz) or fps (frames per second). 60Hz is considered the minimum acceptable level these days, and some monitors and display cards go up to well over 100Hz for a rock-solid display.
  • 2D acceleration—Hardware support on the video card that helps Windows and/or DirectX with 2D operations like bitmapped graphics, lines, circles, text, scaling, and so forth.
  • 3D acceleration—Hardware support on the video card that helps Windows or DirectX/Direct3D with 3D graphics rendering.

These elements are shown in Figure. 3.14.

Figure 3.14 The mechanics of a video display.

Of course, Table 3.2 is only a sampling of possible video modes and color depths. Your card may support many more. The important thing is to understand that it’s pretty easy to eat up 2MB to 4MB of video RAM. The good news is that most DirectX Windows games that you’ll write will run in 320×240 or 640×480, which, depending on the color depth, a 2MB card can support.

Table 3.2 Video Resolutions and Memory Requirements

Resolution | Bits per Pixel | Memory (min-max)
--- | --- | ---

320×200* | 8 | 64KB
320×240* | 8 | 64KB
640×480 | 8, 16, 24, 32 | 307KB–1.22MB
800×600 | 8, 16, 24, 32 | 480KB–1.92MB
1024×768 | 8, 16, 24, 32 | 786KB–3.14MB
1280×1024 | 8, 16, 24, 32 | 1.31MB–5.24MB
1600×1200 | 8, 16, 24, 32 | 1.92KB–7.68MB

> *These are considered to be Mode X modes and may not be supported by your video card.

Previous | Table of Contents | Next

Copyright © Macmillan Computer Publishing, Inc.

Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.