DirectX5.0 Latest Game Programming Guide DirectDraw Article One, DirectDraw Basic Image Concept

zhaozj2021-02-11  204

DirectX5.0 Latest Game Programming Guide DirectDraw

DirectDraw is one of the main parts of the DirectX SDK, which allows you to display memory operations directly, support hardware bit blocks, hardware override, surface flip, and maintain compatible with current Windows-based applications and drivers. DirectDraw is a software interface that keeps also compatible with Windows Graphics Device Interface in addition to the display device access. For graphics, it is not an advanced application interface. DirectDRAW provides a method-independent approilt that allows Windows-based applications and games (such as 3D graphics packages, and digital video games) to directly acquire the characteristics of the display device. DirectDraw can work in a wide variety of display devices, from simple SVGA displays to advanced display devices that provide shear, stretching, and non-RGB formats. The DirectDraw interface allows your application to simulate the performance of basic hardware and use hardware acceleration features; hardware does not provide feature will be simulated by DirectX. DirectDraw provides access to devices that display memory that makes you easily manage display memory. Your application only needs to identify some basic device properties, which are all standard hardware applications, such as the colors of RGB and YUV format. You don't need to call special procedures to use bit blocks to transfer or manipulate palette registers. Using DirectDraw, you can easily display memory and make full use of bit blocks of different types of display devices, without having to rely on specific hardware. DirectDRAW can run in Windows95 / NT4.0 and later. DirectDraw's hardware abstraction layer HAL (Hardware Abstract Layer) provides a unified interface, and the program can work directly in memory or video memory to obtain the best performance of the hardware. DirectDraw estimates the performance of video hardware, as long as you may use the specific performance provided by the hardware. For example, if the video card support bit block transmission, DirectDraw will delegate the bit block to the video card, the CPU does not participate in the processing of bit block transmission, which greatly enhances the performance of the program. In addition, DirectDRAW provides hardware simulation layer HEL (Hardware Emulation Layer), making it possible to use software simulations when certain hardware does not exist. This should be provided by these hardware. DirectDraw runs on Windows 95, which can utilize 32-bit memory superiority and "flat" memory models provided by the operating system. DirectDraw uses system memory and video memory as bulk storage instead of a small segment. In addition, DirectDraw also brought many powerful features for Windows graphics: .directDraw enables easy transformation of multiple background buffers in full screen mode. Support window mode and cutting function in full screen mode. Supports three-dimensional Z buffer. Hardware auxiliary coverage in the Z direction. Provides access to hardware for image stretching. Access standard and enhanced display device memory area. Dynamic palette, exclusive hardware access, resolution Rate switching, etc., combine these features, you can easily prepare performances that exceed GDI-based standard Windows games or even MS-DOS.

First, the basic image concept of DirectDraw provides a set of graphical terms that are different from GDI, so it is necessary to use DirectDraw, first you should understand the concepts. The following is an introduction to the important concepts in DirectDraw. 1.1 Device-independent bitmap DIB (Device-Independent Bitmap) DirectX uses device-independent bitmap DIB as the primary graphical file format. A DIB file mainly protects the following information: the dimension of the image, the number of colors used, describes the value of the color and the data describing each pixel. The DIB file also protects less use parameters, like information about file compression, and physical dimension of the image. The extension of the DIB file is generally ".bmp", sometimes it may be ".dib". Because DIB is extremely widely used in Windows programming, DirectX SDK already contains many related functions.

