Displaying Irrlicht in a c# picture box
Displaying Irrlicht in a c# picture box
Has anyone successfully displayed irrilicht within a c# picture box control? How to do it?
continuation from previous
I get an error "Color is an ambigous reference" with the following code that is inserted in the main loop:
while(device.Run())
{
if (device.WindowActive)
{
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(0xffffff), false);
device.VideoDriver.EndScene();
//display frames per second value
if (fps != device.VideoDriver.FPS)
{
fps = device.VideoDriver.FPS;
device.WindowCaption = "Scalper 2005 ["+ device.VideoDriver.Name + "] fps:" + fps;
}
}
while(device.Run())
{
if (device.WindowActive)
{
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(0xffffff), false);
device.VideoDriver.EndScene();
//display frames per second value
if (fps != device.VideoDriver.FPS)
{
fps = device.VideoDriver.FPS;
device.WindowCaption = "Scalper 2005 ["+ device.VideoDriver.Name + "] fps:" + fps;
}
}
You have to write the following when you create your device
if your picture box is named picturebox1
if your picture box is named picturebox1
Code: Select all
IrrlichtDevice device = new IrrlichtDevice(DriverType.DIRECTX9, new Dimension2D(picturebox1.Width, picturebox1.Height), 16, false, false, false, true, picturebox1.Handle
"Color is an ambigous reference" is because there is a Color class/struct in Irrlicht.Video AND System.Drawing. You need to qualify the reference with the full namespace. ie:
Code: Select all
device.VideoDriver.BeginScene(true, true, new Irrlicht.Video.Color(0,100,100,100));
I have done everything said to do here, but it doesnt compile. Here is what the compiler tells me, and the source from the application. Can someone help please?.
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();
}
}
}
}
Here's an example of Irrlicht running in a .net 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;
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(); } } } }
create a Form1 method like this
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();
Using .NET 1.1 w/ VS.NET 2003
I am using my own loop, and each iteration I call the following:
When running this in a picturebox, the cursor is stuck to the center of the picturebox, I noticed that keyboard events aren't being processed any longer, along with that setting the cursor to invisible does not work (this is irrelevant for me, but it still doesn't work nonetheless)
I was wondering if there was a way to release the cursor from the control or Irrlicht so that the user can use the cursor to navigate controls in the program, switch windows without having to alt+tab... all the things you can do with a mouse thats not stuck in the middle of the window.
I've looked through the source code, found the mouse message processing, checked icursorcontrol etc.. but I can't seem to find anything that would release the mouse cursor from the clutches of irrlicht. I'd rather not have to make my own irrlicht fork and have to update the message processing stuff with each new release.
Unless I am completely missing something (which is more probable than I'd like to think) I guess I'm asking for a feature request of the ability to turn off irrlicht's input processing so that I can process the mouse/keyboard events on my own.
Thanks
Gabriel
I am using my own loop, and each iteration I call the following:
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();
I was wondering if there was a way to release the cursor from the control or Irrlicht so that the user can use the cursor to navigate controls in the program, switch windows without having to alt+tab... all the things you can do with a mouse thats not stuck in the middle of the window.
I've looked through the source code, found the mouse message processing, checked icursorcontrol etc.. but I can't seem to find anything that would release the mouse cursor from the clutches of irrlicht. I'd rather not have to make my own irrlicht fork and have to update the message processing stuff with each new release.
Unless I am completely missing something (which is more probable than I'd like to think) I guess I'm asking for a feature request of the ability to turn off irrlicht's input processing so that I can process the mouse/keyboard events on my own.
Thanks
Gabriel