nikkkilll

khel4

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