An understanding of the Windows platform
Windows in the eyes of programmers
The venue in the eyes of the programmer is a big difference in the eyes of ordinary users - not fast and convenient, but quite troubles and irritated. Especially those who have a process of DOS feel that Windows is very awkward, and there are many concepts that make people feel weird. When Windows just came out, almost all the amateur programmakers were eliminated because the programming became quite complicated, which is more complex than DOS.
When the program is complex or more, the good mind can't be affected. I saw a foreign author to write this: "Usually the programmer is written out when writing the Windows program, instead of re-coding, because of that Too much trouble, no one can't remember so much thing. "Indeed, if you use VC and call Win32API to write a standard Windows program, you will feel that you like VB. Because VB does not write the form1 form generated by the code, you can write the code on the VC.
However, my impression of Windows is the API provided by a bunch of dynamic link libraries. Thousands of API, I want to remember, there is no door! But you have to write a game, you can only use it, who makes Microsoft's windows everywhere.
Some concepts of windows programs
It should be said to be the event drive mechanism. Previously written in DOS, it is a programmer to write code to accept the user's button or mouse information, and then analyze how the user is pressed to determine how to run your own program. Now this thing Windows has been done for us, what we have to do is to let your app to inform your app, tell your user to press what button, or something else. Processing is to solve the trouble brought about by multitasking. Imagine if Windows runs more than 100 programs, these programs are desperately judge what the user is doing, which will definitely become a group, but also white waste of the CPU to compose the same problem, so these things are unified by Windows, it Responsible for unified judgment to the user in what button. For example, Windows is running 3 programs at the same time. The user clicks the first program. At this time, Windows will convert this event into a message to tell the first program. The first program will know that the user is using it, and the other two The program will not know this event, so there will be no response. This is the event drive mechanism, and the program is just waiting for the user's operating event and then makes corresponding processing.
Second, what is the message, although the user's operating event is converted to a message by Windows, but does not mean that the message is only some operating events. There are still many kinds of messages, you can do a lot, it is responsible for passing the information to the program. For example, Windows To turn off the system, it will send a message that it wants to close, so that everyone will be automatically turned off. Everyone knows that when you shut down the system, you will show you the dialog box for you to save the document. In fact, this is a message that Windows will be sent to Word. Not Word checks when Windows is going to close.
There is also a concept called callback function, English is called callback, meaning other programs to call your function, not you call other functions. But people programmed under DOS may have never heard of this concept, because the DOS system does not call the function you write. Someone may see the window handling function on some Windows, enumeration functions, in fact, they are all callback functions. The callback function is very wide. For example, when Windows sent a message, you call the callback function to send this message. It is actually calling the function you write, and then pass the message through the function parameters to the function. Therefore, the function of the window message is also called the window processing function. This is just an application of the callback function. The enumeration function mentioned above is to use the callback function to make an enumeration work. In DirectX (enumerated) display mode is made with a callback function. DirectX issues all supported display modes in the system to the callback function, not you call DirectX to check all the display modes supported by the system. How is the Windows program built?
Since most of the programs need to be used as a window, the application is generally closely related to the window. How to write an application with only a window without any feature is to learn to write a Windows program, it is a standard Windows program, you will know how Windows works.
First, a window should be created via the service function in Win32API, then write a window handler for system call, and finally write a message loop to time to take the message. In these steps, which one is not yet. If there is no window, then the message loop and window handling function is not used; if the window handling function is not written, the window is found at all; if there is no write message, then WINDOWS is sent Your message will not be reached, the window on the screen will like death, how to do it, and there is no response if the window handling function is not processed.
As shown below:
This is a probably structure, the application is taking the message at this time, and then send the message to the window processing function after being taken. Specifically, Windows is actually not sent directly to the application's callback function, but puts the message into the message queue of this application, and then waiting for the message loop to take. This message queue is built as the window, which can store some messages or prevent the loss of messages. When the message is taken back, the function of taking the message will call the window processing function to process it.
Windows multitasking
A significant feature of the Windows platform is multitasking, that is, it can run multiple programs at the same time. This feature gives us great convenience, we can listen to music while writing articles, but also outputs an article on the printer.
Multiking can make each program mistakenly think that itself has a machine, because Windows is not like the previous DOS, when executing a program to this program, but the CPU is turned to it. The program, so that each program can be executed. In fact, Windows only assigns little time to use the CPU for each program, so these programs look like they are running at the same time. This is the principle of multitasking, but when Windows is processed too much, it will become very slow.
Early Windows uses a "non-seizure multitasking", this multitasking is the implementation principle is Windows system clock periodically interrupts a task and executes the next one, that is, it gives each program. Time is the same. Now, Windows uses "preemptive multitasking", this multitasking and early difference, Windows will run the program it run according to priority, the higher the priority of a program, and Windows assigns it to it. The longer the time. Usually Windows will set the program that the user is using high priority, so the user thinks that the program he run is fast, that is, there is no much impact on the running program. The more "non-seized multitasking" is more slow because it assigns many times to the programs that the user is useless. Graphics hardware understanding
Structure of video subsystem
The quality of the video system directly affects the performance of the computer. Many people even think that the picture he saw is all the computers, and more people think that the computer is the monitor. Although this is very absurd, it also reflects the status of visual images in people's minds.
Usually the video subsystem can be replaced because most of them are what we said, and there is also an integrated to the motherboard. It mainly includes displaying the coprocessor and display memory (memory), the display coprocessor and the CPU are connected to the extension bus. The display coprocessor on the video subsystem also has its own bus, which allows you to quickly access the above memory, just like the CPU access system memory. It is also an independent system, so they call them a video subsystem. Due to hardware design, the CPU can access the memory on the video subsystem through the bus, but the display coprocessor has access to system memory on the motherboard. However, the bus speed is far from being able to meet the needs. When the CPU and the display coprocessor are swallowed, the bus has become unusually crowded. In order to solve this problem, the AGP structure has been generated. This structure has a direct and system memory connection of the display system, which means that it has bypass the system bus, so that both the bus's pressure has resolved the CPU and display coordination. The data of the data of the device, and the speed of transmitting data with AGP is much more faster than the bus.
Display image principle
The first thing to say is that the display is similar to the principle of TV in the home, but it is only a bit different from the indicators and structures. It mainly has several major parts such as the image tube, electron gun, deflection coil and control circuit, which performs image scans based on the image passed by the computer. In order to display color images, the electron gun is made 3, which is a red gun, green gun, blue gun, and the electrons whose electrons are emitted, respectively, respectively, respectively, as the electronic impact on the screen When we can see this light. When the image is displayed, the electron gun quickly scans the electron to display the corresponding image, and the deflection coil begins to play its role. When it comes to the coil, everyone will always think of electromagnetic, yneas, the electron is offset to the respective positions of the screen under the magnetic field of the deflection coil. If the display of the display is broken, we will see a very bright point in the middle of the screen, what is it? It is a piece of electronic gun to be called by the electron gun. Because the electronic gun is no longer, the electron gun is shot into the center of the screen, it will become this.
There are 256th-order voltages on three electrons, so the 3 gun combination can show 16777216 colors, which is true color.
Image data representation
The data representation of the image refers to how to use data to expand the image. Detailed you know that this detail can be modified to the image to produce a variety of image effects. For example, what is gradienty, you can write it yourself.
The simplest is true colorful image, it is represented by 24 binary, where RGB (red-green blue) accounted for 8, which is one byte, which is very unknown in the programming language. Good treatment, you can modify it with a dedicated byte variable. The 16-bit RGB is troublesome. It is usually 565 or 555 format, 565 is used to use 5 binary binary to indicate red, 6-bit binary represent green, 5-bit binary represent blue. 555 (also known as 5551 format) and 565 mean the same, but it expressed green with 5. In this case, you have to perform a binary operation to extract the RGB inside, because the RGB is not a complete byte, so it is destined to have trouble. However, in software development, 16-bit color is usually used. For computers, it is more than 24 bits and 32-bit images, the same size image, 16-bit color occupied space is less than 24 and 32 bits. Although the 16-bit image rendering is more troublesome, but most developers have selected it. 32-bit color is a blind spot for the majority of users, many people superstitious it is much more color than 24 color, so their usual practice is to set their own Windows to 32 colors, in fact, this is nothing to use. The 32-bit color is only 8 digits more than 24 color, the first 24 bits and 24-bit color are the same, and the remaining 8 digits are not used to display, but used as a flag or other use. Usually 3D operations can be used in 32 colors, while 2D charts or playing 2D games, it is not used because it is too slow.
Palette
An image of the palette format is not the same because it is different from the principles above. The display of the palette image is 8-bit RGB. Different from the above is that it uses 8 bits to indicate the color index of the palette and is not true color. Because the true colors are in the palette, the palette images do not appear in 16-bit colors to extract RGB colors, but it often makes the developer confused because the use of palette is not good. Gring the color very messy. However, in the old game consoles and old games we played, it has set up the sweat work, because the palette is a display method for the most survival and memory in the case of expensive hardware prices. So the images of the game consoles such as MD and FC at the time were poor, but with the development of technology, the palette has been basically given up by the developer.
The use of the palette is based on the development of the software. If you want to develop a color is not a lot, the speed is very fast, the palette mode should be your best choice, because it is more than other display methods Most, such as fighting games, action games can be displayed with palettes.
The following is a palette schematic:
The data in the memory is the image to be displayed, but the real color value in the image is read from the palette, and the actual memory is stored in the color index in the palette, so a palette image If there is no palette, it will not be displayed. You can also replace other palettes for the same image, as shown below:
The left is the normal palette image, and the right side is changed color palette image. This technology can replace the color of the clothes in the game, that is, we are common to distinguish the same character in different colors in fighting games. method.
Tear phenomenon
Everyone should see the tear phenomenon, as long as you leave a little bit, you can see some software will produce this phenomenon. The tear phenomenon is actually playing the game or watching the image on the image. The mimi bearded in the figure is a tear phenomenon generated during high speed playback. Tearing phenomenon is a problem that game developers often encounter, but it is not difficult to solve, let me introduce how it is produced.
For the sense, the image we see is actually a data area in the memory, and the size view mode of this data area is fixed, and the main map is called in DirectX. When running the game, the game needs to write images synthesized from the background display page into the main map so that we can see the image of the game on the display. It is not all written directly into the main map, but we must see that the continuous high-frequency animation will keep refresh the main section. The problem is in the refresh, in fact, the display shows the image there is a process, but it is too fast. The general display frequency is between 60Hz and 85 Hz, so it is also scanned by the display of the monolith. The tear phenomenon is between the refresh and the display refresh of the main surface, because their refresh has produced this phenomenon. As shown in the figure below, the display is scanning the small ball in the main map. The A step is that the display is scanning the main map, but the positive scan is displayed to a portion of the approximately 1/3. At this time, the main section is refreshed into data moving to the right of the small ball, which produces a phenomenon in the B step. At this time, 1/3 of the display is already an image in the original A step, but to continue to read the 2/3 data left in the main surface, but these 2/3 data is in the steps. The image drawn is different, so the tear phenomenon is generated.
It is not difficult to solve this problem, as long as you know when the monitor's electronic gun is closed and start rescan from the upper corner, the professional point is waiting for the vertical blank, which prevents tear phenomenon and reaches synchronization. The effect of the display.