Meshviewer using DeusXL's Irr.NET CP

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
sh1ny
Posts: 21
Joined: Mon Jul 17, 2006 6:21 pm

Meshviewer using DeusXL's Irr.NET CP

Post by sh1ny »

Hello. Im new here and not very experienced in both C# and irrlicht, but i decided for a start that i should try and use DeusXL's Irr.NET CP ( due to obvious advantages over the current NET wrapper of Irrlicht ) and i started out with converting the examples and trying to learn what is what :). So far i didnt have any problems , untill i tryed the Meshviewer. It compiles fine but i get an error at startup :

Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "_09.WinFormMeshViewer.MainForm.resources" was correctly embedded or linked into assembly "Meshviewer_NET" at compile timem, or that all the satelite assemblies required are loadable and fully signed.

And here is the code :

Code: Select all


/* 

* This tutorial covers creating a mesh viewer.
*
* It is similar to the native tutorial, but different.
* Since much of the gui and xml stuff is not in the
* .NET wrapper yet, I decided to use winforms and
* the .NET xml mush for those portions of the tutorial.
*
* Some of this tutorial is based on the work Braneloc did
* on Tutorial 14.
*
* The tutorial also includes some other interesting stuff
* that I decided to play with.
*
* For instance, you can change the driver in the middle of
* looking at a mesh.
* Since I used .net 2.0 & VS2005, you can also move the
* toolbar around the form.  (A new freebe in .net 2.0)
*
* DISCLAIMERS:  This will not work with .net 1.1.
* The reason is that some of the controls I used in this
* tutorial are not available in .net 1.1.
* Most of the controls that I know have changed are the
* menu and toolbar stuff.
* The new stuff now has names like "MenuStrip",
* "ToolStrip", and "ToolStripMenuItem", etc.
* Seems kinda silly, I know, but I'm sure someone over
* in Redmond really thought they had a great idea.
*
* Also, MS changed their xml api in .net 2.0.
* The xml part of the tutorial might port to .net 1.1
* just fine, but I'm not sure and not ambitious enough
* to check it out myself.
*
* BUGS:  Yeah, I'm sure there's a few in there.
* I notice when switching drivers, the app will
* sometimes lock.  I haven't quite figured out why yet,
* but it seems to have something to do with Irrlicht
* having a null device.EventReceiver.  Also, the
* debugger will sometimes point to a problem with fonts
* in this case.
*
* The winforms event responses are very doggy.
* I tried a couple of Application.DoEvents() in the render loop,
* but they didn't seem to help much.  I may
* look at this in the future.
*
* FINAL NOTE:  If you happen to find any fixes for any of the
* bugs listed above or any new ones you find, share them with
* the community.  Post about them on the forum, and update
* the Wiki.
*
* Getting it working: 
* Create project as windows form, and add the 2 Irrlicht DLL's to it.
* (This file is the only one needed in the project)
* Add open.bmp and help.bmp from the Irrlicht media directory to the
* resources.
* You'll probably need to rebind the images to the toolstrip, hint,
* open is the one on the left..
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Text;
using System.IO;
using System.Xml;
using Irrlicht.NET;
using core = Irrlicht.NET;
using scene = Irrlicht.NET;
using video = Irrlicht.NET;
using gui = Irrlicht.NET;

namespace _09.WinFormMeshViewer
{

    /// <summary>
    /// Description of MainForm.
    /// </summary>
    public class MainForm : System.Windows.Forms.Form
    {
        // Path from tutorial binary to standard SDK media folder.
        private string path = "../../media/";
        private string messageText = string.Empty;
        private string caption = string.Empty;
        private string captBase = "Irrlicht.NET with WinForms - MeshViewer";
        private string configFile = "config.xml";
        private string startupModelFile = string.Empty;
        private string currentModelFile = string.Empty;
        private bool quitting = false;
        private bool paused = false;
        private IrrlichtDevice device;
        private scene.AnimatedMeshSceneNode model;
        private scene.SceneNode skyBox;
        private video.Texture irrLogo;
        private System.Windows.Forms.Timer startDelay;
        private Panel pnlIrrlicht;
        private Rectangle panelMemory = Rectangle.Empty;	// Remembers the size & location of the panel

        private ToolStripMenuItem mnuFile;
        private ToolStripMenuItem mnuFileOpen;
        private ToolStripSeparator toolStripMenuItem1;
        private ToolStripMenuItem mnuFileExit;
        private ToolStripMenuItem mnuView;
        private ToolStripMenuItem mnuHelp;
        private ToolStripContainer toolStripContainer1;
        private ToolStrip toolStrip1;
        private ToolStripButton btnOpen;
        private ToolStripButton btnHelp;
        private ToolStripMenuItem mnuViewSkyBox;
        private ToolStripMenuItem mnuViewDebug;
        private ToolStripMenuItem mnuViewMaterial;
        private ToolStripMenuItem mnuViewMatSolid;
        private ToolStripMenuItem mnuViewMatTransp;
        private ToolStripMenuItem mnuViewMatReflect;
        private ToolStripMenuItem mnuHelpAbout;
        private Label lblScaleZ;
        private NumericUpDown numScaleZ;
        private Label lblScaleY;
        private NumericUpDown numScaleY;
        private Label lblScaleX;
        private NumericUpDown numScaleX;
        private CheckBox chkDebug;
        private CheckBox chkSkyBox;
        private RadioButton rbSoft1;
        private RadioButton rbOGL;
        private RadioButton rbD3D8;
        private RadioButton rbD3D9;
        private RadioButton rbNull;
        private RadioButton rbSoft2;
        private GroupBox gbDrivers;
        private ToolStripTextBox txtFPS;
        private MenuStrip mnuMain;

        public MainForm()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();

            //
            // Add constructor code after the InitializeComponent() call.
            //
            startDelay = new System.Windows.Forms.Timer();
            startDelay.Interval = 1000;
            startDelay.Enabled = false;
            startDelay.Tick += new EventHandler(startDelay_Tick);
            CreatePanel();
        }

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            try
            {
                // Create a new instance of our application
                MainForm viewer = new MainForm();

                //Show the window
                viewer.Show();

                // Initialize items
                viewer.LoadIrrConfig();
                if (viewer.startupModelFile == string.Empty) viewer.startupModelFile = "dwarf.x";
                viewer.currentModelFile = viewer.startupModelFile;
                viewer.SetDevice(viewer.pnlIrrlicht, viewer.PickDriver());
                viewer.LoadModel(viewer.path + viewer.currentModelFile);
                viewer.LoadSkyBox();

                // Run the viewer
                System.Windows.Forms.Application.Run(viewer);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Application.Exit();
                GC.Collect();
            }

        }

        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Forms Designer generated code
        /// <summary>
        /// This method is required for Windows Forms designer support.
        /// Do not change the method contents inside the source code editor. The Forms designer might
        /// not be able to load this method if it was changed manually.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
            this.mnuMain = new System.Windows.Forms.MenuStrip();
            this.mnuFile = new System.Windows.Forms.ToolStripMenuItem();
            this.mnuFileOpen = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
            this.mnuFileExit = new System.Windows.Forms.ToolStripMenuItem();
            this.mnuView = new System.Windows.Forms.ToolStripMenuItem();
            this.mnuViewSkyBox = new System.Windows.Forms.ToolStripMenuItem();
            this.mnuViewDebug = new System.Windows.Forms.ToolStripMenuItem();
            this.mnuViewMaterial = new System.Windows.Forms.ToolStripMenuItem();
            this.mnuViewMatSolid = new System.Windows.Forms.ToolStripMenuItem();
            this.mnuViewMatTransp = new System.Windows.Forms.ToolStripMenuItem();
            this.mnuViewMatReflect = new System.Windows.Forms.ToolStripMenuItem();
            this.mnuHelp = new System.Windows.Forms.ToolStripMenuItem();
            this.mnuHelpAbout = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripContainer1 = new System.Windows.Forms.ToolStripContainer();
            this.gbDrivers = new System.Windows.Forms.GroupBox();
            this.rbNull = new System.Windows.Forms.RadioButton();
            this.rbD3D9 = new System.Windows.Forms.RadioButton();
            this.rbSoft2 = new System.Windows.Forms.RadioButton();
            this.rbD3D8 = new System.Windows.Forms.RadioButton();
            this.rbSoft1 = new System.Windows.Forms.RadioButton();
            this.rbOGL = new System.Windows.Forms.RadioButton();
            this.chkDebug = new System.Windows.Forms.CheckBox();
            this.chkSkyBox = new System.Windows.Forms.CheckBox();
            this.lblScaleZ = new System.Windows.Forms.Label();
            this.numScaleZ = new System.Windows.Forms.NumericUpDown();
            this.lblScaleY = new System.Windows.Forms.Label();
            this.numScaleY = new System.Windows.Forms.NumericUpDown();
            this.lblScaleX = new System.Windows.Forms.Label();
            this.numScaleX = new System.Windows.Forms.NumericUpDown();
            this.toolStrip1 = new System.Windows.Forms.ToolStrip();
            this.btnOpen = new System.Windows.Forms.ToolStripButton();
            this.btnHelp = new System.Windows.Forms.ToolStripButton();
            this.txtFPS = new System.Windows.Forms.ToolStripTextBox();
            this.mnuMain.SuspendLayout();
            this.toolStripContainer1.ContentPanel.SuspendLayout();
            this.toolStripContainer1.TopToolStripPanel.SuspendLayout();
            this.toolStripContainer1.SuspendLayout();
            this.gbDrivers.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.numScaleZ)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.numScaleY)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.numScaleX)).BeginInit();
            this.toolStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // mnuMain
            // 
            this.mnuMain.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
																					 this.mnuFile,
																					 this.mnuView,
																					 this.mnuHelp});
            this.mnuMain.Location = new System.Drawing.Point(0, 0);
            this.mnuMain.Name = "mnuMain";
            this.mnuMain.Size = new System.Drawing.Size(632, 24);
            this.mnuMain.TabIndex = 0;
            this.mnuMain.Text = "menuStrip1";
            // 
            // mnuFile
            // 
            this.mnuFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
																							 this.mnuFileOpen,
																							 this.toolStripMenuItem1,
																							 this.mnuFileExit});
            this.mnuFile.Name = "mnuFile";
            this.mnuFile.Size = new System.Drawing.Size(35, 20);
            this.mnuFile.Text = "&File";
            // 
            // mnuFileOpen
            // 
            this.mnuFileOpen.Name = "mnuFileOpen";
            this.mnuFileOpen.Size = new System.Drawing.Size(139, 22);
            this.mnuFileOpen.Text = "&Open Mesh";
            this.mnuFileOpen.Click += new System.EventHandler(this.open_Click);
            // 
            // toolStripMenuItem1
            // 
            this.toolStripMenuItem1.Name = "toolStripMenuItem1";
            this.toolStripMenuItem1.Size = new System.Drawing.Size(136, 6);
            // 
            // mnuFileExit
            // 
            this.mnuFileExit.Name = "mnuFileExit";
            this.mnuFileExit.Size = new System.Drawing.Size(139, 22);
            this.mnuFileExit.Text = "E&xit";
            this.mnuFileExit.Click += new System.EventHandler(this.Exit_Click);
            // 
            // mnuView
            // 
            this.mnuView.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
																							 this.mnuViewSkyBox,
																							 this.mnuViewDebug,
																							 this.mnuViewMaterial});
            this.mnuView.Name = "mnuView";
            this.mnuView.Size = new System.Drawing.Size(41, 20);
            this.mnuView.Text = "&View";
            // 
            // mnuViewSkyBox
            // 
            this.mnuViewSkyBox.Checked = true;
            this.mnuViewSkyBox.CheckOnClick = true;
            this.mnuViewSkyBox.CheckState = System.Windows.Forms.CheckState.Checked;
            this.mnuViewSkyBox.Name = "mnuViewSkyBox";
            this.mnuViewSkyBox.Size = new System.Drawing.Size(170, 22);
            this.mnuViewSkyBox.Text = "&SkyBox Visibility";
            this.mnuViewSkyBox.CheckedChanged += new System.EventHandler(this.SkyBox_CheckedChanged);
            // 
            // mnuViewDebug
            // 
            this.mnuViewDebug.Checked = true;
            this.mnuViewDebug.CheckOnClick = true;
            this.mnuViewDebug.CheckState = System.Windows.Forms.CheckState.Checked;
            this.mnuViewDebug.Name = "mnuViewDebug";
            this.mnuViewDebug.Size = new System.Drawing.Size(170, 22);
            this.mnuViewDebug.Text = "Model &Debug Info";
            this.mnuViewDebug.CheckedChanged += new System.EventHandler(this.Debug_CheckedChanged);
            // 
            // mnuViewMaterial
            // 
            this.mnuViewMaterial.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
																									 this.mnuViewMatSolid,
																									 this.mnuViewMatTransp,
																									 this.mnuViewMatReflect});
            this.mnuViewMaterial.Name = "mnuViewMaterial";
            this.mnuViewMaterial.Size = new System.Drawing.Size(170, 22);
            this.mnuViewMaterial.Text = "&Model Material";
            // 
            // mnuViewMatSolid
            // 
            this.mnuViewMatSolid.Checked = true;
            this.mnuViewMatSolid.CheckState = System.Windows.Forms.CheckState.Checked;
            this.mnuViewMatSolid.Name = "mnuViewMatSolid";
            this.mnuViewMatSolid.Size = new System.Drawing.Size(144, 22);
            this.mnuViewMatSolid.Text = "S&olid";
            this.mnuViewMatSolid.Click += new System.EventHandler(this.mnuViewMatSolid_Click);
            // 
            // mnuViewMatTransp
            // 
            this.mnuViewMatTransp.Name = "mnuViewMatTransp";
            this.mnuViewMatTransp.Size = new System.Drawing.Size(144, 22);
            this.mnuViewMatTransp.Text = "&Transparent";
            this.mnuViewMatTransp.Click += new System.EventHandler(this.mnuViewMatTransp_Click);
            // 
            // mnuViewMatReflect
            // 
            this.mnuViewMatReflect.Name = "mnuViewMatReflect";
            this.mnuViewMatReflect.Size = new System.Drawing.Size(144, 22);
            this.mnuViewMatReflect.Text = "Reflection";
            this.mnuViewMatReflect.Click += new System.EventHandler(this.mnuViewMatReflect_Click);
            // 
            // mnuHelp
            // 
            this.mnuHelp.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
																							 this.mnuHelpAbout});
            this.mnuHelp.Name = "mnuHelp";
            this.mnuHelp.Size = new System.Drawing.Size(40, 20);
            this.mnuHelp.Text = "&Help";
            // 
            // mnuHelpAbout
            // 
            this.mnuHelpAbout.Name = "mnuHelpAbout";
            this.mnuHelpAbout.Size = new System.Drawing.Size(114, 22);
            this.mnuHelpAbout.Text = "&About";
            this.mnuHelpAbout.Click += new System.EventHandler(this.Help_Click);
            // 
            // toolStripContainer1
            // 
            // 
            // toolStripContainer1.ContentPanel
            // 
            this.toolStripContainer1.ContentPanel.Controls.Add(this.gbDrivers);
            this.toolStripContainer1.ContentPanel.Controls.Add(this.chkDebug);
            this.toolStripContainer1.ContentPanel.Controls.Add(this.chkSkyBox);
            this.toolStripContainer1.ContentPanel.Controls.Add(this.lblScaleZ);
            this.toolStripContainer1.ContentPanel.Controls.Add(this.numScaleZ);
            this.toolStripContainer1.ContentPanel.Controls.Add(this.lblScaleY);
            this.toolStripContainer1.ContentPanel.Controls.Add(this.numScaleY);
            this.toolStripContainer1.ContentPanel.Controls.Add(this.lblScaleX);
            this.toolStripContainer1.ContentPanel.Controls.Add(this.numScaleX);
            this.toolStripContainer1.ContentPanel.Size = new System.Drawing.Size(632, 397);
            this.toolStripContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.toolStripContainer1.Location = new System.Drawing.Point(0, 24);
            this.toolStripContainer1.Name = "toolStripContainer1";
            this.toolStripContainer1.Size = new System.Drawing.Size(632, 422);
            this.toolStripContainer1.TabIndex = 1;
            this.toolStripContainer1.Text = "toolStripContainer1";
            // 
            // toolStripContainer1.TopToolStripPanel
            // 
            this.toolStripContainer1.TopToolStripPanel.Controls.Add(this.toolStrip1);
            // 
            // gbDrivers
            // 
            this.gbDrivers.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.gbDrivers.Controls.Add(this.rbNull);
            this.gbDrivers.Controls.Add(this.rbD3D9);
            this.gbDrivers.Controls.Add(this.rbSoft2);
            this.gbDrivers.Controls.Add(this.rbD3D8);
            this.gbDrivers.Controls.Add(this.rbSoft1);
            this.gbDrivers.Controls.Add(this.rbOGL);
            this.gbDrivers.Location = new System.Drawing.Point(510, 223);
            this.gbDrivers.Name = "gbDrivers";
            this.gbDrivers.Size = new System.Drawing.Size(104, 162);
            this.gbDrivers.TabIndex = 15;
            this.gbDrivers.TabStop = false;
            this.gbDrivers.Text = "Driver Selection:";
            // 
            // rbNull
            // 
            this.rbNull.AutoSize = true;
            this.rbNull.Location = new System.Drawing.Point(6, 134);
            this.rbNull.Name = "rbNull";
            this.rbNull.Size = new System.Drawing.Size(72, 17);
            this.rbNull.TabIndex = 14;
            this.rbNull.TabStop = true;
            this.rbNull.Text = "null Driver";
            this.rbNull.UseVisualStyleBackColor = true;
            this.rbNull.CheckedChanged += new System.EventHandler(this.rb_CheckedChanged);
            // 
            // rbD3D9
            // 
            this.rbD3D9.AutoSize = true;
            this.rbD3D9.Checked = true;
            this.rbD3D9.Location = new System.Drawing.Point(6, 19);
            this.rbD3D9.Name = "rbD3D9";
            this.rbD3D9.Size = new System.Drawing.Size(91, 17);
            this.rbD3D9.TabIndex = 9;
            this.rbD3D9.TabStop = true;
            this.rbD3D9.Text = "Direct3D 9.0c";
            this.rbD3D9.UseVisualStyleBackColor = true;
            this.rbD3D9.CheckedChanged += new System.EventHandler(this.rb_CheckedChanged);
            // 
            // rbSoft2
            // 
            this.rbSoft2.AutoSize = true;
            this.rbSoft2.Location = new System.Drawing.Point(6, 111);
            this.rbSoft2.Name = "rbSoft2";
            this.rbSoft2.Size = new System.Drawing.Size(75, 17);
            this.rbSoft2.TabIndex = 13;
            this.rbSoft2.TabStop = true;
            this.rbSoft2.Text = "Apfelbaum";
            this.rbSoft2.UseVisualStyleBackColor = true;
            this.rbSoft2.CheckedChanged += new System.EventHandler(this.rb_CheckedChanged);
            // 
            // rbD3D8
            // 
            this.rbD3D8.AutoSize = true;
            this.rbD3D8.Location = new System.Drawing.Point(6, 42);
            this.rbD3D8.Name = "rbD3D8";
            this.rbD3D8.Size = new System.Drawing.Size(85, 17);
            this.rbD3D8.TabIndex = 10;
            this.rbD3D8.TabStop = true;
            this.rbD3D8.Text = "Direct3D 8.1";
            this.rbD3D8.UseVisualStyleBackColor = true;
            this.rbD3D8.CheckedChanged += new System.EventHandler(this.rb_CheckedChanged);
            // 
            // rbSoft1
            // 
            this.rbSoft1.AutoSize = true;
            this.rbSoft1.Location = new System.Drawing.Point(6, 88);
            this.rbSoft1.Name = "rbSoft1";
            this.rbSoft1.Size = new System.Drawing.Size(67, 17);
            this.rbSoft1.TabIndex = 12;
            this.rbSoft1.TabStop = true;
            this.rbSoft1.Text = "Software";
            this.rbSoft1.UseVisualStyleBackColor = true;
            this.rbSoft1.CheckedChanged += new System.EventHandler(this.rb_CheckedChanged);
            // 
            // rbOGL
            // 
            this.rbOGL.AutoSize = true;
            this.rbOGL.Location = new System.Drawing.Point(6, 65);
            this.rbOGL.Name = "rbOGL";
            this.rbOGL.Size = new System.Drawing.Size(83, 17);
            this.rbOGL.TabIndex = 11;
            this.rbOGL.TabStop = true;
            this.rbOGL.Text = "OpenGL 1.5";
            this.rbOGL.UseVisualStyleBackColor = true;
            this.rbOGL.CheckedChanged += new System.EventHandler(this.rb_CheckedChanged);
            // 
            // chkDebug
            // 
            this.chkDebug.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.chkDebug.AutoSize = true;
            this.chkDebug.Checked = true;
            this.chkDebug.CheckState = System.Windows.Forms.CheckState.Checked;
            this.chkDebug.Location = new System.Drawing.Point(510, 193);
            this.chkDebug.Name = "chkDebug";
            this.chkDebug.Size = new System.Drawing.Size(113, 17);
            this.chkDebug.TabIndex = 8;
            this.chkDebug.Text = "Debug Information";
            this.chkDebug.UseVisualStyleBackColor = true;
            this.chkDebug.CheckedChanged += new System.EventHandler(this.Debug_CheckedChanged);
            // 
            // chkSkyBox
            // 
            this.chkSkyBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.chkSkyBox.AutoSize = true;
            this.chkSkyBox.Checked = true;
            this.chkSkyBox.CheckState = System.Windows.Forms.CheckState.Checked;
            this.chkSkyBox.Location = new System.Drawing.Point(510, 170);
            this.chkSkyBox.Name = "chkSkyBox";
            this.chkSkyBox.Size = new System.Drawing.Size(101, 17);
            this.chkSkyBox.TabIndex = 7;
            this.chkSkyBox.Text = "SkyBox Visibility";
            this.chkSkyBox.UseVisualStyleBackColor = true;
            this.chkSkyBox.CheckedChanged += new System.EventHandler(this.SkyBox_CheckedChanged);
            // 
            // lblScaleZ
            // 
            this.lblScaleZ.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.lblScaleZ.AutoSize = true;
            this.lblScaleZ.Location = new System.Drawing.Point(510, 116);
            this.lblScaleZ.Name = "lblScaleZ";
            this.lblScaleZ.Size = new System.Drawing.Size(55, 13);
            this.lblScaleZ.TabIndex = 6;
            this.lblScaleZ.Text = "Z Scaling:";
            // 
            // numScaleZ
            // 
            this.numScaleZ.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.numScaleZ.DecimalPlaces = 1;
            this.numScaleZ.Increment = new decimal(new int[] {
																 1,
																 0,
																 0,
																 65536});
            this.numScaleZ.Location = new System.Drawing.Point(510, 135);
            this.numScaleZ.Name = "numScaleZ";
            this.numScaleZ.Size = new System.Drawing.Size(61, 20);
            this.numScaleZ.TabIndex = 5;
            this.numScaleZ.Value = new decimal(new int[] {
															 10,
															 0,
															 0,
															 65536});
            this.numScaleZ.ValueChanged += new System.EventHandler(this.Scale_ValueChanged);
            // 
            // lblScaleY
            // 
            this.lblScaleY.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.lblScaleY.AutoSize = true;
            this.lblScaleY.Location = new System.Drawing.Point(510, 63);
            this.lblScaleY.Name = "lblScaleY";
            this.lblScaleY.Size = new System.Drawing.Size(55, 13);
            this.lblScaleY.TabIndex = 4;
            this.lblScaleY.Text = "Y Scaling:";
            // 
            // numScaleY
            // 
            this.numScaleY.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.numScaleY.DecimalPlaces = 1;
            this.numScaleY.Increment = new decimal(new int[] {
																 1,
																 0,
																 0,
																 65536});
            this.numScaleY.Location = new System.Drawing.Point(510, 82);
            this.numScaleY.Name = "numScaleY";
            this.numScaleY.Size = new System.Drawing.Size(61, 20);
            this.numScaleY.TabIndex = 3;
            this.numScaleY.Value = new decimal(new int[] {
															 10,
															 0,
															 0,
															 65536});
            this.numScaleY.ValueChanged += new System.EventHandler(this.Scale_ValueChanged);
            // 
            // lblScaleX
            // 
            this.lblScaleX.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.lblScaleX.AutoSize = true;
            this.lblScaleX.Location = new System.Drawing.Point(510, 12);
            this.lblScaleX.Name = "lblScaleX";
            this.lblScaleX.Size = new System.Drawing.Size(55, 13);
            this.lblScaleX.TabIndex = 2;
            this.lblScaleX.Text = "X Scaling:";
            // 
            // numScaleX
            // 
            this.numScaleX.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
            this.numScaleX.DecimalPlaces = 1;
            this.numScaleX.Increment = new decimal(new int[] {
																 1,
																 0,
																 0,
																 65536});
            this.numScaleX.Location = new System.Drawing.Point(510, 31);
            this.numScaleX.Name = "numScaleX";
            this.numScaleX.Size = new System.Drawing.Size(61, 20);
            this.numScaleX.TabIndex = 1;
            this.numScaleX.Value = new decimal(new int[] {
															 10,
															 0,
															 0,
															 65536});
            this.numScaleX.ValueChanged += new System.EventHandler(this.Scale_ValueChanged);
            // 
            // toolStrip1
            // 
            this.toolStrip1.Dock = System.Windows.Forms.DockStyle.None;
            this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
																						this.btnOpen,
																						this.btnHelp,
																						this.txtFPS});
            this.toolStrip1.Location = new System.Drawing.Point(3, 0);
            this.toolStrip1.Name = "toolStrip1";
            this.toolStrip1.Size = new System.Drawing.Size(160, 25);
            this.toolStrip1.TabIndex = 0;
            // 
            // btnOpen
            // 
            this.btnOpen.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.btnOpen.Image = ((System.Drawing.Image)(resources.GetObject("btnOpen.Image")));
            this.btnOpen.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnOpen.Name = "btnOpen";
            this.btnOpen.Size = new System.Drawing.Size(23, 22);
            this.btnOpen.Text = "toolStripButton1";
            this.btnOpen.Click += new System.EventHandler(this.open_Click);
            // 
            // btnHelp
            // 
            this.btnHelp.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
            this.btnHelp.Image = ((System.Drawing.Image)(resources.GetObject("btnHelp.Image")));
            this.btnHelp.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.btnHelp.Name = "btnHelp";
            this.btnHelp.Size = new System.Drawing.Size(23, 22);
            this.btnHelp.Text = "btnHelp";
            // 
            // txtFPS
            // 
            this.txtFPS.Name = "txtFPS";
            this.txtFPS.Size = new System.Drawing.Size(100, 25);
            // 
            // MainForm
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(632, 446);
            this.Controls.Add(this.toolStripContainer1);
            this.Controls.Add(this.mnuMain);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.MainMenuStrip = this.mnuMain;
            this.MinimumSize = new System.Drawing.Size(640, 480);
            this.Name = "MainForm";
            this.Text = "Irrlicht with WinForms MeshViewer";
            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing);
            this.Load += new System.EventHandler(this.MainForm_Load);
            this.mnuMain.ResumeLayout(false);
            this.mnuMain.PerformLayout();
            this.toolStripContainer1.ContentPanel.ResumeLayout(false);
            this.toolStripContainer1.ContentPanel.PerformLayout();
            this.toolStripContainer1.TopToolStripPanel.ResumeLayout(false);
            this.toolStripContainer1.TopToolStripPanel.PerformLayout();
            this.toolStripContainer1.ResumeLayout(false);
            this.toolStripContainer1.PerformLayout();
            this.gbDrivers.ResumeLayout(false);
            this.gbDrivers.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.numScaleZ)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.numScaleY)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.numScaleX)).EndInit();
            this.toolStrip1.ResumeLayout(false);
            this.toolStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }
        #endregion


        #region - Winforms Events -

        private void MainForm_Load(object sender, EventArgs e)
        {
            startDelay.Enabled = true;
        }

        void startDelay_Tick(object sender, EventArgs e)
        {
            startDelay.Enabled = false;
            RunDevice(pnlIrrlicht);
        }

        private void open_Click(object sender, EventArgs e)
        {
            StringBuilder filter = new StringBuilder();
            filter.Append("3D Studio Mesh(*.3ds)|*.3ds");
            filter.Append("|Alias Wavefront Maya(*.obj)|*.obj");
            filter.Append("|Cartography Shop 4(*.csm)|*.csm");
            filter.Append("|COLLADA(*.xml;*.dae)|*.xml;*.dae");
            filter.Append("|DeleD(*.dmf)|*.dmf");
            filter.Append("|FSRad oct(*.oct)|*.oct");
            filter.Append("|Microsoft DirectX(*.x)|*.x");
            filter.Append("|Milkshape (*.ms3d)|*.ms3d");
            filter.Append("|My3DTools 3(*my3D)|*.my3D");
            filter.Append("|Pulsar LMTools(*.lmts)|*.lmts");
            filter.Append("|Quake 3 levels(*.bsp)|*.bsp");
            filter.Append("|Quake 2 models(*.md2)|*.md2");
            filter.Append("|Packed models(*.pk3)|*.pk3");
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = filter.ToString();
            ofd.FilterIndex = 7;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                LoadModel(ofd.FileName);
            }
        }

        private void Exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            quitting = true;
        }

        private void Help_Click(object sender, EventArgs e)
        {
            caption = "Irrlicht.NET engine mesh viewer - ";
            if (device != null && device.VideoDriver != null)
            {
                caption += device.VideoDriver.GetType().ToString();
            }
            MessageBox.Show(messageText, caption);
        }

        private void rb_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                paused = true;
                SetDevice(pnlIrrlicht, PickDriver());
                LoadModel(path + currentModelFile);
                LoadSkyBox();
                paused = false;
                RunDevice(pnlIrrlicht);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, caption);
            }
        }

        private void SkyBox_CheckedChanged(object sender, EventArgs e)
        {
            if (sender.GetType() == typeof(CheckBox))
                mnuViewSkyBox.Checked = chkSkyBox.Checked;
            else
                chkSkyBox.Checked = mnuViewSkyBox.Checked;

            if (skyBox != null) skyBox.Visible = chkSkyBox.Checked;
        }

        private void Debug_CheckedChanged(object sender, EventArgs e)
        {
            if (sender.GetType() == typeof(CheckBox))
                mnuViewDebug.Checked = chkDebug.Checked;
            else
                chkDebug.Checked = mnuViewDebug.Checked;

            if (model != null) model.DebugDataVisible = chkDebug.Checked;
        }

        private void mnuViewMatSolid_Click(object sender, EventArgs e)
        {
            mnuViewMatSolid.Checked = true;
            mnuViewMatTransp.Checked = false;
            mnuViewMatReflect.Checked = false;

            if (model != null) model.SetMaterialType(video.MaterialType.Solid);
        }

        private void mnuViewMatTransp_Click(object sender, EventArgs e)
        {
            mnuViewMatSolid.Checked = false;
            mnuViewMatTransp.Checked = true;
            mnuViewMatReflect.Checked = false;

            if (model != null) model.SetMaterialType(video.MaterialType.TransparentAddColor);
        }

        private void mnuViewMatReflect_Click(object sender, EventArgs e)
        {
            mnuViewMatSolid.Checked = false;
            mnuViewMatTransp.Checked = false;
            mnuViewMatReflect.Checked = true;

            if (model != null) model.SetMaterialType(video.MaterialType.SphereMap);
        }

        private void Scale_ValueChanged(object sender, EventArgs e)
        {
            core.Vector3D scale;
            scale.X = (float)numScaleX.Value;
            scale.Y = (float)numScaleY.Value;
            scale.Z = (float)numScaleZ.Value;

            if (model != null) model.Scale = scale;
        }
        #endregion


        #region - Resource Loading -

        private void LoadIrrConfig()
        {
            if (File.Exists(path + configFile))
            {
                XmlTextReader xtr = new XmlTextReader(path + configFile);

                try
                {
                    while (xtr.Read())
                    {
                        if ((xtr.NodeType == XmlNodeType.Element))
                        {
                            if (xtr.LocalName == "startUpModel")
                            {
                                xtr.MoveToFirstAttribute();
                                startupModelFile = xtr.Value;
                                // Clean the leading stuff from the filename:
                                int lastSlash = startupModelFile.LastIndexOf("/");
                                startupModelFile = startupModelFile.Substring(lastSlash + 1);
                                xtr.MoveToElement();
                            }
                            else if (xtr.LocalName == "messageText")
                            {
                                xtr.MoveToFirstAttribute();
                                captBase = xtr.Value;
                                xtr.MoveToElement();
                                messageText = xtr.ReadElementString();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                xtr.Close();
            }
        }

        /// <summary>
        /// This method loads a model and displays it using an
        /// addAnimatedMeshSceneNode and the scene manager. Nothing difficult. It also
        /// displays a short message box, if the model could not be loaded.
        /// </summary>
        /// <param name="fileName">File name of the model to be loaded.</param>
        private void LoadModel(string fileName)
        {
            // Check if we have a valid device to use.
            if (device == null)
            {
                MessageBox.Show("Can't load model because the device is not created.", caption);
                return;
            }

            bool foundBSP = false;
            // modify the name if it a .pk3 file
            if (fileName.EndsWith(".pk3"))
            {
                //device.FileSystem.AddZipFileArchive(fileName);
                device.FileSystem.AddZipFileArchive(fileName, true, true);
                foundBSP = true;
            }

            // Clear the model if there was something loaded before.
            if (model != null) model.Remove();

            // Load a mesh from file.
            scene.AnimatedMesh m = device.SceneManager.GetMesh(fileName);

            if (m == null)
            {
                // Model could not be loaded
                if (startupModelFile != fileName)
                {
                    string error = "The model could not be loaded.\nMaybe it is not a supported file format.";
                    MessageBox.Show(error, caption);
                }
                return;
            }

            // load a model into the engine from the mesh
            //model = device.SceneManager.AddAnimatedMeshSceneNode(m, null, 0);
            model = device.SceneManager.AddAnimatedMeshSceneNode(m);

            // set default material properties
            if (!foundBSP)
            {
                if (mnuViewMatSolid.Checked)
                    model.SetMaterialType(video.MaterialType.Solid);
                else if (mnuViewMatTransp.Checked)
                    model.SetMaterialType(video.MaterialType.TransparentAddColor);
                else if (mnuViewMatReflect.Checked)
                    model.SetMaterialType(video.MaterialType.SphereMap);
            }

            model.SetMaterialFlag(video.MaterialFlag.Lighting, false);
            model.DebugDataVisible = true;
            model.AnimationSpeed = 1000;
        }

        /// <summary>
        /// Loads the skybox using the device's driver & scene manager.
        /// </summary>
        private void LoadSkyBox()
        {
            if (device == null)
            {
                MessageBox.Show("Couldn't load skybox because device was null.", caption);
                return;
            }

            video.VideoDriver driver = device.VideoDriver;
            scene.SceneManager smgr = device.SceneManager;
            skyBox = smgr.AddSkyBoxSceneNode(null, new Texture[] {driver.GetTexture(path + "irrlicht2_up.jpg"),
                driver.GetTexture(path + "irrlicht2_dn.jpg"),
                driver.GetTexture(path + "irrlicht2_lf.jpg"),
                driver.GetTexture(path + "irrlicht2_rt.jpg"),
                driver.GetTexture(path + "irrlicht2_ft.jpg"),
                driver.GetTexture(path + "irrlicht2_bk.jpg") },
                -1);	// null & -1 are the defaults in the native engine.

            if (skyBox != null) skyBox.Visible = chkSkyBox.Checked;
        }

        #endregion


        #region - Device selection & setup -

        /// <summary>
        /// Gets the <see cref="Irrlicht.Video.DriverType"/> that the user selected.
        /// </summary>
        /// <returns><see cref="Irrlicht.Video.DriverType"/> the user selected.</returns>
        private Irrlicht.NET.DriverType PickDriver()
        {
            //if (rbD3D9.Checked) return Irrlicht.Video.DriverType.DIRECT3D9;
            if (rbD3D9.Checked) return Irrlicht.NET.DriverType.Direct3D9;
            if (rbD3D8.Checked) return Irrlicht.NET.DriverType.Direct3D8;
            if (rbOGL.Checked) return Irrlicht.NET.DriverType.OpenGL;
            if (rbSoft1.Checked) return Irrlicht.NET.DriverType.Software;
            if (rbSoft2.Checked) return Irrlicht.NET.DriverType.Software2;
            return Irrlicht.NET.DriverType.Null;
        }

        /// <summary>
        /// Sets up the device to run in a <see cref="Control"/> with the specified <see cref="Irrlicht.Video.DriverType"/>.
        /// </summary>
        /// <param name="c">Winforms <see cref="Control"/> that Irrlicht is to render in.</param>
        /// <param name="driver"><see cref="Irrlicht.Video.DriverType"/> to use when setting up the IrrlichtDevice.</param>
        /// <returns>True if the setup went well, False otherwise.</returns>
        private bool SetDevice(Control c, Irrlicht.NET.DriverType driverType)
        {
            if (quitting) return false;

            if (device != null)
            {
                //device.E
            }

            CreatePanel();

            //device = new IrrlichtDevice(driverType, new core.Dimension2D(c.ClientRectangle.Width, c.ClientRectangle.Height), 32, false, false, false, true, c.Handle);
            device = new IrrlichtDevice(driverType, new Dimension2D(c.ClientRectangle.Width, c.ClientRectangle.Height), 32, false, true, true, true);

            if (device == null) return false;

            device.Resizeable = true;
            gui.GUIEnvironment env = device.GUIEnvironment;
            video.VideoDriver driver = device.VideoDriver;
            scene.SceneManager smgr = device.SceneManager;
            driver.SetTextureFlag(video.TextureCreationFlag.Always32Bit, true);

            // This sets the gui font from a bmp file.
            gui.GUISkin skin = env.Skin;
            gui.GUIFont font = env.GetFont(path + "fonthaettenschweiler.bmp");
            //if (font != null) skin.Font = font;

            // This is loaded with the default values for the native engine.
            smgr.AddCameraSceneNodeMaya(null, -1500, 500, 1500, -1);
            irrLogo = driver.GetTexture(path + "irrlichtlogoaligned.jpg");

            caption = captBase + " (using " + driverType.ToString() + " driver)";
            this.Text = caption;

            return true;
        }

        /// <summary>
        /// Since the panel gets destroyed with device.CloseDevice,
        /// we are creating it separately from the standard
        /// Visual Studio section.
        /// </summary>
        private void CreatePanel()
        {
            if (panelMemory == null || panelMemory == Rectangle.Empty)
                panelMemory = new Rectangle(12, 12, 481, 373);

            this.pnlIrrlicht = new System.Windows.Forms.Panel();
            // 
            // pnlIrrlicht
            // 
            this.pnlIrrlicht.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
                | System.Windows.Forms.AnchorStyles.Left)
                | System.Windows.Forms.AnchorStyles.Right)));
            this.pnlIrrlicht.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.pnlIrrlicht.Location = panelMemory.Location;
            this.pnlIrrlicht.Name = "pnlIrrlicht";
            this.pnlIrrlicht.Size = panelMemory.Size;
            this.pnlIrrlicht.TabIndex = 0;
            this.pnlIrrlicht.Resize += new EventHandler(pnlIrrlicht_Resize);
            this.pnlIrrlicht.Move += new EventHandler(pnlIrrlicht_Move);
            this.toolStripContainer1.ContentPanel.Controls.Add(this.pnlIrrlicht);
            this.toolStripContainer1.ContentPanel.ResumeLayout(false);
            this.toolStripContainer1.ContentPanel.PerformLayout();
        }

        /// <summary>
        /// We are using this to rember the location / size of the Irrlicht panel.
        /// </summary>
        /// <param name="sender">Event's sender.</param>
        /// <param name="e">Event arguments.</param>
        void pnlIrrlicht_Move(object sender, EventArgs e)
        {
            panelMemory.Location = pnlIrrlicht.Location;
            panelMemory.Size = pnlIrrlicht.Size;
        }

        /// <summary>
        /// We are using this to rember the location / size of the Irrlicht panel.
        /// </summary>
        /// <param name="sender">Event's sender.</param>
        /// <param name="e">Event arguments.</param>
        void pnlIrrlicht_Resize(object sender, EventArgs e)
        {
            panelMemory.Location = pnlIrrlicht.Location;
            panelMemory.Size = pnlIrrlicht.Size;
        }

        #endregion

        /// <summary>
        /// Starts the Irrlicht rendering loop.
        /// </summary>
        /// <param name="c">The <see cref="Control"/> that Irrlicht is running in.</param>
        private void RunDevice(Control c)
        {
            if (model == null) LoadModel(path + startupModelFile);
            while (!paused && !quitting && device.Run() && device.VideoDriver != null)
            {
                //device.VideoDriver.BeginScene(true, true, new Irrlicht.Net.Color(150, 50, 50, 50));
                device.VideoDriver.BeginScene(true, true, new Irrlicht.NET.Color(150, 50, 50, 50));
                device.SceneManager.DrawAll();
                device.GUIEnvironment.DrawAll();
                core.Position2D logoLocation = new core.Position2D(c.ClientRectangle.Left + 20, c.ClientRectangle.Bottom - 40);
                device.VideoDriver.Draw2DImage(irrLogo, logoLocation);
                device.VideoDriver.EndScene();
                if (!quitting && !paused) txtFPS.Text = device.VideoDriver.FPS + " FPS";
            }
        }

    }
}
// Retrieved from "http://www.irrforge.org/index.php/CS_Tutorial_9"
// This page has been accessed 283 times. This page was last modified 01:00, 26 Jan 2006. 

Any help is welcome ( and take it easy on the newb :oops: ).
DeusXL
Posts: 114
Joined: Sun Mar 14, 2004 9:37 am
Contact:

Post by DeusXL »

Hello,
I think the problem is not related to any wrapper because it's written :
"Could not find any resources appropriate for the specified culture or the neutral culture. Make sure "_09.WinFormMeshViewer.MainForm.resources" was correctly embedded or linked into assembly "Meshviewer_NET" at compile timem, or that all the satelite assemblies required are loadable and fully signed. "

So I guess you are using an resource that you did not include in your Visual Studio solution.

The best solution would be to include all resources in your new solution but if you just want to test you can just remove all lines (there are 3) which use the variable "resources" in InitializeComponent().
They begin with "this.btnOpen.Image", "this.BtnHelp.Image" and "this.Icon".

Your code should look like that :

Code: Select all


PS : I added the Irrlicht binding with the panel because even if it is marked obsolete, it seems to work !
Last edited by DeusXL on Tue Jul 18, 2006 7:45 am, edited 1 time in total.
Irrlicht .NET complete and Cross Platform Wrapper
The kid on my avatar wrote:A painless lesson is one without any meaning
sh1ny
Posts: 21
Joined: Mon Jul 17, 2006 6:21 pm

Post by sh1ny »

Yay ! :)
Last one for today ( ill be trying to convert write some stuff on my own next but i wont give up easy :P ) :

Code: Select all

/* 
Lets start like the HelloWorld example: We include 
the irrlicht header files and an additional file to be able 
to ask the user for a driver type using the console. 
*/
using System;
using System.Text;
using System.IO;

