C # game development tutorial (D3D)

xiaoxiao2021-03-05  27

This article is suitable for a fifth enthusiast! This article does not involve basic grammar and other content, this article is suitable for all game development beginners, this article starts from the example of the Tutorials folder under the D3D in Microsoft DirectX 9.0 SDK (SUMMER 2004)! !

Keywords: C # game development 3D tutorial

C # (read "C Sharp") is a simple, modern, object-oriented, type, 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)

The first chapter sets 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.drawing; use system.windows.form; 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 // setup window The initial value of the body this.clientsize = new system.drawing.size (400, 300); // and it's caption // Setting Form Title 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); //?, The type of equipment (here, hardware), create a form of graphics devices , Create type, create 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 (parameter of the screen) It is the target, the color, depth (possibly used for template), template (0) because there is no use of template) // begin the scene // Start rendering scene, (because there is no scene, the sentence is empty, the scene is directly over the scene) Rendering) Device.Beginscene (); // rendering of scene Objects Can Happen Here // You can render the scene // end The Scene // Rendering Device.EndScene (); device.present ();} protected override void OnPaint (System.Windows.Forms.PaintEventArgs e) // override OnPaint method {//this.Render (); // Render on painting // cycle refresh the window} protected override void onKeyPress (System.Windows.Forms . KeypressEventargs e) // Overote ONKEYPRESS Method {IF ((int) E.keychar == (int) system.windows.forms.keys.escape) this.close (); // esc WASSED //// If you press ESC to exit the program} ///

///// Program main function, entry point /// static void main () {/ / Using the USING statement to create an object to ensure the destruction of the object (CreateDevice FRM = New CreateDevice ()) {if (! Frm.initializegraphics ()) // Initialize Direct3D {MessageBox.show ("Could Not Initialize Direct3d. This Tutorial Will EXIT."); Return;} fm.show ();

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

New Post(0)