Window Initialization.
Microsoft DirectX is a collection of application programming interfaces (APIs) for handling tasks related to multimedia, especially game programming and video, on Microsoft platforms. Originally, the names of these APIs all began with Direct, such as Direct3D, DirectDraw, DirectMusic, DirectPlay, DirectSound, and so forth. Direct3D (the 3D graphics API within DirectX) is widely used in the development of video games for Microsoft Windows. Direct3D is also used by other software applications for visualization and graphics tasks such as CAD/CAM engineering. As Direct3D is the most widely publicized component of DirectX, it is common to see the names "DirectX" and "Direct3D" used interchangeably. The DirectX software development kit (SDK) consists of runtime libraries in redistributable binary form, along with accompanying documentation and headers for use in coding.
The SDK is available as a free download. While the runtimes are proprietary, closed-source software, source code is provided for most of the SDK samples. Direct3D is a graphics application programming interface (API) for Microsoft Windows. Part of DirectX, Direct3D is used to render three-dimensional graphicsin applications where performance is important, such as games. Direct3D exposes the advanced graphics capabilities of 3D graphics hardware, including Z-buffering, W-buffering, stencil buffering, spatial anti-aliasing, alpha blending, color blending, mipmapping, texture blending, clipping, culling, atmospheric effects, perspective-correct texture mapping, programmable HLSL shaders and effects. In this program we are creating a device, which will be later use to render the images. Here PresentParameters is the public class in Microsoft.DirectX.Direct3D. It describes the presentation parameters. An application can use the Discard swap effect to enable the display driver to choose the most efficient presentation technique for the swap chain. In this practical we are just learning the window framework and initializing a Direct3D device.
Step 1:
i) Create new project, and select “Windows Forms Application”, select .NET Framework as 2.0 in Visuals C#.
ii) 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:
Edit the Form’s C# code file. Namespace must be as same as your project name.
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 GP_P1
{
public partial class Form1 : Form
{
Microsoft.DirectX.Direct3D.Device device;
public Form1()
{
InitializeComponent();
InitDevice();
}
public void InitDevice()
{
PresentParameters pp = new PresentParameters();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.HardwareVertexProcessing, pp);
}
private void Render()
{
device.Clear(ClearFlags.Target, Color.Orange, 0, 1);
device.Present();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Render();
}
}
}
Step 6:
Click on Start. And here is the output. We have initialized 3D Device.
Output:
The SDK is available as a free download. While the runtimes are proprietary, closed-source software, source code is provided for most of the SDK samples. Direct3D is a graphics application programming interface (API) for Microsoft Windows. Part of DirectX, Direct3D is used to render three-dimensional graphicsin applications where performance is important, such as games. Direct3D exposes the advanced graphics capabilities of 3D graphics hardware, including Z-buffering, W-buffering, stencil buffering, spatial anti-aliasing, alpha blending, color blending, mipmapping, texture blending, clipping, culling, atmospheric effects, perspective-correct texture mapping, programmable HLSL shaders and effects. In this program we are creating a device, which will be later use to render the images. Here PresentParameters is the public class in Microsoft.DirectX.Direct3D. It describes the presentation parameters. An application can use the Discard swap effect to enable the display driver to choose the most efficient presentation technique for the swap chain. In this practical we are just learning the window framework and initializing a Direct3D device.
Step 1:
i) Create new project, and select “Windows Forms Application”, select .NET Framework as 2.0 in Visuals C#.
ii) 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:
Edit the Form’s C# code file. Namespace must be as same as your project name.
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 GP_P1
{
public partial class Form1 : Form
{
Microsoft.DirectX.Direct3D.Device device;
public Form1()
{
InitializeComponent();
InitDevice();
}
public void InitDevice()
{
PresentParameters pp = new PresentParameters();
pp.Windowed = true;
pp.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this,
CreateFlags.HardwareVertexProcessing, pp);
}
private void Render()
{
device.Clear(ClearFlags.Target, Color.Orange, 0, 1);
device.Present();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Render();
}
}
}
Step 6:
Click on Start. And here is the output. We have initialized 3D Device.
Output:
No comments
Post a Comment