Visual C # DirectX Development Series A first-knowledge of DirectX

Source: Internet
Author: User

1. How to view the version of the native DirectX:

Click "Start"-"Run", enter "DxDiag" in "Run", the DirectX Diagnostic Tool window pops up, on the home page, there is a lot of system information, the bottom one is the DirectX version.


2. Add a reference to the DirectX Class Library:

Create a new WinForm form application and add three reference (References), respectively: Microsoft.directx, Microsoft.DirectX.Direct3D and Microsoft.DirectX.Direct3DX,


3. First DirectX Program:

First introduce the device class, the device class is used to complete all the graphics operations in DirectX, we can think of this class as a graphics card, all other graphical objects in the scene depend on the device, the computer can have multiple device
Object. So define a drawing device in the global variable, with the following code:

Device device = null;//defining a drawing device

Next, you define an initialization function: Initializedirect3d (), which tells the drawing device how to render to the screen as well as some exception handling, as in the following code:

public bool Initializedirect3d ()        {            try            {                presentparameters presentparams = new PresentParameters ();                Presentparams.windowed = true; Specifies that Presentparams.swapeffect = Swapeffect.discard is displayed as a Windows Form                ;//The current screen is drawn after it is automatically removed from memory                device = new device (0, Devicetype.hardware, this,                createflags.softwarevertexprocessing, presentparams); Instantiate the device object                return true;            catch (directxexception e)            {                MessageBox.Show (e.tostring (), "Error");//Handling exception                return false;            }        }

Next we will define the render function render (), the code is as follows:

   public void render ()        {            if (device = = NULL)//If device is empty, {return is not rendered                ;            }            Device. Clear (Clearflags.target, color.red, 1.0f, 0); Clears the Windows interface to red            device. BeginScene ();            Add the rendered graphics code            device here. EndScene ();            Device. Present ();        }


Finally define the program entry, the code is as follows:

static void Main ()        {            Form1 frm1 = new Form1 ();//Create Form Object            if (Frm1. Initializedirect3d () = = false)//Check if Direct3D starts            {                MessageBox.Show ("Cannot Start direct3d! "," Error! ");                return;            }            Frm1. Show (); If everything is initialized successfully, the form while (FRM1) is displayed            . Created)//Set a loop to update the render state            {Frm1 in real time                . Render (); Keep device rendering until the program finishes                application.doevents ();//Handle input events such as keyboard and mouse            }        }

PS: When finished I run the error, prompt

This is because using the Dirext3d managed library under. NET 4.0, the "mixed-mode assembly is generated for the v1.1.4322" version of the runtime and cannot be loaded in the 4.0 runtime without additional information being configured. "Exception information, view the assembly Microsoft.DirectX.dll, Microsoft.DirectX.Direct3D.dll, Microsoft.DirectX.Direct3DX, and discover its. NET The runtime version is v1.1.4322, which means that the D3D managed library was built under the. NET v1.1 version. In. NET4.0 before, due to the nature of the program operating environment or. NET2.0, and. NET2.0 compatible. NET1.0 and 1.1, but when you upgrade to. NET4.0, the. NET kernel makes significant adjustments to assemblies that were previously generated in. Net2.0 or. net3.5, if you want to run under. net4.0, To specify the common language runtime version supported by this application in the configuration file and to enable the. NET Framework 2.0 Runtime Activation policy, modify the app. config content as follows:

<?xml version= "1.0"?><configuration>  <startup uselegacyv2runtimeactivationpolicy= "true" >    <supportedruntime version= "v4.0"/>  </startup></configuration>


There may also be an error like this,

As for this question, the error message is clear, you can create a new 32-bit application (ie x86) in Configuration Manager,


Post-run effects



This article source: http://download.csdn.net/detail/yangyisen0713/8385527

Visual C # DirectX Development Series A first-knowledge of DirectX

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.