First of all, we have to know Device, which is the basics of Direct3D.
The Direct3D device
All the roots of the Direct3D class of the drawing are the Device class, you can think that this class is the real devices in your computer, all of which are derived from this class in the scene you draw.
Here, Device has three constructor, now we are ready to use one, in the later chapter, we will introduce additional constructor. Function prototypes and parameters described below we will use public Device (System.Int32 adapter, Microsoft.DirectX.Direct3D.DeviceType deviceType, System.Windows.Forms.Control renderWindow, Microsoft.DirectX.Direct3D.CreateFlags behaviorFlags, Microsoft.DirectX.Direct3D .Pesentparameters presentationParameters The first is your physical display card device, usually 0; second parameter DeviceType, tells Direct3D The type of device you want to build, usually use DeviceType.hardware, meaning you create a hardware device Type, and a parameter value is DeviceType.reference, standard type, unless this parameter is used when performing debugging, it is unnecessary because it will make your program run very slowly. He opened the grating, or using the third in the test card to support the raster function, use the third is endwindow, he tells what you use to present the scene you need, we generally use this, here behave to use this window to present the fourth A behaviorflags is a representation of the equipment established, saying, how we use the software vertex processing, that is The graphics card is slow, but we still don't know if all the graphics cards using this program support this feature, so in order to be safe, we are set to the CPU completion model to the CPAR, which is more troublesome, we just Whether setting is displayed, in fact, he also includes some settings, such as the height, width, and pixel format of the background buffer, and the way to copy from the background buffer to the front cache screen display. If Direct3D is running in a window, the pixel format must query the current display mode.
Ok, the parameters are also introduced. Now we start to build our first device, first, like all C # languages, we must apply for a device first, we can apply for a device under the FRME1 class Private Device Device = NULL ; Then, we build a initialization function to initialize our equipment, here is to use the constructor just mentioned. Public void initializegraphics () {// set parameters
PresentParameters Presentparams = New Presentparameters ();
Presentparams.windowed = true; // window mode presentparams.swapeffect = swapect.discard; // exchange
// Create a device device = new device (0, DeviceType.hardware, this, createflags.softwarevertexprocessing, presentparams);} Here, before the establishment of the device, we applied for a PresentParams to set some places we care. For example, window mode and dual cache, then establish a device, follow the above parameters, we build such a device, use our first graphics card, hardware acceleration, in this class (that is, our Windows window) presented scenes , Use the CPU to establish a polygonal vertex, and is a window mode, using SwaPeffect
Next, we have to call this function so that the device is really established. Static void main () {using (Form1 FRM = New Form1 ()) {// Display window and initializes frm.show (); frm.initializegraphics (); application.run (fm);}}
There is not much to say this here. Everyone can read the following, this modified the .NET default code, use the using statement and show (), is to ensure the security of the program, ensure that we build our equipment Previously, the Windows window has been established and loaded. I suggest that everyone will write like this later. Ok, now you can compile the code. Now, it is the first Direct3D program we have established.
Oh, although it is very simple, it is already a full-meaning Direct3D program. After the DirectX9.c released, the Direct 3D program is written by the C , and it is easy to use C . As the dominant position of the .NET platform is gradually strengthened, this feeling will become more and more obvious. However, the oldest thing is still a oldest thing. What happened again, now it seems to be a migrant worker, others give a drawing, we are just a housing, this, discovery when I find information, Chinese documentation Even translation is very small, don't say original. So, I will gradually translate my English document here, I hope to help you, let us also draw a few drawings instead of masonry. Ha ha ~~~~~