using Irrlicht.NET;

namespace TerrainRendering
{
    class Program : Event
    {
        string path = "../../media/";
        TerrainSceneNode terrain;
        bool isWireframe = false;

        //ISceneNode node=null; 
        /// <summary> 
        /// Main entry point for the program. 
        /// </summary> 
        /// <param name="args">Arguments to pass the software.</param> 
        [STAThread]
        static void Main(string[] args)
        {
            Program prog = new Program();
            prog.run();
        }

        /* In the beginning there is nothing special. We include the needed header files 
              and create an event listener to listen if the user presses the 'W' key so we 
              can switch to wireframe mode and if he presses 'D' we toggle to material 
              between solid and detail mapped. 
        */
        public bool OnEvent(Event p_event)
        {
            // check if user presses the key 'W' or 'D' 
            if (p_event.Type == EventType.KeyInputEvent && !p_event.KeyPressedDown)
            {
                switch (p_event.KeyCode)
                {
                    case KeyCode.Key_W:
                        isWireframe = !isWireframe;
                        terrain.SetMaterialFlag(MaterialFlag.Wireframe, isWireframe);
                        break;
                    case KeyCode.Key_D:
                        terrain.SetMaterialType(
                            terrain.GetMaterial(0).MaterialType == MaterialType.Solid ?
                            MaterialType.DetailMap : MaterialType.Solid);
                        return true;
                }
            }
            return false;
        }