For example, there is a function in the DDUTIL.CPP file provided by DirectX SDK, which combines the Win32 and DirectX functions. The concept is to load a DIB file into the DirectX surface, the code is as follows: Extern "c" idirectdrawsurface * DDLoadBitmap (iDirectDraw * PDD) , LPCSTR szBitmap, int dx, int dy) {HBITMAP hbm; BITMAP bm; DDSURFACEDESC ddsd; IDirectDrawSurface * pdds;. // This is the Win32 part // Try to load the bitmap as a resource, if that fails, try it as . a file hbm = (HBITMAP) LoadImage (GetModuleHandle (NULL), szBitmap, IMAGE_BITMAP, dx, dy, LR_CREATEDIBSECTION); if (hbm == NULL) hbm = (HBITMAP) LoadImage (NULL, szBitmap, IMAGE_BITMAP, dx, dy, Lr_loadfromfile | lr_createdibsection; if (hbm == null) Return Null; // Get the size of the bitmap. GetObject (HBM, SIZEOF (BM), & BM); // Now, Return to Directx Function Calls. // Create A DirectDrawSurface for this Bitmap. ZeromeMory (& DDSD, SIZEOF (DDSD); DDSD.DWSIZE = SizeOf (DDSD); DDSD.DWFLAGS = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH; DDSD.D dsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth = bm.bmWidth; ddsd.dwHeight = bm.bmHeight; if (! pdd-> CreateSurface (& ddsd, & pdds, NULL) = DD_OK) return NULL; DDCopyBitmap (pdds, hbm, 0, 0, 0, 0); DeleteObject (HBM); Return PDDS;

1.2, drawing surface (Drawing Surface) Draw the surface accepts video data and displays it as an image. In most Windows applications, you can use the Win32 function such as getDC to access the drawing surface. GETDC Getting the Device Context DC (Device Context), after obtaining the device, you can redraw the surface. However, the image function of Win32 is provided by GDI. GDI is part of the system that provides an abstract layer that allows the standard Windows program to draw surfaces. The disadvantage of GDI is that it is not designed for high-performance multimedia software, which is mainly used for commercial software such as word processing and spreadsheet software. GDI provides access to video buffers in system memory, but does not provide access to video memory. Although GDI is very suitable for most commercial software, it is too slow to multimedia applications and game software. On the other hand, DirectDraw provides a drawing surface that characterizes real video memory, which means that when you use DirectDraw, you can write data directly to the video, so that the image's display speed is enough. These surfaces are characterized as a continuous memory block that makes it easier to address addresses. 1.3, bit block Transfer Blit Blit is the story of "Bit Block Transfer", indicating bit block transmission. It is a way to transmit a data of one address in memory to another address. Block transmission is often used in the elf animation. You can use the iDirectdrawsurface3 :: BLT method and the iDirectdrawsurface3 :: Bltfast method to perform bit block transmission. 1.4, page flipping and back buffering page flip is the key to multimedia, animation, game software. The software page flip is an simulation of cartoon painters to motion image motion. For example, the painter draws a character on a piece of paper, then placed it in the next frame, for each frame, only rarely changing the character image. When you quickly flip the sheet of paper, the continuous character image seems to have an animation. The page flips in the software is similar to the above process. First, you have established a series of DirectDraw surfaces, which are ready to "flip" to the screen. The first surface is considered as a primary surface, which is called a background buffer after all surfaces behind the main surface. The application writes the data to the background buffer, then flips the main surface, so the background buffer is displayed on the side. When the system is displaying an image, the program can write data to the background buffer, which has continued until the end of the animation, which makes you quickly and efficiently turn the discrete image into an animation. DirectDraw can utilize relatively simple double buffers (one main surface and a background buffer), can also use more complex technologies to add other background buffers. Make you can easily create a program that flipped.

1.5, rectangle, one of the most important concepts programming through DirectDraw and Windows is the object on the surface - a bounded rectangle. A bounded rectangle is determined by two points, namely the upper left corner and the lower right corner. When writing data in a block transmission, most applications use the RECT structure to transmit information about the boundary rectangle. The definition of the RECT structure is as follows: typedef struct tagRect {long left; // this is the top-left corner's x-coordinate. Long top; // the top-left corner's y-coordinate. Long Right; // the bottom-Right Corner's X-coordinate. Long bottom; // the bottom-right corner's y-coordinate.} Rect, * prect, Near * npRect, Far * LPRECT; where Left and TOP member variables are values ​​of X, Y coordinate in the upper left corner of the rectangle, Right and Bottom are coordinate values ​​of X, Y in the lower right corner.

转载请注明原文地址:https://www.9cbs.com/read-4923.html

New Post(0)