Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Practical 4:
- AIM: Code for Texturing the Traingle using Direct3D 11.
- 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.
- Step 2:Click on View Code of Form 1.
- 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”.
- Step 4:Go to Properties Section of Form, select Paint in the Event List and enter as Form1_Paint.
- Step 5:Copy and Paste the below given code into Form’s C# code file. Namespace must be as same as your project name.
- Program:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using Microsoft.DirectX;
- using Microsoft.DirectX.Direct3D;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- private Microsoft.DirectX.Direct3D.Device device;
- private CustomVertex.PositionTextured[] v = new CustomVertex.PositionTextured[3];
- private Texture texture;
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- device.Clear(ClearFlags.Target, Color.DarkRed, 1, 0);
- device.BeginScene();
- device.SetTexture(0, texture);
- device.VertexFormat = CustomVertex.PositionTextured.Format;
- device.DrawUserPrimitives(PrimitiveType.TriangleList, v.Length / 3, v);
- device.EndScene();
- device.Present();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- PresentParameters obj = new PresentParameters();
- obj.Windowed = true;
- obj.SwapEffect = SwapEffect.Discard;
- device = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, obj);
- device.Transform.Projection = Matrix.PerspectiveFovLH(3.14f / 4, device.Viewport.Width / device.Viewport.Height, 1f, 1000f);
- device.Transform.View = Matrix.LookAtLH(new Vector3(0, 0, 20), new Vector3(0,0,10), new Vector3(0, 1, 2));
- device.RenderState.Lighting = false;
- v[0] = new CustomVertex.PositionTextured(new Vector3(0, 0, 0), 0, 0);
- v[1] = new CustomVertex.PositionTextured(new Vector3(5, 0, 0), 0, 1);
- v[2] = new CustomVertex.PositionTextured(new Vector3(0, 5, 0), -1, 1);
- texture = new Texture(device, new Bitmap("C:\\Users\\SDV\\Pictures\\sunset.jpg"), 0, Pool.Managed);
- }
- }
- }
Add Comment
Please, Sign In to add comment