WinForm Use Using VS2003.NET

Irrlicht.Net is no longer developed or supported, Irrlicht.Net Cross Platform is a much more complete wrapper. Please ask your C# related questions on their forums first.
Locked
TOP-Proto
Posts: 14
Joined: Sun Jun 25, 2006 8:41 pm

WinForm Use Using VS2003.NET

Post by TOP-Proto »

Had some problems with the examples.

1. Add reference to Irrlicht.NET
2. Add Irrlicht into the bin/debug directory
3. Move media into right location
4. Create new WindowsApplication
5. Copy in all code below


heres modified example code made to work in 2003.net

Code: Select all

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Irrlicht;
using Irrlicht.Video;
using Irrlicht.Core;
using Irrlicht.Scene;

namespace WindowsApplication2
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.PictureBox pictureBox1;
		private System.Windows.Forms.Button button1;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

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

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <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.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.button1 = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// pictureBox1
			// 
			this.pictureBox1.Location = new System.Drawing.Point(0, 0);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(1136, 664);
			this.pictureBox1.TabIndex = 0;
			this.pictureBox1.TabStop = false;
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(1016, 680);
			this.button1.Name = "button1";
			this.button1.TabIndex = 1;
			this.button1.Text = "button1";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
			this.ClientSize = new System.Drawing.Size(1136, 720);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.pictureBox1);
			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>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}
		IrrlichtDevice device; //Declare the device

		void runIrrlichtInWindowsFormTest(Control c)
		{

			device = new IrrlichtDevice(Irrlicht.Video.DriverType.DIRECT3D9,
				new Dimension2D(c.Width, c.Height),
				32, false, false, false, true, c.Handle);

			ICameraSceneNode cam = device.SceneManager.AddCameraSceneNode(null, new Vector3D(), new Vector3D(), -1);
			
			ISceneNodeAnimator anim = device.SceneManager.CreateFlyCircleAnimator(new Vector3D(0, 10, 0), 30.0f, 0.003f);
			
			cam.AddAnimator(anim);
			
			ISceneNode cube = device.SceneManager.AddTestSceneNode(25, null, -1, new Vector3D());
			
			cube.SetMaterialTexture(0, device.VideoDriver.GetTexture("../../../media/rockwall.bmp"));
			// draw everything
			// Note, using device.WindowActive will not work on a control, since we don't
			// really activate controls..
			
			while (device.Run() && c.Enabled)
			{
				device.VideoDriver.BeginScene(true, true, new Irrlicht.Video.Color(255, 0, 0, 50));
				device.SceneManager.DrawAll();
				device.GUIEnvironment.DrawAll();
				device.VideoDriver.EndScene();
			}
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
		runIrrlichtInWindowsFormTest(pictureBox1);
		}
	}
}
jayvatar
Posts: 6
Joined: Mon Nov 13, 2006 4:44 pm
Location: Kansas City, MO

Post by jayvatar »

This works well, except you need to insert code to check to see if the device is running on close, cause if you close it after you click button1, the application does not close in memory.
Locked