nikkkilll

khel3

Oct 4th, 2019
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. Practical 3:
  2. AIM: Draw a Traingle using direct 3D 11.
  3. Step 1:Create new project, and select “Windows Forms Application”, select .NET Framework as 2.0 in Visuals C#.Right Click on properties Click on open click on build Select Platform Target and Select x86.
  4. Step 2:Click on View Code of Form 1.
  5. Step 3:Go to Solution Explorer, right click on project name, and select Add Reference. Click on Browse and select the given .dll files which are “Microsoft.DirectX”, “Microsoft.DirectX.Direct3D”, and “Microsoft.DirectX.DirectX3DX”.
  6. Step 4:Go to Properties Section of Form, select Paint in the Event List and enter as Form1_Paint.
  7. Step 5:Copy and Paste the below given code into Form’s C# code file. Namespace must be as same as your project name.
  8. Program:
  9. using System;
  10. using System.Collections.Generic;
  11. using System.ComponentModel;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.Text;
  15. using System.Windows.Forms;
  16. using Microsoft.DirectX;
  17. using Microsoft.DirectX.Direct3D;
  18.  
  19.  
  20. namespace WindowsFormsApplication1
  21. {
  22. public partial class Form1 : Form
  23. {
  24. Microsoft.DirectX.Direct3D.Device device;
  25. public Form1()
  26. {
  27. InitializeComponent();
  28. InitDevice();
  29. }
  30. private void InitDevice()
  31. {
  32. PresentParameters pp = new PresentParameters(); pp.Windowed = true;
  33. pp.SwapEffect = SwapEffect.Discard;
  34. device = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, pp);
  35. }
  36.  
  37.  
  38. private void Render()
  39. {
  40. CustomVertex.TransformedColored[] vertexes = new CustomVertex.TransformedColored[3];
  41. vertexes[0].Position = new Vector4(240, 110, 0, 1.0f); vertexes[0].Color = System.Drawing.Color.FromArgb(0, 255, 0).ToArgb();
  42.  
  43.  
  44. vertexes[1].Position = new Vector4(380, 420, 0, 1.0f); vertexes[1].Color = System.Drawing.Color.FromArgb(0, 0, 255).ToArgb(); vertexes[2].Position = new Vector4(110, 420, 0, 1.0f);
  45. device.Clear(ClearFlags.Target, Color.DarkOrchid, 1.0f, 0); device.BeginScene();
  46. device.VertexFormat = CustomVertex.TransformedColored.Format; device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, vertexes); device.EndScene();
  47. device.Present();
  48. }
  49.  
  50.  
  51.  
  52. private void Form1_Paint(object sender, PaintEventArgs e)
  53. {
  54. Render();
  55. }
  56.  
  57. private void Form1_Load(object sender, EventArgs e)
  58. {
  59.  
  60. }
  61. }
  62. }
Add Comment
Please, Sign In to add comment