Irrlicht in a WinForm!

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.
chromdragon
Posts: 101
Joined: Wed Feb 15, 2006 4:22 pm
Location: RO

Irrlicht in a WinForm!

Post by chromdragon »

How do I integrate Irrlicht in a WinForm Apllication like a control not a separat windows!
Cube3
Posts: 30
Joined: Wed Mar 15, 2006 7:42 pm
Location: http://cube3.helpmy.net

Post by Cube3 »

Platform 3D Engine using Irrlicht.NET
http://cube3.helpmy.net
chromdragon
Posts: 101
Joined: Wed Feb 15, 2006 4:22 pm
Location: RO

Post by chromdragon »

No not working! VS Studio 2005 C# 2.0! Irrlicht 1.0!

Code: Select all

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using Irrlicht;
using Irrlicht.Video;
using Irrlicht.Core;
using Irrlicht.Scene;

namespace Program
{
    public partial class FormProgram : Form
    {
        IrrlichtDevice device;
        ITexture texLogo;
        System.Threading.Thread irrThread;

        public FormProgram()
        {
            InitializeComponent();
        }

        private void FormProgram_Load(object sender, EventArgs e)
        {
            device = new IrrlichtDevice(DriverType.OPENGL,
                new Dimension2D(pictureBox1.Width, pictureBox.Height), 16,
                false, false, false, true, pictureBox.Handle);

            irrThread = new System.Threading.Thread(new System.Threading.ThreadStart(IrrlichtInit));
            irrThread.Start();
        }

        private void FormProgram_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (irrThread != null)
                irrThread.Abort();

            if (device != null)
                device.CloseDevice();
        }

        private void IrrlichtInit()
        {
            IVideoDriver driver = device.VideoDriver;

            ITexture tex = device.VideoDriver.GetTexture(@"C:\irrlicht-1.0\engine\Data\color.tga"); 
            
            while (device.Run())
            {
                device.VideoDriver.BeginScene(true, true, new Irrlicht.Video.Color(128, 128, 0, 255));

                driver.Draw2DImage(tex, new Position2D(10, 10));
                device.SceneManager.DrawAll();

                device.VideoDriver.EndScene();
            }

        }
    }
}
Cube3
Posts: 30
Joined: Wed Mar 15, 2006 7:42 pm
Location: http://cube3.helpmy.net

Post by Cube3 »

You are initializing the device on a different thread than the render loop. There are issues with that, OPENGL will then show a black screen. Try DirectX8 or 9 and it should work, or choose to run the control + irrlicht on the same thread.
Platform 3D Engine using Irrlicht.NET
http://cube3.helpmy.net
chromdragon
Posts: 101
Joined: Wed Feb 15, 2006 4:22 pm
Location: RO

Post by chromdragon »

Code: Select all

       private void IrrlichtInit()
        {
            device = new IrrlichtDevice(DriverType.DIRECT3D9,
                new Dimension2D(pictureBox1.Width, pictureBox.Height), 16,
                false, false, false, true, pictureBox.Handle);

            driver = device.VideoDriver;
            tex = device.VideoDriver.GetTexture(@"C:\irrlicht-1.0\engine\Data\color.tga"); 

            while (device.Run())
            {
                device.VideoDriver.BeginScene(true, true, new Irrlicht.Video.Color(128, 128, 0, 255));

                // driver.Draw2DImage(tex, new Position2D(10, 10));
                // device.SceneManager.DrawAll();

                device.VideoDriver.EndScene();
            } 

        }

ERROR Window
:
Cross-thread operation not valid: Control 'pictureBox' accessed from a thread other than the thread it was created on."
Cube3
Posts: 30
Joined: Wed Mar 15, 2006 7:42 pm
Location: http://cube3.helpmy.net

Post by Cube3 »

In the constructor of your form after

Code: Select all

InitializeComponent();
Use

Code: Select all

CheckForIllegalCrossThreadCalls = false;
Platform 3D Engine using Irrlicht.NET
http://cube3.helpmy.net
chromdragon
Posts: 101
Joined: Wed Feb 15, 2006 4:22 pm
Location: RO

Post by chromdragon »

It's seems to be working even with OpenGL! BIG TKS! :mrgreen:

Code: Select all

       private void IrrlichtInit()
        {
            device = new IrrlichtDevice(DriverType.OPENGL,
                new Dimension2D(pictureBox1.Width, pictureBox.Height), 16,
                false, false, false, true, pictureBox.Handle);

            driver = device.VideoDriver;
            tex = device.VideoDriver.GetTexture(@"C:\irrlicht-1.0\engine\Data\color.tga"); 

            while (device.Run())
            {
                device.VideoDriver.BeginScene(true, true, new Irrlicht.Video.Color(128, 128, 0, 255));

                driver.Draw2DImage(tex, new Position2D(10, 10));
                device.SceneManager.DrawAll();

                device.VideoDriver.EndScene();
            } 
        }
thzero
Posts: 6
Joined: Fri Apr 14, 2006 1:29 pm

Post by thzero »

If you are running Irrlicht in another thread, you don't need to send the control across, you just need to send the control's height/width and the handle.
chromdragon
Posts: 101
Joined: Wed Feb 15, 2006 4:22 pm
Location: RO

Post by chromdragon »

It is possible to use addCameraSceneNodeMaya() or addCameraSceneNodeFPS() in a WinForm? (If yes how?)

Code: Select all

cam = device.SceneManager.AddCameraSceneNodeMaya(null, -250, 100, 100, -1);
thzero
Posts: 6
Joined: Fri Apr 14, 2006 1:29 pm

Post by thzero »

chromdragon wrote:It is possible to use addCameraSceneNodeMaya() or addCameraSceneNodeFPS() in a WinForm? (If yes how?)

Code: Select all

cam = device.SceneManager.AddCameraSceneNodeMaya(null, -250, 100, 100, -1);
Sure, they work as intended, but they do take over your control device. If you want to use a Window dialog or such with it, then you'd have to set the ActiveCamera's HasControl (sorry, don't have the exact method right now as my dev PC is not fully functional right now) property to false. Then when you leave the dialog you can set it back to true.
chromdragon
Posts: 101
Joined: Wed Feb 15, 2006 4:22 pm
Location: RO

Post by chromdragon »

Here is the online documentation. I can't find anything in the ICameraSceneNode class.

Irrlicht Doc: http://irrlicht.sourceforge.net/docu/index.html
Irrlicht .Net Doc: http://irrlicht.sourceforge.net/docu.net/index.html
G-ray
Posts: 5
Joined: Sat Nov 12, 2005 6:27 am
Location: Russia

Post by G-ray »

up
The spice must flow!
chromdragon
Posts: 101
Joined: Wed Feb 15, 2006 4:22 pm
Location: RO

Post by chromdragon »

help help!
thzero
Posts: 6
Joined: Fri Apr 14, 2006 1:29 pm

Post by thzero »

In the scenemanager object there is an ActiveCamera property which has an InputReceiverEnabled property. Set the InputReceiverEnabled to false when you want to regain input control from Irrlicht and set it to true when you want Irrlicht to take over again.
chromdragon
Posts: 101
Joined: Wed Feb 15, 2006 4:22 pm
Location: RO

Post by chromdragon »

Found! Tks I will try it later.
Locked