        public void run()
        {
            /* The start of the main function starts like in most other example. 
               We ask the user for the desired renderer and start it up. 
            */

            // ask user for driver 
            DriverType driverType;

            // Ask user to select driver: 
            StringBuilder sb = new StringBuilder();
            sb.Append("Please select the driver you want for this example:\n");
            sb.Append("\n(a) Direct3D 9.0c\n(b) Direct3D 8.1\n(c) OpenGL 1.5");
            sb.Append("\n(d) Software Renderer\n(e) Apfelbaum Software Renderer");
            sb.Append("\n(f) Null Device\n(otherKey) exit\n\n");

            // Get the user's input: 
            TextReader tIn = Console.In;
            TextWriter tOut = Console.Out;
            tOut.Write(sb.ToString());
            string input = tIn.ReadLine();

            // Select device based on user's input: 
            switch (input)
            {
                case "a":
                    driverType = DriverType.Direct3D9;
                    break;
                case "b":
                    driverType = DriverType.Direct3D8;
                    break;
                case "c":
                    driverType = DriverType.OpenGL;
                    break;
                case "d":
                    driverType = DriverType.Software;
                    break;
                case "e":
                    driverType = DriverType.Software;
                    break;
                case "f":
                    driverType = DriverType.Null;
                    break;
                default:
                    return;
            }

            // Create device and exit if creation fails: 
            IrrlichtDevice device = new IrrlichtDevice(driverType, new Dimension2D(640, 480), 32, false, true, true, true);
            if (device == null)
            {
                tOut.Write("Device creation failed.");
                return;
            }

            /* set this as event receiver*/
            device.OnEvent += new OnEventDelegate(OnEvent);
            /*************************************************/
            /* First, we add standard stuff to the scene: A nice irrlicht engine logo, 
               a small help text, a user controlled camera, and we disable the mouse 
               cursor.*/
            SceneManager smgr = device.SceneManager;
            VideoDriver driver = device.VideoDriver;
            GUIEnvironment env = device.GUIEnvironment;

            driver.SetTextureFlag(TextureCreationFlag.Always32Bit, true);

            // add irrlicht logo 
            env.AddImage(driver.GetTexture(path + "irrlichtlogoalpha.tga"), new Position2D(10, 10), true, null, 0, "");

            // add some help text 
            GUIStaticText text = env.AddStaticText(
                "Press 'W' to change wireframe mode\nPress 'D' to toggle detail map",
                new Rect(new Position2D(10, 453), new Position2D(200, 475)), true, true, null, -1, false);

            // add camera 
            CameraSceneNode camera =
                smgr.AddCameraSceneNodeFPS(null, 100.0f, 1200.0f, false);
            camera.Position = new Vector3D(1900 * 2, 255 * 2, 3700 * 2);
            camera.Target = new Vector3D(2397 * 2, 343 * 2, 2700 * 2);
            camera.FarValue = 12000.0f;

            // disable mouse cursor 
            device.CursorControl.Visible = false;
            /* Here comes the terrain renderer scene node: We add it just like any other scene 
               node to the scene using ISceneManager::addTerrainSceneNode(). The only parameter 
               we use is a file name to the heightmap we use. A heightmap is simply a gray 
               scale texture. The terrain renderer loads it and creates the 3D terrain 
               from it. 
               To make the terrain look more big, we change the scale factor of it to 
               (40, 4.4, 40). Because we don't have any dynamic lights in the scene, we 
               switch off the lighting, and we set the file terrain-texture.jpg as texture 
               for the terrain and detailmap3.jpg as second texture, called detail map. 
               At last, we set the scale values for the texture: The first texture will be 
               repeated only one time over the whole terrain, and the second one (detail map) 
               20 times. 
             */
            // add terrain scene node 
            terrain = smgr.AddTerrainSceneNode(
                path + "terrain-heightmap.bmp", null, -1,
                new Vector3D(), new Vector3D(), new Vector3D(40, 4.4f, 40), new Color(255, 255, 255, 255), -1, TerrainPatchSize.TPS129);

            terrain.SetMaterialFlag(MaterialFlag.Lighting, false);
            terrain.SetMaterialType(MaterialType.DetailMap);
            terrain.SetMaterialTexture(0, driver.GetTexture(path + "terrain-texture.jpg"));
            terrain.SetMaterialTexture(1, driver.GetTexture(path + "detailmap3.jpg"));


            terrain.ScaleTexture(1.0f, 20.0f);

            /* To be able to do collision with the terrain, we create a triangle selector. 
               If you want to know what triangle selectors do, just take a look into the 
               collision tutorial. The terrain triangle selector works together with the 
               terrain. To demonstrate this, we create a collision response animator and 
               attach it to the camera, so that the camera will not be able to fly through 
               the terrain.*/
            // create triangle selector for the terrain    
            TriangleSelector selector =
                smgr.CreateTerrainTriangleSelector(terrain, 0);

            // create collision response animator and attach it to the camera 
            Animator anim = smgr.CreateCollisionResponseAnimator(
                selector, camera, new Vector3D(60, 100, 60),
                new Vector3D(0, 0, 0),
                new Vector3D(0, 50, 0), 0.0005f);
            camera.AddAnimator(anim);

            //we add the skybox which we already used in lots of Irrlicht examples. 
            driver.SetTextureFlag(TextureCreationFlag.CreateMipMaps, false);

            smgr.AddSkyBoxSceneNode(
                null,
                new Texture[] {
                driver.GetTexture(path + "irrlicht2_up.jpg"),
                driver.GetTexture(path + "irrlicht2_dn.jpg"),
                driver.GetTexture(path + "irrlicht2_lf.jpg"),
                driver.GetTexture(path + "irrlicht2_rt.jpg"),
                driver.GetTexture(path + "irrlicht2_ft.jpg"),
                driver.GetTexture(path + "irrlicht2_bk.jpg") },  0);

            driver.SetTextureFlag(TextureCreationFlag.CreateMipMaps, true);










            /* That's it, draw everything. Now you know how to use terrain 
               in Irrlicht. 
            */
            int lastFPS = -1;

            while (device.Run())
            {
                if (device.WindowActive)
                {
                    device.VideoDriver.BeginScene(true, true, new Color(0, 200, 200, 200));
                    device.SceneManager.DrawAll();
                    device.VideoDriver.EndScene();

                    int fps = device.VideoDriver.FPS;
                    if (lastFPS != fps)
                    {
                        device.WindowCaption = "Irrlicht Engine - Terrain example [" +
                            driverType.ToString() + "] FPS:" + fps.ToString();
                        lastFPS = fps;
                    }
                }
            }


            /* 
            In the end, delete the Irrlicht device. 
            */
            // Instead of device.drop, we'll use: 
            GC.Collect();

        }
    }
}
// Retrieved from "http://www.irrforge.org/index.php/CS_Tutorial_12"
// This page has been accessed 228 times. This page was last modified 06:58, 20 Jan 2006. 

