Deepen RPG game production - graphics

xiaoxiao2021-03-06  64

Author: Zhu strong

I don't know if you have noticed this: I like the computer to like the game. why? Because, no matter whether they are young and old, the game has a special charm, the charm of casual, the charm of the aftertaste, or the charm of competition. But sometimes I think so, for example, because of memory or hardware, the game can't play, please come to my friends to help adjust, solve the problem, and continue to play, then you haven't learned anything. If it is deeply in-depth, the planing roots will understand from the head to the end, I believe that you will become a computer master. What a master is also usually tempered. Everyone is trying to edit the game, maybe one day you will find that although the programming level is limited, it is unknowing 3DS or Corel Draw and other software, and can look at the previously ambiguous operating system concept with another highly viewed operating system concept. This is a unimmented.

So what can we make? QUAKE is still "AH-64D long bow Apache"? These are probably many professional programmers are also difficult to understand the key details. We may wish to be slightly lower, first from the speed, the tip of the RPG, SLG begins, if you have endurance, willingness, plus a little talent and inspiration, I believe that we can have a Tom Hall in the middle, The more cool engine program than the Quake.

(1) opening

Today, in high configuration and software, I think that the "brave fighting Dragon" is probably it is hard to make players fans, from 4 color to 16M true color, from 320 × 200 turn to 1024 × 768 development is a general trend , How do we have to position? The 16 colors introduced before, just give you a simple practice, to achieve the "Yanlong Knight II", "Xianjian Qi Chuan Chuan", 256 colors are more appropriate, there are many friends will ask: So True color? True color is good, but we may wish to make a comparison, turn a 16M true color picture to 256 colors via an image conversion tool, and the image distortion is not serious than the gloss is slightly reduced. Only dynamic animations, such as the "Galaxy Flying IV" over animation only true color (actually 64k color) will show truly power. However, please feel a little in mind, the true attraction of a game is still in connotation and creativity, empty, a housing is useless, like the battle picture is not less inferior to the "Magic Magic Ji" of "Xianjian Qi Chuan" It is an example of failure. Light is the same as the beauty level, the same 256 colors, and the standards of production are also considerable, and some are not as good as 16 colors. And in 16 colors, it is no longer less than 256 colors, and like glorious "Three Kingdoms Ying Jie Chuan" can't see which "Three Kingdoms II" is poor than the "Three Kingdoms II". It seems to be strong. The game will definitely develop to the true color in the future. Everyone has a true programming environment, and the art still needs to be careful.

(2) Color

Color is a surface feature of the object. For most people, we can't deal directly with the light, we see color effect. When we sit in front of the screen, use a tool to generate, control various colors, you must understand that the color seen by the eye is actually reflected by the pigment. This may be less accustomed at the beginning, but when learning the artistic skills including the light effect, it is necessary to first understand the color of the pigment.

The painter has achieved new colors by mixing the pigment. This mix can produce a variety of color change effects, which is called primary color, they are red, green, blue, such as we need magenta, then mix red and blue, need white, It is necessary to mix the isometric red, green, blue. Now let's take a look at another color scheme: Magenta, a magenta (CYAN), yellow (YELLOW), twin, yellow (Yellow), three-color CYM mode. An important difference in CYM mode is that the three-colored mix is ​​gave together to get black instead of brown, and the LCD liquid crystal display usually usually contact is a CYM solution. Color (hue) is usually said. Many people may be surprised, black and gray are also colorful colors, which usually say color is colorful, while gray is a color and black mixture, which understands that they are important to understand computer image creation. Different colors will have different effects visually, and some are easy to relax, some make people feel uneasy, and there are some suggestions that are dangerous or safe. All of these will take into account when compilating. The quality of a work, maybe a harmony is more important than gorgeous, you don't have to draw the game screen with an artist's point of view, but before the game, you can first listen to others' opinions is a good idea, if these colors Make them bored, then I want to be a good thing before your work is officially launched.

