Page 1 of 1

Can't load libOgre.dll in C#

Posted: Mon Feb 22, 2021 6:33 pm
by r0ut
Ogre Version: 1.12.11
Operating System: Windows 10 Pro x64
Render System: DX11 I guess

I did with success the example made at https://github.com/OGRECave/ogre/tree/m ... les/Csharp
But now I want to do it in my own project. So I've created a WPF project in C# and when I try to run the example it throws me an error saying it couldn't load libOgre.dll at var app = new Example();
I'm running in x64 debug mode in Visual Studio Community

Should I include more than Ogre.dll reference in my project or any other files? I'm pretty new to Ogre and I wanted to create an application with a 3D preview powered by Ogre inside my main window

This is the whole code, I just copypasted it from the example:

Code: Select all

using System.Windows;
using org.ogre;

namespace TesteWPFOgre
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var app = new Example();
            app.initApp();
            app.getRoot().startRendering();
            app.closeApp();
        }      
    }

    public class KeyListener : InputListener
    {
        org.ogre.ApplicationContext ctx;

        public KeyListener(org.ogre.ApplicationContext ctx)
        {
            this.ctx = ctx;
        }

        public override bool keyPressed(KeyboardEvent evt)
        {
            if (evt.keysym.sym == 27)
                ctx.getRoot().queueEndRendering();
            return true;
        }
    }

    public class Example : org.ogre.ApplicationContext
    {
        InputListener listener;

        public Example()
        {
            listener = new KeyListener(this);
        }

        public override void setup()
        {
            base.setup();
            addInputListener(listener);

            var root = getRoot();
            var scnMgr = root.createSceneManager();

            var shadergen = ShaderGenerator.getSingleton();
            shadergen.addSceneManager(scnMgr); // must be done before we do anything with the scene

            scnMgr.setAmbientLight(new ColourValue(.1f, .1f, .1f));

            var light = scnMgr.createLight("MainLight");
            var lightnode = scnMgr.getRootSceneNode().createChildSceneNode();
            lightnode.setPosition(0f, 10f, 15f);
            lightnode.attachObject(light);

            var cam = scnMgr.createCamera("myCam");
            cam.setAutoAspectRatio(true);
            cam.setNearClipDistance(5);
            var camnode = scnMgr.getRootSceneNode().createChildSceneNode();
            camnode.attachObject(cam);

            var camman = new CameraMan(camnode);
            camman.setStyle(CameraStyle.CS_ORBIT);
            camman.setYawPitchDist(new Radian(0), new Radian(0.3f), 15f);
            addInputListener(camman);

            var vp = getRenderWindow().addViewport(cam);
            vp.setBackgroundColour(new ColourValue(.1f, .1f, .1f));

            var ent = scnMgr.createEntity("Sinbad.mesh");
            var node = scnMgr.getRootSceneNode().createChildSceneNode();
            node.attachObject(ent);
        }
    }
}

Re: Can't load libOgre.dll in C#

Posted: Mon Feb 22, 2021 7:09 pm
by paroj
probably it will work if you copy your .exe to the bin/ folder.

Ogre.dll, needs libOgre.dll, which needs OgreMain.dll, which at runtime loads RenderSystem_Direct3D11.dll etc.

You do not necessarily need to copy all of that. See this for details:
https://ogrecave.github.io/ogre/api/lat ... tupRunning

Re: Can't load libOgre.dll in C#

Posted: Tue Feb 23, 2021 2:17 pm
by r0ut
I've accidentally clicked on "mark as solved" button, is there a way to cancel that?
paroj wrote: Mon Feb 22, 2021 7:09 pm probably it will work if you copy your .exe to the bin/ folder.

Ogre.dll, needs libOgre.dll, which needs OgreMain.dll, which at runtime loads RenderSystem_Direct3D11.dll etc.

You do not necessarily need to copy all of that. See this for details:
https://ogrecave.github.io/ogre/api/lat ... tupRunning
Thanks! I've added the sdk/bin folder to Windows PATH variables and seems to work! :D
However now I've got

Code: Select all

System.ApplicationException: 'Ogre::RuntimeAssertionException::RuntimeAssertionException: no RenderSystem in Ogre::Root::startRendering at C:\projects\ogre-bsrh7\OgreMain\src\OgreRoot.cpp (line 844)'
At app.getRoot().startRendering();.
This path doesn't even exist in my pc.

I've searched and I think there should be an file called "Ogre.cfg" so I could change the render system but I can't find this file. Should I create it or there's somewhere I need to change?

Re: Can't load libOgre.dll in C#

Posted: Tue Feb 23, 2021 5:42 pm
by paroj
yeah, thats addressed the part "Configuration Files" in the above link.

RenderSystems are plugins, but there is likely no "plugins.cfg" next to your .exe. While at it, you should also put a "resources.cfg" there, as this will likely be your next issue.

The path in the exception refers to the .cpp file on the builder, so you can ignore that. However, the message still tells you whats wrong.

Re: Can't load libOgre.dll in C#

Posted: Tue Feb 23, 2021 6:02 pm
by r0ut
Yeah, I've created the plugins.cfg and resources.cfg, coppied the media folder with all the stuff but still has some errors that I need to find out now, at the moment I don't see any program on running my .exe inside the bin folder. Thanks!

Also is there a way to render Ogre inside a Canvas or something like that inside my WPF application without Mogre? I don't want it to open a new window. Will I need to mess around with WIN32 API or there are something built in like Mogro?