This one wants the runtime to terminate it :/
Sorry really last one for today :P :)
DeusXL
Posts: 114
Joined: Sun Mar 14, 2004 9:37 am
Contact:

Post by DeusXL »

This one's terminating because you have no console and you are trying to get the input.
Go to Project=><your project name> Properties
And Set Ouput Type to "Console Application".

If your bug is not solved (for instance you have an C++ Runtime Termination), there is a big problem when you are creating the terrain :
terrain = smgr.AddTerrainSceneNode(
path + "terrain-heightmap.bmp", null, -1,
new Vector3D(), new Vector3D(), new Vector3D(40, 4.4f, 40), new Color(255, 255, 255, 255), -1, TerrainPatchSize.TPS129);
You see the "-1" in red ? There is a bug because you set the maxLOD to -1 and Irrlicht cannot accept it !
If you always want the maximal LOD, set a value like 1000 or int.MaxValue !
The maxLOD must never be null or negative !

Moreover you set the terrain patch size to 129, I do not advice it because Irrlicht won't behave well with such a patch size. Try using TPS17 or TPS33 instead (TPS65 is really really slow and TPS9 is not precise).

PS : When you are debugging an application which causes a runtime termination, try adding some Console.WriteLine() or MessageBox.Show to see were is the error because when you will have a 10000 lines-long code, no one will be able to debug in your stead ;)
Irrlicht .NET complete and Cross Platform Wrapper
The kid on my avatar wrote:A painless lesson is one without any meaning
sh1ny
Posts: 21
Joined: Mon Jul 17, 2006 6:21 pm

