0% found this document useful (0 votes)
66 views6 pages

Output With Images 3 Differnt

The document contains code for rendering 3D graphics using DirectX in C#. It initializes a DirectX device, defines vertex and texture data, and implements a Paint method that clears the target, sets the texture, renders the geometry, and presents the results. The code is contained within a Form class and is run on load to set up the 3D scene and on paint to render it with different textures for each output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views6 pages

Output With Images 3 Differnt

The document contains code for rendering 3D graphics using DirectX in C#. It initializes a DirectX device, defines vertex and texture data, and implements a Paint method that clears the target, sets the texture, renders the geometry, and presents the results. The code is contained within a Form class and is run on load to set up the 3D scene and on paint to render it with different textures for each output.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Output 1 with picture

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\\p2.jpg"), 0,
Pool.Managed);
}

private void Form2_Paint(object sender, PaintEventArgs e)


{
device.Clear(ClearFlags.Target, Color.CornflowerBlue, 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();

}
}
}
Output 2 with image

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();

}
}
}

Output 3 with image


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\\p1.jpg"), 0,
Pool.Managed);
}

private void Form2_Paint(object sender, PaintEventArgs e)


{
device.Clear(ClearFlags.Target, Color.Cyan, 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();

}
}
}

You might also like