nikkkilll

khel5

Oct 4th, 2019
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. Practical 5:
  2. Aim: Code for Texturing the Rectangle using Direct3D 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. namespace WindowsFormsApplication4
  20. {
  21.  
  22. public partial class Form2 : Form
  23. {
  24. private Microsoft.DirectX.Direct3D.Device device;
  25. private CustomVertex.PositionTextured[] v = new CustomVertex.PositionTextured[6];
  26. private Texture texture;
  27. public Form2()
  28. {
  29. InitializeComponent();
  30. }
  31.  
  32. private void Form2_Load(object sender, EventArgs e)
  33. {
  34.  
  35. PresentParameters obj = new PresentParameters();
  36. obj.Windowed = true;
  37. obj.SwapEffect = SwapEffect.Discard;
  38. device = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, obj);
  39. device.Transform.Projection = Matrix.PerspectiveFovLH(3.14f / 4, device.Viewport.Width / device.Viewport.Height, 1f, 1000f);
  40. device.Transform.View = Matrix.LookAtLH(new Vector3(0, 0, 20), new Vector3(0, 0, 10), new Vector3(0, 1, 2));
  41. device.RenderState.Lighting = false;
  42. v[0] = new CustomVertex.PositionTextured(new Vector3(0, 2, 1), 0, 0);
  43. v[1] = new CustomVertex.PositionTextured(new Vector3(0, -2, 1), 0, 1);
  44. v[2] = new CustomVertex.PositionTextured(new Vector3(2, -2, 1),-1,1);
  45. v[3] = new CustomVertex.PositionTextured(new Vector3(2, -2, 1), -0, 0);
  46. v[4] = new CustomVertex.PositionTextured(new Vector3(2, 2, 1), 0, 1);
  47. v[5] = new CustomVertex.PositionTextured(new Vector3(0, 2, 1), -1, 1);
  48. texture = new Texture(device, new Bitmap("D:\\design\\p3.jpg"), 0, Pool.Managed);
  49. }
  50.  
  51. private void Form2_Paint(object sender, PaintEventArgs e)
  52. {
  53. device.Clear(ClearFlags.Target, Color.BlueViolet, 1, 0);
  54. device.BeginScene();
  55. device.SetTexture(0, texture);
  56. device.VertexFormat = CustomVertex.PositionTextured.Format;
  57. device.DrawUserPrimitives(PrimitiveType.TriangleList, v.Length / 3, v);
  58. device.EndScene();
  59. device.Present();
  60.  
  61. }
  62. }
  63. }
Add Comment
Please, Sign In to add comment