Jump to content
  • Advertisement
Sign in to follow this  
Roman_O

Creating a triangle in .NET 2.0/MDX August 2006

This topic is 4450 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Having trouble creating a triangle in .NET 2.0 using MDX to create a triangle with the directions in SAMS Kickstart. Source Code:
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 Chapter1Code
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
        private Device device = null;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
		}

        /// <summary>
        /// We will initialize our graphics device here
        /// </summary>
        public void InitializeGraphics()
        {
            // Set our presentation parameters
            PresentParameters presentParams = new PresentParameters();

            presentParams.Windowed = true;
            presentParams.SwapEffect = SwapEffect.Discard;

            // Create our device
            device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
        }

        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            device.Clear(ClearFlags.Target, System.Drawing.Color.CornflowerBlue, 1.0f, 0);

            CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[3];
            verts[0].SetPosition(new Vector4(this.Width / 2.0f, 50.0f, 0.5f, 1.0f));
            verts[0].Color = System.Drawing.Color.Aqua.ToArgb();
            verts[1].SetPosition(new Vector4(this.Width - (this.Width / 5.0f), this.Height - (this.Height / 5.0f), 0.5f, 1.0f));
            verts[1].Color = System.Drawing.Color.Black.ToArgb();
            verts[2].SetPosition(new Vector4(this.Width / 5.0f, this.Height - (this.Height / 5.0f), 0.5f, 1.0f));
            verts[2].Color = System.Drawing.Color.Purple.ToArgb();

            device.BeginScene();
            device.VertexFormat = CustomVertex.TransformedColored.Format;
            device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, verts);
            device.EndScene();

            device.Present();

            this.Invalidate();
        }

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.SuspendLayout();
            // 
            // Form1
            // 
            this.ClientSize = new System.Drawing.Size(292, 266);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
        static void Main() 
        {
            using (Form1 frm = new Form1())
            {
                // Show our form and initialize our graphics engine
                frm.Show();
                frm.InitializeGraphics();
                Application.Run(frm);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
	}
}


Error: 'Microsoft.DirectX.Direct3D.CustomVertex.TransformedColored' does not contain a definition for 'SetPosition' I can only see 'Position' being derived from TransformedColored with no 'SetPosition'. Perhaps I should turn this into a Property? Or is there something obvious that I'm missing? Edit: Using Microsoft's own SDK samples I have found that I need a graphics stream and have to use the VertexBuffer object. [Edited by - Roman_O on August 9, 2006 10:50:47 AM]

Share this post


Link to post
Share on other sites
Advertisement
Yes, I think thats what I found out when I was working through that book. Try hovering over the command and see if it shows as a property or not, but what I end up doing is try for function and then property if it doesn't work.

Now, whether there is a difference between 1.1 and 2.0 in that area I can't remember.

Share this post


Link to post
Share on other sites
The whole reason that this won't work anymore is because of .NET 2.0 I think due to some methods being switched around and some replaced with properties. It did work in .NET 1.1 if I remember correctly. Ah well, guess I'll have to get used to translating all these .NET 1.1 books I have into 2.0 :(

Share this post


Link to post
Share on other sites
I think I ended up going back to using 1.1 because of the changes theyre doing in 2.0 or the bugs. I seem to have a lot better chance of having no problems that way. Of course once I get the new Windows and its been around a little while I'll try out DirectX10 but thats a way off.

Share this post


Link to post
Share on other sites
Well... In my Opinion the changes between 1.1 and 2.0 are not so bad.
Regarding the probs you described - but also apart from that - I can only say:

USE THE DOCUMENTATION!

all properties and methods are described in there, sometimes including examples. If something doesn't work the way your book describes it, then look it up in the doc and you'll save yourself a lot of trouble and frustration.

Good luck for the future,

Martin

[edit]
And yes, the vertice's position is a property called Position ;)
[/edit]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!