Is it possible to use Irrlicht and Windows Forms?

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
jag0423
Posts: 3
Joined: Wed Aug 31, 2005 9:06 am

Is it possible to use Irrlicht and Windows Forms?

Post by jag0423 »

I am on a 5 man game development team at my universtiy. We are designing a blitz and speed chess game. This project will be complete in 3 months and I would like to share it with the Irrlicht.Net community after it is complete. Hopefully this will help some of the developers get a starting point or help in their development by looking at our implementation. We are using Microsoft Visual Studio 7, C++ for the game engine, C# for the AI, Blender to model the meshes and then export to Quake2 md2 format, TCP\IP Net Protocol (rules are still being established), and Macromedia Flash for the GUI. This will be package in a Windows Form. I would like to use Irrlicht.Net as the 3D engine to display the board and some mesh animation.

My Question:
Is it possible to use Irrlicht in Windows Forms?
Foole
Posts: 87
Joined: Mon Aug 29, 2005 10:08 am

Post by Foole »

From changes.txt for 0.11.0:

"Irrlicht.NET can now run inside a pre created Windows.Form window."

You can pass a window handle to the constructor for IrrlichtDevice.
jag0423
Posts: 3
Joined: Wed Aug 31, 2005 9:06 am

Post by jag0423 »

Thanks for the the tip. Ill check it out
jag0423
Posts: 3
Joined: Wed Aug 31, 2005 9:06 am

Post by jag0423 »

I see that Irrlicht can be used with windows forms. I was wondering if there is a way where the animation doesn't occupy the full screen of the form, in order to leave space for other components, such as windows form buttons.
Foole
Posts: 87
Joined: Mon Aug 29, 2005 10:08 am

Post by Foole »

As far as I know, no.

I would have thought you could put a picture box control on your form and use the Handle property of that, but after a quick test, I couldn't get it working. Everything seems to run, but the window never gets painted. Perhaps this should be a feature request?
shurijo
Posts: 148
Joined: Sat Feb 21, 2004 3:04 am

Post by shurijo »

You can put panels, images, groupboxes,etc. over the background of the form, so it doesn't appear to take the entire form.

I've also tried to use the handle of a picturebox and it didn't work for me. I also had some problems with transparent images (transparency doesn't seem to work) overlayed on the form's background.
kaeles-notlogged

Post by kaeles-notlogged »

maybe you could try using an mdi, make irrlicht a seperate window that is inside the main form window, and have all the controls on the main form, that way you can still control the size of the irrlicht window.

Not sure if that would work, im just learning c# so, just a suggestion.
Irme
Posts: 55
Joined: Sat Jul 16, 2005 8:24 am

Post by Irme »

Try passing the handle of a picture box or panel instead of the form, that may work. i'm not sure tho.
Duncan Mac Leod
Posts: 64
Joined: Sun May 22, 2005 3:06 pm
Location: Germany
Contact:

Post by Duncan Mac Leod »

Foole wrote:As far as I know, no.

I would have thought you could put a picture box control on your form and use the Handle property of that, but after a quick test, I couldn't get it working. Everything seems to run, but the window never gets painted. Perhaps this should be a feature request?
AFAIK - yes, BUT: you'll have to do a lot of extra work, if you want something special... - for standard use (in Windows.Forms) there are no issues...

We are using Niko's Engine for our upcoming RPG Toolset and have modified a lot of things, but it's possible to have the Engine rendering in Docking Containers like VS.NET 8) ...

Image
Image
Image
Image

Duncan
--
Tucan Entertainment
karim1a2004
Posts: 41
Joined: Sat Jan 15, 2005 8:03 pm
Contact:

Post by karim1a2004 »

hello
with which program one can do that
you with a source code
thank
Duncan Mac Leod
Posts: 64
Joined: Sun May 22, 2005 3:06 pm
Location: Germany
Contact:

Post by Duncan Mac Leod »

karim1a2004 wrote:hello
with which program one can do that
you with a source code
thank
I don't know what you mean by 'with which program one can do that'...

