Embedding ogre in gtk-sharp custom widget?

shaft

29-03-2006 23:22:54

Just curious if anyone has tried and successfully embedded ogre into a GTK-sharp widget? If so, and tutorials or code I could look at?

I;m planning on using GTK rather than winforms becuase there is a little better compatibility on Mono and linux.

rastaman

30-03-2006 01:02:44

hmm... I was thinking about this last week. It should not be too different than Winforms, just need to call a different Initialise function in root.

public RenderWindow Initialise(int existingwindowhandle, int width, int height, bool fullscreen)


The real question is how to get a handle to something in gtk-sharp. was looking in monodoc and didn't see anything explicitly saying it was the equivalent of a Hwnd ;). But everything derives from GLib.Object and that has a read-only property Handle.

rastaman

30-03-2006 15:13:02

well no joy on my first try with gtk-sharp and ogre in linux. I got the same error as winforms is giving me. "Got a SIGSEGV while executing native code". almost the same the stactrace is differnt. seems mono is not working the same as .net somewhere.
i found some post in Mono-winforms-list about simarlar problem but not sure how to resolve it.
feb 2006 archive
in this post
Just a small update for all of you who are watching this topic/
thread. With help from the very friendly people on irc.gimp.net #mono-
winforms we managed to find out that the cause of this problem was
because of the -fomit-frame-pointer CFLAG. which for some reason was
causing the application to seg fault.

By Compiling the library without the -fomit-frame-pointer cflag we
were able to solve the problem. The proposed solution is to patch the
configure/make file script to check if the -fomit-frame-pointer is
turned on and if so disable it.

but what library. and how would i check/remove that flag i haven't figured out.

shaft

31-03-2006 03:34:21

Have you tried your code in windows?

If not, send me a copy of your test code and I'll give it a try. Just curious if it is a linux issue, a mono issue, or a gtk usage issue.

rastaman

31-03-2006 05:11:42

its nothing much real GTKSharpTest.tgz

shaft

31-03-2006 23:48:17

I'm having trouble as well... I'm running code very similar to yours and I'm getting an ogre exceptions.

Any thoughts...


class OgreWidget : Gtk.Container
{
//...Skipping attribute code

public OgreWidget() : base()
{

root = new Root();
Initialiser.SetupResources("resources.cfg");
root.ShowConfigDialog();

renderWindow = root.Initialise(this.Handle.ToInt32(), 640, 480, false);
// Skipping code that follows
}



I'm getting an error on the initialize function
The error says
15:19:26: GLRenderSystem::createRenderWindow "", 640x480 windowed miscParams: externalWindowHandle=79039736
15:19:26: An exception has been thrown!

-----------------------------------
Details:
-----------------------------------
Error #: 0
Function: Win32Window::create
Description: selectPixelFormat failed.
File: c:\softwaredevelopment\c++\ogresdk\ogrenew_vc80\rendersystems\gl\src\ogrewin32window.cpp
Line: 246

rastaman

01-04-2006 00:35:51

I've been digging though this.. wish i saved the URLs :(
fog was doing work to allow Ogre to render in a Gtk window. He has not posted anything in a while so I gess ill try and email him about this.

I think that Glib.Handle is retruning an IntPtr to the GTK class, in your code a Gtk Container class, not an X11 or Windows handle to a window. in c++ gtk there are functions to get the window handle from that i beleve, not sure what functions. It looks like we will have to create another c++ dll that references GTK and Ogre and can do this work. othere than that one thing, I'm not sure what else may need to be done.

shaft

01-04-2006 07:19:12

I think I'm going to look into the "gdk_window_foreign_new ()" function tomorrow.

It might be possible to let Ogre create the window, and then attach it to the GTK widget.

rastaman

05-04-2006 01:10:53

I'v extracted fog's GtkOgre widget from his project shy. Still a problem on windows :( but we may be able to figure it out.
Now just have to wrapp it.

source


shaft

06-04-2006 21:25:37

Hope you have better luck than I am having.

I'm following the gtk# example for creating custom widgets, and looked at the ogregtk example, and I still have the same problem. How do I get an HWND handle. The gtk C++ library has methods to do this, I can't find anything similar in the C# library.

Ocelot

25-05-2006 22:20:13

Hey Rastaman, thank you for adaptation GTKOgre to windows.
I found two bugs in the code, cause that in test1 example there was no ogre in the window and in all examples, ogre window was notconnected with it's parent window.
in gtk_ogre_bridge_window_create function
instead
params[String("parentWindowHandle")] = handle;
ought to be

params[String("externalWindowHandle")] = handle;

and
instead
rw->getCustomAttribute("GdkNativeWindow", (void*)&xid);
#if defined( __WIN32__ ) || defined( _WIN32 )
rw->getCustomAttribute("HWND", (void*)&xid);
#else
rw->getCustomAttribute("GdkNativeWindow", (void*)&xid);
#endif


Now there is only problem ;) , ogre widget occupy the hole parent window (other child widgets are cover).

rastaman

26-05-2006 18:32:41

Hi Ocelot, thanks for the info. I haven't mested with that project in a while, and probably will not have time this weekend :(.

Now there is only problem Wink , ogre widget occupy the hole parent window (other child widgets are cover).
in linux i had the same problem with widgets. I think it was to create the ogre widget on top and other widgets at bottum, not sure if i tried any other way like with a hbox.

camel69

31-05-2006 00:22:46

Hi all!
@rastaman: i downloaded and compiled your code (i also patched it with ocelot's improvements) but both example programs always create an extra ogre window (i.e. not embedded into gtk), and test1 also fails right after startup:
lt-test1: OgreControllerManager.cpp:41: static Ogre::ControllerManager& Ogre::ControllerManager::getSingleton(): Assertion »ms_Singleton« failed.

i'm trying to code a wxWidgets (2.6.2, using gtk on linux) application with an ogre control inside for hours but it's still not working ... i also tried this piece of code, though it's for windows only (i mixed it with your/shy's code)
what's remarkable: the ogre window's created before the application main frame shows up
is it because i compiled ogre to use SDL?

hope you can help me, i'm also willing to provide some hours of work to help you all :)

Ocelot

23-06-2006 17:03:28

Only one, look at http://www.ogre3d.org/phpBB2/viewtopic.php?p=157786#157786