This is what I love about SADeveloper, the members are soooo keeen, I got to thank Deon for inspiring to teach this old dog that Direct-X is not that hard. Yes I am supposed to be wrapping up the material from my Web Service, talk so I can post it. I'll go do that now, but check it out, I admit I was following a Tut, but I got my first MDX applet to run. Nothing fancy, just a 2d triangle, but I can feel the bug biting, who knows, maybe I'll learn a new trick.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DirectXTest
{
public class frmFirstMDX : System.Windows.Forms.Form
{
private Device mDevice = null;
private System.ComponentModel.Container mComponent = null;
public frmFirstMDX()
{
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (mComponent != null)
{
mComponent.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.mComponent = new System.ComponentModel.Container();
this.Size = new System.Drawing.Size(300,300);
this.Text = "frmFirstMDX";
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
mDevice.Clear(ClearFlags.Target, System.Drawing.Color.CornflowerBlue, 1.0f, 0);
CustomVertex.TransformedColored[] mPoints = new CustomVertex.TransformedColored[3];
//Set up our Triange
mPoints[0].SetPosition(new Vector4(this.Width / 2.0f, 50.0f, 0.5f, 1.0f));
mPoints[0].Color = System.Drawing.Color.Aqua.ToArgb();
mPoints[1].SetPosition(new Vector4(this.Width - (this.Width / 5.0f), this.Height - (this.Height / 5.0f), 0.5f, 1.0f));
mPoints[1].Color = System.Drawing.Color.Black.ToArgb();
mPoints[2].SetPosition(new Vector4(this.Width / 5.0f, this.Height - (this.Height / 5.0f), 0.5f, 1.0f));
mPoints[2].Color = System.Drawing.Color.Purple.ToArgb();
//Tell MDX to draw it
mDevice.BeginScene();
mDevice.VertexFormat = CustomVertex.TransformedColored.Format;
mDevice.DrawUserPrimitives(PrimitiveType.TriangleList, 1, mPoints);
mDevice.EndScene();
mDevice.Present();
this.Invalidate();
}
#endregion
[STAThread]
static void Main()
{
using (frmFirstMDX frm = new frmFirstMDX())
{
// Show form and initialize graphics engine
frm.Show();
frm.InitializeGraphics();
Application.Run(frm);
}
}
/// <summary>
/// We will initialize our graphics Device here
/// </summary>
public void InitializeGraphics()
{
// Set our presentation parameters
PresentParameters mPresentParams = new PresentParameters();
mPresentParams.Windowed = true;
mPresentParams.SwapEffect = SwapEffect.Discard;
// Create mDevice
mDevice = new Device(0, DeviceType.Hardware, this,
CreateFlags.SoftwareVertexProcessing, mPresentParams);
}
}
}