image

In this tutorial you will learn:

  • How to create a new project which uses Irrlicht.Net
  • Create a device
  • Set the window caption
  • Add some text
  • Load an animated 3D model and adding it to the scene
  • Draw the scene

 

Getting started

First of we will start Visual Studio 2010, or in this case Visual C# 2010 Express. Click the button saying New Project… Once you click it, a dialog widow will popup, looking something like this:

image

Select Console Application, and choose a name. Once you are done click the button saying OK

image

In the Solution Explorer, right click on References and select Add Reference… Find Irrlicht.Net.dll, select it and then click OK

Now add Irrlicht.dll and IrrlichtW.dll, these are written in C++ and can not b added as  a reference, so lets add it as an item, right click on your project and select Add->Add Existing Item… Find the Dll’s, select them both (Hold down CTRL, and click them), then click the button saying Add.

(Don’t forget to add the 3D model you want to load, and it’s textures. http://irrlicht.sourceforge.net/ has some nice media.)

image

Select Irrlicht.dll, IrrlichtW.dll and an eventual 3D model with it’s textures.

Find a tab saying properties, or press Alt+Enter, while they are selected.

Set Build Action to None, and Copy to Output Directory to Copy if Newer

 

Coding

Once you create your project, a new code file, named Program.cs, is automatically added.

The file should look something like this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Tutorial1
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }
}

To start with we will need to add a few namespaces;

using Irrlicht.Net;
using Irrlicht.Net.Core;
using Irrlicht.Net.GUI;
using Irrlicht.Net.IO;
using Irrlicht.Net.Scene;
using Irrlicht.Net.Video;

Also we need to add some code to create the Device:

Device device = new Device(DriverTypes.OpenGL, new Dimension2D(640, 480), false);

You may explore this function, anything you do to it, will not have any effect on this tutorial, for example: Create a Device that is using Burnings Video, running full screen, at the resolution 1024x768

 

Lets add a shortcut to the VideoDriver, SceneManager and GUIEnvironment:

VideoDriver driver = device.VideoDriver;
SceneManager scene = device.SceneManager;
GUIEnvironment gui = device.GUIEnvironment;

Set the window caption:

device.WindowCaption = "Tutorial 1 - Hello World!";

Lets add a StaticText:

StaticText text = gui.AddStaticText("Hello World!", new Rectangle<int>(10, 10, 250, 22), true);

 

Loading an animated 3D model, with textures and animation, is a bit more advanced than just adding text or anything similar. But I think you will get the hang of it quite fast.

Lets begin with loading our AnimatedMesh:

AnimatedMesh mesh = scene.GetMesh("faerie.md2"); 

Then lets add it to the scene:

AnimatedMeshSceneNode node = scene.AddAnimatedMeshSceneNode(mesh);

Before we can see it we must turn of the lighting for our model, because we do not have any lights in the scene:

node.SetMaterialFlag(MaterialFlags.Lightning, false);

To make the model look more real, lets set the texture:

node.SetMaterialTexture(0, driver.GetTexture("faerie2.bmp"));

If you loaded a .md2 mesh, you might want to set the animation:

node.Animation = AnimationTypes.Stand;

That is everything you have to do to add an animated model to the scene.

 

Lets add a camera to our scene:

scene.AddCameraSceneNodeFPS();

 

Now lets draw everything:

while(device.Run())
{
    driver.BeginScene(true, true, new Color(255, 100, 101, 140));
    scene.DrawAll();
    gui.DrawAll();
    driver.EndScene();
}

 

Just before we are done, lets dispose the device:

device.Dispose();

 

Now, press F5 to run the application. It should look something like the image above.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Irrlicht.Net;
using Irrlicht.Net.Core;
using Irrlicht.Net.GUI;
using Irrlicht.Net.IO;
using Irrlicht.Net.Scene;
using Irrlicht.Net.Video;

namespace Tutorial1
{
    class Program
    {
        static void Main(string[] args)
        {
            Device device = new Device(DriverTypes.OpenGL, new Dimension2D(640, 480), false);
            VideoDriver driver = device.VideoDriver;
            SceneManager scene = device.SceneManager;
            GUIEnvironment gui = device.GUIEnvironment;

            device.WindowCaption = "Tutorial 1 - Hello World!";

            StaticText text = gui.AddStaticText("Hello World!", new Rectangle<int>(10, 10, 250, 22), true);

            AnimatedMesh mesh = scene.GetMesh("faerie.md2");
            AnimatedMeshSceneNode node = scene.AddAnimatedMeshSceneNode(mesh);
            node.SetMaterialFlag(MaterialFlags.Lightning, false);
            node.SetMaterialTexture(0, driver.GetTexture("faerie2.bmp"));
            node.Animation = AnimationTypes.Stand;

            scene.AddCameraSceneNodeFPS();

            while(device.Run())
            {
                driver.BeginScene(true, true, new Color(255, 100, 101, 140));
                scene.DrawAll();
                gui.DrawAll();
                driver.EndScene();
            }
            device.Dispose();
        }
    }
}