These are Screenshots of our upcoming Toolset (and not a Program for using with Irrlicht) and one can develop Modules for our upcoming RPG Game (based on a modified version of Irrlicht) with that Toolset...

The Toolset's look (and it's features) is similiar to Visual Studio, cause we'll provide a dev.-environment for coding Game-Modules...
trg
Posts: 10
Joined: Tue Sep 20, 2005 7:33 pm

Post by trg »

To render Irrlicht in a windows form, or in a control placed on a form, such as a panel (VB.NET), just do something like this (tested):

Module1.vb

Code: Select all

' Example application using Irrlicht.NET 
' A little bit more complicated than the C++ hello world example, 
' but hey, its the only one yet. Give me some time.
Module Module1




    ' The main entry point for the application.
    Sub Main()

        ' start up the engine


        Dim f2 As Form1 = New Form1
        f2.Show()

        Dim device As IrrlichtDevice



        Dim dimension As New Dimension2D(f2.PanelIrr.Width, f2.PanelIrr.Height)
        device = New IrrlichtDevice(Irrlicht.Video.DriverType.DIRECTX9, dimension, 16, False, False, False, False, f2.PanelIrr.Handle)

        'device = New IrrlichtDevice(Irrlicht.Video.DriverType.DIRECTX9)

        device.ResizeAble = True
        device.WindowCaption = "Irrlicht.NET VisualBasic example 01 - Hello World"

        ' load some textures 

        Dim texSydney As ITexture = device.VideoDriver.GetTexture("media\sydney.bmp")
        Dim texWall As ITexture = device.VideoDriver.GetTexture("media\wall.bmp")
        Dim texLogo As ITexture = device.VideoDriver.GetTexture("media\irrlichtlogoaligned.jpg")

        ' load the animated mesh of sydney

        Dim mesh As Irrlicht.Scene.IAnimatedMesh = device.SceneManager.GetMesh("media\sydney.md2")

        If mesh Is Nothing Then
            System.Windows.Forms.MessageBox.Show("Could not load mesh ..\..\media\sydney.md2, exiting.", "Problem starting program")
            Return
        End If

        ' add a camera, a test scene node and the animated mesh to the scene	

        'Dim cam As ICameraSceneNode = device.SceneManager.AddCameraSceneNode(Nothing , 100, 100, -1)
        'cam.Position = New Vector3D(20, 0, -50)

        Dim node As ISceneNode = device.SceneManager.AddTestSceneNode(15, Nothing, -1, New Vector3D(30, -15, 0))
        node.SetMaterialTexture(0, texWall)

        node = device.SceneManager.AddAnimatedMeshSceneNode(mesh, Nothing, -1)
        node.SetMaterialTexture(0, texSydney)
        node.SetMaterialFlag(MaterialFlag.LIGHTING, False)

        ' disable mouse cursor
        'device.CursorControl.Visible = False

        ' start drawing loop

        Dim fps As Integer = 0


        While device.Run() = True And f2.PanelIrr.Visible
            If f2.PanelIrr.Visible Then

                device.VideoDriver.BeginScene(True, True, New Color(0, 100, 100, 100))

                device.SceneManager.DrawAll()

                ' draw the logo

                device.VideoDriver.Draw2DImage(texLogo, New Position2D(10, 10), New Rect(0, 0, 88, 31), New Rect(New Position2D(0, 0), device.VideoDriver.ScreenSize), New Color(255, 255, 255, 255), False)
                device.VideoDriver.EndScene()

                If (fps <> device.VideoDriver.FPS) Then
                    fps = device.VideoDriver.FPS
                    device.WindowCaption = "Irrlicht.NET Visual Basic example 01 - Hello World [" + device.VideoDriver.Name + "] fps:" + fps.ToString

                End If



            End If

        End While



    End Sub


End Module



Form1.vb

Code: Select all

Imports Irrlicht ' compiler error here? Look at the next comment
Imports Irrlicht.Video
Imports Irrlicht.Core
Imports Irrlicht.Scene