Post by sh1ny »

Yeah i get a C++ runtime termination >.< . I added some deubug messages and it seems to stop at adding the terrain. I modified it to look like :

Code: Select all

terrain = smgr.AddTerrainSceneNode(path + "terrain-heightmap.bmp", null, int.MaxValue, new Vector3D(), new Vector3D(1,1,1), new Vector3D(40, 4.4f, 40), new Color(255, 255, 255, 255), -1, TerrainPatchSize.TPS17);
And yes im sure the project is set to "Console application". Can you try creating a terrain demo with Irrlicht.NET CP and see if it works for you ? Almost everything else is ok....im currently unsure how to do code like :

Code: Select all

void CMainMenu::setTransparency()
{
	for (s32 i=0; i<gui::EGDC_COUNT ; ++i)
	{
		video::SColor col = device->getGUIEnvironment()->getSkin()->
			getColor((gui::EGUI_DEFAULT_COLOR)i);
		col.setAlpha(transparent ? 201 : 255);
		device->getGUIEnvironment()->getSkin()->setColor((gui::EGUI_DEFAULT_COLOR)i, col);
	}
}
since i dont see a way to set/get the color. Same goes for Skin fonts, but i guess it's just wip :P :)
DeusXL
Posts: 114
Joined: Sun Mar 14, 2004 9:37 am
Contact:

Post by DeusXL »

Read again my post, I told you how to solve your problem...
Irrlicht .NET complete and Cross Platform Wrapper
The kid on my avatar wrote:A painless lesson is one without any meaning
sh1ny
Posts: 21
Joined: Mon Jul 17, 2006 6:21 pm

Post by sh1ny »

DeusXL wrote:Read again my post, I told you how to solve your problem...
Ooops, my bad, i changed the wrong -1 :oops: Havent slept much hehe :)
Locked