If you have any problem with the tutorials, please do not hesitate to ask Ler

Last edited Feb 7, 2011 at 12:28 PM by Mattan360, version 4

Comments

Memorix101 Sep 11, 2012 at 4:02 PM 
Why doesn't work this in Ubuntu with MonoDevelop ..... I get this error .... Irrlicht.Net.Device..ctor (driverType=Irrlicht.Net.Video.DriverTypes.Software, dimensions={Irrlicht.Net.Core.Dimension2D}, fullscreen=false) in

ahmadbanat Aug 22, 2011 at 6:26 PM 
How to load a model and the textures? I don't know how to do this. Sorry am a noob in 3D Gaming. Please help

thoqbk May 10, 2011 at 5:08 PM 
Plz be give me some little feedback about it. thx

thoqbk May 10, 2011 at 5:07 PM 
Hi,

is it true that not all of the Irrlicht.dll is implemented in yours at the moment?
For some months, I have found the IrrlichtNETCP and yeah the version of the supported irrlicht is 1.3 or 1.5? dunno.
Now on the weekend I have rub my eyes and see your nice Irrlicht Wrapper for C# and .NET. WOW

And today I have implements it and have to refactor my old IrrlichtNETCP project but one thing is not all of the functions can I use like these things, that i need. I know it is a alpha or beta and I really hope that you will implement the most or all of the functionality. Here are the list with some things, that doesnt work. Hope you will implement it or show me an alternative.

Color.Blue (static) alternative = new Color(a, r, g, b)
Draw3DLine() method
new Triangle3D() ctor
MaterialType. static (Types are DetailMap, Paralax?)
Device Anything; Anything.FileSystem.WorkingDirectory (Dir for the mediafiles)
SceneManager RootSceneNode
SceneNode SetMaterialType() Method
AddMeshSceneNode() Method
AddSphereSceneNode() Method
Animator objectName
CreateFlyStraightAnimator() Method
Material objectName
Logger
CursorControl
SetMaterial() Method (VideDriver)
TriangleSelector objectName
SetTransform() Method (VideoDriver)
TransformationState.World... static (staticObject)
CreateTriangleSelector
AbsolutePosition.DistanceFrom() SceneNode Method
TransformedBoundingBox SceneNode Property

Thats all at the moment
Many many Regards and great work

npro1234 May 7, 2011 at 7:41 AM 
Very nice, thanks very much. I'm so glad it's Visual Studio 2010 also :)

Alex_d7 Apr 21, 2011 at 7:11 AM 
Nice, nice!

Is lighting implemented?

Wolfae Apr 3, 2011 at 10:02 PM 
Hello.
I really appreciate the kind work you've done by providing this tutorial. It helped me quite a lot.
But, I <beg> you, to make a tutorial about positioning/rotating meshes in a scene... Also using terrains.
Thanks!
~Wolfae

only1skingle Mar 9, 2011 at 5:24 PM 
No worries, I now have it working. I was using Visual Studio 2008 instead of 2010. I used 2010 and now it's working ^_^

iksi99 - My camera is within the model too, but u can move the camera out of the model on the program has started by pressing down the 'down arrow' key.

only1skingle Mar 9, 2011 at 5:03 PM 
Hey all, I'm having a problem with this tutorial, When i reference the Irrlicht.net dll file it inserts in visual studio, but a yellow triangle with a black '!' appears and so the program doesn't register Irrlicht at all.

Any advice???

iksi99 Mar 3, 2011 at 8:38 PM 
I have a camera problem. My camera is at the same coordinates as the model, so I can't see the whole model. I tried copying and pasting the code and it didn't help. Any ideas?

CYannick Feb 15, 2011 at 8:37 PM 
Hi and big thanks for this fantastic wrapper.

I hope more tutorials and updates will come later.

vmakar Feb 15, 2011 at 10:00 AM 
Hi, sorry for my English =p

Really appreciate what you have done so much work, I tried to compile your tutorial, I really enjoyed it.

I would like to share my little experience. in the project settings, tab application - put the type of output -> "application windows"
In this case, the console window is not displayed when you start the software.