Displaying Irrlicht in a c# picture box
Posted: Mon Oct 17, 2005 4:37 pm
Has anyone successfully displayed irrilicht within a c# picture box control? How to do it?
Official forum of the Irrlicht Engine
https://irrlicht.sourceforge.io/forum/
Code: Select all
IrrlichtDevice device = new IrrlichtDevice(DriverType.DIRECTX9, new Dimension2D(picturebox1.Width, picturebox1.Height), 16, false, false, false, true, picturebox1.Handle
Code: Select all
device.VideoDriver.BeginScene(true, true, new Irrlicht.Video.Color(0,100,100,100));
C:\Development\Projects\irrDOTNet\Form1.cs(91): 'irrDOTNet.Form1.pictureBox1' denotes a 'field' where a 'class' was expected
C:\Development\Projects\irrDOTNet\Form1.cs(91): 'irrDOTNet.Form1.pictureBox1' denotes a 'field' where a 'class' was expected
C:\Development\Projects\irrDOTNet\Form1.cs(91): 'irrDOTNet.Form1.pictureBox1' denotes a 'field' where a 'class' was expected
C:\Development\Projects\irrDOTNet\Form1.cs(94): 'Irrlicht.Video.Color' denotes a 'class' which is not valid in the given context
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 irrDOTNet
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.PictureBox pictureBox1;
/// <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.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.BackColor = System.Drawing.SystemColors.ControlDark;
this.pictureBox1.Location = new System.Drawing.Point(48, 24);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(216, 208);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 271);
this.Controls.Add(this.pictureBox1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
IrrlichtDevice device = new IrrlichtDevice(DriverType.DIRECTX9, new Dimension2D(pictureBox1.Width, pictureBox1.Height), 16, false, false, false, true, pictureBox1.Handle);
while(device.Run())
{
device.VideoDriver.BeginScene(true,true,Irrlicht.Video.Color(128,128,0,255));
device.SceneManager.DrawAll();
device.VideoDriver.EndScene();
}
}
}
}
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;
using Irrlicht.Video;
using Irrlicht.Core;
using Irrlicht.Scene;
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; //prevent Irrlicht from hogging all of your resources...run it in a different thread
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);
//load some textures
ITexture texSydney = device.VideoDriver.GetTexture(@"..\..\media\sydney.bmp");
ITexture texWall = device.VideoDriver.GetTexture(@"..\..\media\wall.bmp");
ITexture texLogo = device.VideoDriver.GetTexture(@"..\..\media\irrlichtlogoaligned.jpg");
// load the animated mesh of sydney
Irrlicht.Scene.IAnimatedMesh mesh = device.SceneManager.GetMesh(@"..\..\media\sydney.md2");
if (mesh == null)
{
System.Windows.Forms.MessageBox.Show(@"Could not load mesh ..\..\media\sydney.md2, exiting.","Problem starting program");
return;
}
// add a camera, a test scene node and the animated mesh to the scene
ICameraSceneNode cam = device.SceneManager.AddCameraSceneNodeFPS(null, 100, 100, -1);
cam.Position = new Vector3D(20,0,-50);
ISceneNode node = device.SceneManager.AddTestSceneNode(15, null, -1, new Vector3D(30,-15,0));
node.SetMaterialTexture(0, texWall);
node = device.SceneManager.AddAnimatedMeshSceneNode(mesh, null, -1);
node.SetMaterialTexture(0, texSydney);
node.SetMaterialFlag(MaterialFlag.LIGHTING, false);
// make cursor invisible
device.CursorControl.Visible = false;
while (device.Run())
{
if (irrPanel.Focused)
{
device.VideoDriver.BeginScene(true, true, new Irrlicht.Video.Color(0,150,150,125));
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.BackColor = System.Drawing.SystemColors.ControlDark;
this.irrPanel.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.irrPanel.Location = new System.Drawing.Point(24, 16);
this.irrPanel.Name = "irrPanel";
this.irrPanel.Size = new System.Drawing.Size(584, 408);
this.irrPanel.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(632, 446);
this.Controls.Add(this.irrPanel);
this.Name = "Form1";
this.Text = "Irrlicht in a Window";
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());
}
}
}
You are trying to access pictureBox1 control (that is non-static) from a static function (main)Code: Select all
[STAThread] static void Main() { Application.Run(new Form1()); IrrlichtDevice device = new IrrlichtDevice(DriverType.DIRECTX9, new Dimension2D(pictureBox1.Width, pictureBox1.Height), 16, false, false, false, true, pictureBox1.Handle); while(device.Run()) { device.VideoDriver.BeginScene(true,true,Irrlicht.Video.Color(128,128,0,255)); device.SceneManager.DrawAll(); device.VideoDriver.EndScene(); } } } }
Code: Select all
public void Init()
{
IrrlichtDevice device = new IrrlichtDevice(DriverType.DIRECTX9, new Dimension2D(pictureBox1.Width, pictureBox1.Height), 16, false, false, false, true, pictureBox1.Handle);
while(device.Run())
{
device.VideoDriver.BeginScene(true,true,Irrlicht.Video.Color(128,128,0,255));
device.SceneManager.DrawAll();
device.VideoDriver.EndScene();
}
}
Code: Select all
irrThread = new System.Threading.Thread(new System.Threading.ThreadStart(Init));
irrThread.Start();
Code: Select all
device.Timer.Tick();
device.VideoDriver.BeginScene(true,true, new Irrlicht.Video.Color(128,128,128,128));
device.SceneManager.DrawAll();
device.VideoDriver.EndScene();