Revision 1324 of "कंप्यूटर ग्राफिक्स/2013-14/प्रयोगशाला 14" on hiwikiversity== डायरेक्टएक्स9 में संक्षिप्त परिचय ==
=== अवलोकन ===
इस प्रयोगशाला में हम डायरेक्टएक्स में सरल दृश्य के बनाने और इसे के अंदर कुछ तत्वों के साथ ड्रा के विषय में कुछ सामान्य मुद्दों पर चर्चा करेंगे। कोड सी# में लिखे जाएँगे। यह बारीकी से जावा जैसा दिखता है।
=== साधारण हैलो वर्ल्ड एप्लीकेशन बनाना ===
<source lang="csharp">
[...]
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Direct3D = Microsoft.DirectX.Direct3D;
namespace FirstDirectX
{
public class HelloDirectX : System.Windows.Forms.Form
{
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(true);
HelloDirectX frm = new HelloDirectX();
frm.Show();
Application.run(frm);
}
[...]
}
}
</source>
हर प्रबंधित डायरेक्टएक्स एप्लीकेशन में मूल रूप से आवश्यक:
* '''आरंभीकरण (initialization)''' विधि जहां Direct3D.Device वस्तु को जोड़ने पूरा किया है। (ओजीएल ''Init'' फ़ंक्शन के समान)
* '''रेंडरिंग (rendering)''' विधि जो दृश्य हैंडलिंग करता है। (ओजीएल डिस्प्ले फ़ंक्शन समान)
* एक '''डिवाइस रीसेट''' हैंडलिंग विधि। इसका उदाहरण है जब खिड़की विंडो के साइज में परिवर्तन (resize) किया जाता है। तभ ऐसी घटना पर यह हैंडलिंग विधि शुरू हो जाती है।
इसके अलावा हम माउस, कीबोर्ड, जॉयस्टिक आदि का उपयोग के लिये कुछ '''यूजर इंटरेक्शन (user interaction)''' की आवश्यकता होती है।
=== डायरेक्टएक्स डिवाइस के आरंभीकरण (Initialization)===
<source lang="csharp">
[...]
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Direct3D = Microsoft.DirectX.Direct3D;
namespace FirstDirectX
{
public class HelloDirectX : System.Windows.Forms.Form
{
private Direct3D.Device device = null;
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(true);
HelloDirectX frm = new HelloDirectX();
// Initialize the device.
frm.Init();
// Show the form.
frm.Show();
Application.run(frm);
}
public void Init()
{
// Do we support hardware vertex processing? If so, use it.
// If not, downgrade to software.
Caps caps = Direct3D.Manager.GetDeviceCaps(Direct3D.Manager.Adapters.Default.Adapter,
Direct3D.DeviceType.Hardware);
CreateFlags flags;
if (caps.DeviceCaps.SupportsHardwareTransformAndLight)
flags = CreateFlags.HardwareVertexProcessing;
else
flags = CreateFlags.SoftwareVertexProcessing;
// Everything checks out - create a simple, windowed device.
PresentParameters d3dpp = new PresentParameters();
d3dpp.BackBufferFormat = Format.Unknown;
d3dpp.SwapEffect = SwapEffect.Discard;
d3dpp.Windowed = true;
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = DepthFormat.D16;
d3dpp.PresentationInterval = PresentInterval.Immediate;
device = new Direct3D.Device(0, Direct3D.DeviceType.Hardware, this, flags,
d3dpp);
}
[...]
}
}
</source>
=== रेंडरिंग (Rendering) ===
<source lang="csharp">
[...]
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Direct3D = Microsoft.DirectX.Direct3D;
namespace FirstDirectX
{
public class HelloDirectX : System.Windows.Forms.Form
{
private Direct3D.Device device = null;
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(true);
HelloDirectX frm = new HelloDirectX();
// Initialize the device.
frm.Init();
// Show the form.
frm.Show();
Application.run(frm);
}
public void Init()
{
[...]
}
private void Render()
{
// Now we can clear just view-port's portion of the buffer to black
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer,
Color.FromArgb(255, 0, 0, 0), 1.0f, 0);
device.BeginScene();
// Place your code here.
device.EndScene();
try
{
device.Present();
}
catch (DeviceLostException)
{
device.Reset(device.PresentationParameters);
}
}
// We need to override this method so that we can control what is being drawn on the screen.
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
this.Render();
}
[...]
}
}
</source>
=== डिवाइस रीसेट (Device resetting) ===
<source lang="csharp">
[...]
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Direct3D = Microsoft.DirectX.Direct3D;
namespace FirstDirectX
{
public class HelloDirectX : System.Windows.Forms.Form
{
private Direct3D.Device device = null;
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(true);
HelloDirectX frm = new HelloDirectX();
// Initialize the device.
frm.Init();
// Show the form.
frm.Show();
Application.run(frm);
}
public void Init()
{
[...]
}
private void Render()
{
[...]
}
// We need to override this method so that we can control what is being drawn on the screen.
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
this.Render();
}
// Event handler for managing the device reset instance.
public void OnResetDevice(object sender, EventArgs e)
{
// Reinitialize the DX device.
Direct3D.Device device = (Direct3D.Device)sender;
// Reinitialize some parameters:
device.RenderState.CullMode = Cull.None;
device.RenderState.FillMode = FillMode.Solid;
device.RenderState.Lighting = true;
}
[...]
}
}
</source>
[[Category:HI]]All content in the above text box is licensed under the Creative Commons Attribution-ShareAlike license Version 4 and was originally sourced from https://hi.wikiversity.org/w/index.php?oldid=1324.
![]() ![]() This site is not affiliated with or endorsed in any way by the Wikimedia Foundation or any of its affiliates. In fact, we fucking despise them.
|