Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Practical 5:
- Aim: Code for Texturing the Rectangle 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 WindowsFormsApplication4
- {
- public partial class Form2 : Form
- {
- private Microsoft.DirectX.Direct3D.Device device;
- private CustomVertex.PositionTextured[] v = new CustomVertex.PositionTextured[6];
- private Texture texture;
- public Form2()
- {
- InitializeComponent();
- }
- private void Form2_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, 2, 1), 0, 0);
- v[1] = new CustomVertex.PositionTextured(new Vector3(0, -2, 1), 0, 1);
- v[2] = new CustomVertex.PositionTextured(new Vector3(2, -2, 1),-1,1);
- v[3] = new CustomVertex.PositionTextured(new Vector3(2, -2, 1), -0, 0);
- v[4] = new CustomVertex.PositionTextured(new Vector3(2, 2, 1), 0, 1);
- v[5] = new CustomVertex.PositionTextured(new Vector3(0, 2, 1), -1, 1);
- texture = new Texture(device, new Bitmap("D:\\design\\p3.jpg"), 0, Pool.Managed);
- }
- private void Form2_Paint(object sender, PaintEventArgs e)
- {
- device.Clear(ClearFlags.Target, Color.BlueViolet, 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();
- }
- }
- }
Add Comment
Please, Sign In to add comment