In the PC, the brightness of R, G, and B is divided into 2 ^ 6 (64) is divided into 2 ^ 6 (64), which is divided into 2 ^ 6 (64) is divided into 2 ^ 6 (64), and the white is (63, 63, " 63) This method can also display 2 ^ 6 × 2 ^ 6 × 2 ^ 6 (256k) colors. For SVGA, since each color is represented by 8 bits, 2 ^ 8 × 2 ^ 8 × 2 ^ 8 (16m) color can be displayed.

The color output of the VGA / SVGA card is RAM DAC (Digtalto Analog Convertor). After the VGA card inputs 8-bit input digital signals, after the conversion of a color control table and DAC, output from the analog signal line to the screen. Although each field in color control can have 256K color changes, only 256 of the input signals, so you can only display 256 colors at the same time on the screen, that is, 256 species from 256k colors. . The DAC chip in the SVGA card must use 16 bits (32k, 64K) or 24-bit (16m) input interfaces. For these chips, the input signal is a real color value, so simply press in RGB format. Since the number of data transfer interface bits is increased, there is a lot of speed, and of course, the integration of the SVGA card and some acceleration settings cannot be active. In drawing mode, this type of card provides hardware cursor capabilities to alleviate the CPU burden.

(3) Display mode

In VGA's drawing mode, the most important thing is patterns 12 and mode 13 (I think most players have no CGA, EGA shows cards). The mode 12h uses a planar corresponding method, supporting 640 × 480, the video memory is a0000h, and the three modes of other D, E, 10h are as 16 colors, but the resolution is different. On the video memory address, each byte represents 8 pixels, each bit can correspond to 4 digits in the same position in the color plane. When we want to paint a point on the screen, the data must be stored on the corresponding bit in the four color planes, respectively. VGA provides a number of ways to access color plane data, such as accessing 4 color plane data at a time or only for single plane operation, which method is faster? If it is an image processing, select the second ideal; for the drawing point mode, the first faster. The mode 13h is the only mode in the VGA card, which supports the resolution of 320 × 200. The video memory start address A0000H, which uses linear corresponding methods (all 256 colors of SVGA and true color are used method). Linear corresponds to each point and video memory address on the screen in order, one point corresponds to one byte, the advantage of this is: this correspondence method is much simpler than the color plane, because we only need to be directly Video memory addresses are accessible without having to pay attention to the correspondence of color planes and memory addresses. It is not difficult to see that, in fact, linear correspondence is to connect four color planes together, and become a linear arrangement.

13h initialization code, "Volkswagen" this year's first phase of Huang Ming friends have given it, if everyone is Turboc, you can write this:

[No.1]

Setup-graph () / * VGA 13H mode initialization * /

{

Union regs r;

R.h.ah = 0;

R.H.al = 0 × 13;

INT86 (0x10, & r, & r);

}

Close-graph () / * Close VGA 13H graphics system * /

{

Union regs r;

R.h.ah = 0x00;

R.h.al = 0x03;

INT86 (0x10, & r, & r);

}

SVGA is generally at least 512K memory due to data to access higher resolution or more colors, but the address of the video memory it is still 64K. In the case where the memory address is not enough, the SVGA's area switching function divides the entire memory into many memory pages, and then uses the handover function to correspond to the different memory pages to the A0000h or other video memory address. However, the SVGA card of each manufacturer is not the same. The method of switching the memory page is not the same, and there are two switching switches on some display cards, which we need to pay attention.

Let's take a look at the SVGA graphical initialization routine:

[No.2]

#Include

INT huge return-svga256 (void)

{

Return (0); / * Returns the corresponding number of various resolutions 0 ~ 6

0) STANDARD VGA / MCGA 320 × 200 × 256

1) 256K SVGA / VESA 640 × 400 × 256

2) 512K SVGA / VESA 640 × 480 × 256

3) 512K SVGA / VESA 800 × 600 × 256

4) 1024K SVGA / VESA 1024 × 768 × 256

5) 256K SVGA 640 × 350 × 256

6) 1280K above VESA 1280 × 1024 × 256 * /

}