Public Class Form1
    Inherits System.Windows.Forms.Form

    Public WithEvents PanelIrr As New System.Windows.Forms.Panel
    Dim ArRoads() As Dimension2D, SArRoad&

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Panel1 As System.Windows.Forms.Panel
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Panel1 = New System.Windows.Forms.Panel
        Me.SuspendLayout()
        '
        'Panel1
        '
        Me.Panel1.Cursor = System.Windows.Forms.Cursors.Cross
        Me.Panel1.Dock = System.Windows.Forms.DockStyle.Left
        Me.Panel1.Location = New System.Drawing.Point(0, 0)
        Me.Panel1.Name = "Panel1"
        Me.Panel1.Size = New System.Drawing.Size(544, 478)
        Me.Panel1.TabIndex = 0
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(800, 478)
        Me.Controls.Add(Me.Panel1)
        Me.Name = "Form1"
        Me.Text = "WorldEditor"
        Me.WindowState = System.Windows.Forms.FormWindowState.Maximized
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '// create window to put irrlicht in
        PanelIrr.Parent = Panel1
        PanelIrr.Size = Panel1.Size
        PanelIrr.Cursor = System.Windows.Forms.Cursors.Cross

        PanelIrr.Show()
    End Sub

    Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        PanelIrr.Hide()
    End Sub

    Private Sub Form1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
        Panel1.Size = Me.Size
        PanelIrr.Size = Panel1.Size
    End Sub

    Private Sub PanelIrr_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PanelIrr.MouseDown
        SArRoad = SArRoad + 1
        ReDim Preserve ArRoads(SArRoad)
        ArRoads(SArRoad - 1).Width = e.X
        ArRoads(SArRoad - 1).Height = e.Y

    End Sub
End Class
jerky
Posts: 12
Joined: Sun Aug 14, 2005 4:53 am

Post by jerky »

nice job, trg!

to be a bit more concise, i'll add some simple c# code.
notice that:
1) to keep Irrlicht from hogging all of your resources, run it in a different thread (see below)
2) as an interesting side note, the Dimension2D that you pass to the IrrlichtDevice has no effect on the size of the IrrlichtWindow. It will always expand to fill the panel

Code: Select all

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using Irrlicht;

namespace SimpleIrrWin
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.Panel irrPanel;
		private Thread irrThread;
		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			
			// start an irrlicht thread
			System.Threading.ThreadStart irrThreadStart = new System.Threading.ThreadStart(startIrr);
			irrThread = new System.Threading.Thread(irrThreadStart);
			irrThread.Start();
		}


		public void startIrr() {
			// this Dimension2D value can be any number!
			Irrlicht.Core.Dimension2D dim = new Irrlicht.Core.Dimension2D(0, 0);

			IrrlichtDevice device = new IrrlichtDevice(Irrlicht.Video.DriverType.DIRECTX9, 
				dim, 16, false, false, false, false, irrPanel.Handle);

			while (device.Run()) {
				if (irrPanel.Focused) {
					device.VideoDriver.BeginScene(
						true, true, new Irrlicht.Video.Color(0,000,100,100));
					device.SceneManager.DrawAll();
					device.VideoDriver.EndScene();
				}
			}
		}

		private void Form1_Closed(object sender, System.EventArgs e) {
			irrThread.Abort();
		}

		/// <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.irrPanel = new System.Windows.Forms.Panel();
			this.SuspendLayout();
			// 
			// irrPanel
			// 
			this.irrPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.irrPanel.Location = new System.Drawing.Point(40, 40);
			this.irrPanel.Name = "irrPanel";
			this.irrPanel.Size = new System.Drawing.Size(144, 120);
			this.irrPanel.TabIndex = 0;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 273);
			this.Controls.Add(this.irrPanel);
			this.Name = "Form1";
			this.Text = "Form1";
			this.Closed += new System.EventHandler(this.Form1_Closed);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}
	}
}
result
Image
Locked