This article is suitable for a fifth enthusiast! This article does not involve basic grammar, etc.
Suitable for all game development beginners, this article from Microsoft DirectX 9.0 SDK (Summer 2004)
The example of the Tutorials folder under D3D begins! ! Keywords: C # game development 3D tutorial C # (read "C Sharp") is a simple, modern, object-oriented, and secure programming language. C and C programmers can be familiar with it. C # Attract high efficiency and powerful power of the "Application Rapid Development" (RAD) language. (C # language standard reference, if you say) nonsense, enter the theme, start our C # game development trip! (If you have a mistake, please forgive me)
Chapter 1 forms our equipment
1. Create a DX program, first you need to download Microsoft DirectX SDK (best 9.0 referred to as DX), install. Then you have to ensure that you have installed the Visual Studio .NET development product suite (referred to as vs.net), this is the smallest environment, then you can develop. Create a DX device. Open the Tutorials1 example under the Tutorials folder in DX and open the compile! Below is the run results: create a DX window! Below is the code:
/ / -------------------------------------------------------------------------------------------- ----------------------------- // File: CreateDevice.cs // Create Device // Desc: this is the first tutorial for Using Direct3d. in this tutorial, all // We all doing it to custom a direct3d device and using it to clear the // window.// Note: This is the first example of using D3D, in this example, we want Just create a D3D "device" and refresh window // Copyright (c) Microsoft Corporation. All Rights Reserved.//------------------- -------------------------------------------------- ------ using System; using System.Drawing; using System.Windows.Forms; using Microsoft.DirectX; using Microsoft.DirectX.Direct3D; namespace DeviceTutorial {public class CreateDevice: Form {// Our global variables for this projectDevice Device = NULL; // Our rendering device // Our drawing device public createDevice () {// set the initial size of our form // Setting the initial value this.clientsize = new system.drawing.size (400,300) ; // and it's capen // Setting the form header this.text = "D3D Tutorial 01: CreateDevice";} public bool initializegraphics () {TRY {/ / Now let's setup our D3D stuff // D3D now we set some of the options PresentParameters presentParams = new PresentParameters (); presentParams.Windowed = true; // marking the program is running in windowed mode presentParams.SwapEffect = SwapEffect.Discard; // return Or set the switching area option ???? Device = New Device (0, DeviceType.hardware, this, createflags.softwarevertexprocessing, presentparams); //? And equipment type (here you selected hardware), create a form of graphics devices, Create a type, create an entity); // Create a device instance return true;} catch (directxexception) // Capture DX exception {RETURN FALSE;}} private void render () // Refresh module {if (Device == null) Return; // Clear the Backbuffer to a blue color // Brush the device window into green device.clear (ClearFlags.target, System.drawing.Color.blue, 1.0F, 0);
// clear (the parameter of the screen is selected here is the target, the color, depth (possibly used for template), template (0) because there is no use template) // begin the footne // Start rendering scene, (because there is no scene) So, the sentence is empty, and the scene's rendering is directly rendered. (); device.present ();} protected override void onpaint (system.windows.forms.painteventargs e) // Override onpaint method {//this.render (); // render on painting // loop refresh window } protected overserride void onkeypress (system.windows e) // Overrides onkeypress method {if (byte) E.KEYCHAR == (int) system.windows.forms.keys.escape) this. Close (); // esc WAS PRESSED / / If the ESC is pressed} ///
The first is: use system; use system.drawing; using system.windows.forms; using microsoft.directX; using microsoft.directx.direct3d; use 3 space! Note that in the main MAIN main program of the program, it is also used, Note that this is a statement in the C #, the using statement defines a range, and the object will be processed at the end of this range. Then Device device = null; this sentence is an object device for the Device class but does not create an instance object, and an instance object creation must be created using the New statement. The Public Bool InitializeGraphics () function is to initialize the DX. The private void render () function is the rendering function, where Device.Beginscene (); is start rendering, device.endscene (); device.present (); end rendering, Like turning! You can add images of display or text display or text display or text display in Beginscene (); and EndScene (); and endscene (); The last while (frm.created) {frm.render (); Application.doEvents ();} is whether the detector is executed, is the method of using the FRM instance object (); to render the screen, Application.doevents ); Is the execution message loop! such! A simple DX window is established! annex