Void setup-svga256 (void) / * SVGA 256 color mode initialization * / {

INT GM, Driver = detect;

InstallUserDriver ("SVGA256", Return-Svga256);

INITGRAPH (& DRIVER, & GM?);

}

void main ()

{

Setup-svga256 ();

SetColor (2);

Circle (100, 100, 50);

Getch ();

Closegraph ();

}

As long as you use the SVGA graphics interface program SVGA256.BGI to copy to C's system program directory, why? Because this driver is of course not a product of Borland. One benefit of doing this is that there is no friend who has not had a graphic library function programming experience directly with the Turbo C graphics library (graphics.lib) embeds the various drawing functions defined in the file graphics.h.

This SVGA graphics driver is good, and most of the SVGA cards, like ATI, TRIDENT, TSENG, etc., the author has encountered some problems on some cards due to the limitations of SVGA card compatibility specifications, such as 9440 cards do not support No. 5 mode, 5428 card does not support the No. 1, No. 5 model, but no matter which type of card, you support models from 0 and 2.

(4) Function and optimization

If you carefully watch the system catalog under Turbo C, you can find a lot of * .bgi files. The Turbo C graphics system can be divided into a graphics.lib and a font library (* .CHR) that exists on the disk in the file form, the graphics device driver (* .bgi). BGI is the abbreviation of Borland Graphics Interface, a set of universal graphics interfaces compiled by Borland, such as Egavga.bgi drivers for EGA / VGA cards. This is a way to make programmers can be independent of various types of display systems on graphics processing, but it does not support SVGA cards for compensation for compatibility. Color or true color shows, although many of the early games (even some shooting games) are indeed written on these drivers, but for current speeds, especially three-dimensional games are undoubtedly unrealistic. One of the best ways is to write an efficient graphic original code yourself, start from the drawing point, and to expand the entire graphics library required. Some friends may say: "How much time is like a few menu frames in RPG?" But if the reel is translated? 640 × 480 × 256 What kind of level concept! Even if you are slow, why can't you make it faster?

The drawing point is a very important step, almost all graphics functions are based on it. Below I provide you with an efficient drawpoint code suitable for various resolutions:

[No.3]

#Include

Void Point (int X, int y, char color)

{

UNSIGNED PUT;

PUT = Y * 320 X; / * Resolution is 320 * 200, if other resolutions, please convert the corresponding coefficient * /

* ((CHAR FAR *) (0 × A0000000L) PUT) = Color;

}

At the same time as you create your own function library, you must pay attention to programming skills on the speed: 1. Avoid multiplication and division, this is a comparable amount of calculation of the CPU time, and the remaining number should also be avoided as much as possible. 2. Use an integer, less floating point, double precision is slower. 3. Reduce the operation of reading the disk file, a number of reads more than a small amount of data is much faster than a small amount of data. 4. Use the Register to define variables, and the speed of the register is even faster than the memory. 5. This will be frequently crossed, try to move the time of operation to the loop. In addition, the drawing function is some of the algorithms that need to be considered, and the Bresenham algorithm of the slash, the filling optimization algorithm, etc., please read the relevant mathematical algorithm program. anything else? Of course, it is a compilation. Compilation is a difficult language. Friends with assembler experience can try some methods of embedded exchange coding, and it is necessary to note that different call rules are specified for different C-compilers in assembly language. In Turbo C, a function of modifier cdecl or that does not explain the parameters into the stack in the order from the right left, that is, the modification function (A, B, C), a first in the stack, then Yes B and C. After entering the assembly encoding process, the register BP content must be in the stack. The current stack pointer SP value is stored in the BP. If the subroutine uses Si and Di, the only registered register is SI and DI, before returning from the assembly language subroutine, BP, SI, and DI must be restored, and the stack pointer is reset.

In the last way, friends who have missing function programming can download some high-efficiency graphics libraries that support VGA / SVGA via Internet, which can be used, and reads readmes can find a detailed function definition description. "I must use Borland's driver painting!" I don't object, maybe I have already come out (jokes) next year.

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

New Post(0)