Re: retrieve user input in child widget embedding Ogre



OK, I eventually got my Ogre + Gtk app to work. For those interested, have a look at the GtkOgre app on the Ogre wiki, and replace gtk_ogre_realize() with this version (which creates a GdkWindow first, then passes it as external window handle to Ogre when creating the RenderWindow) :

static void gtk_ogre_realize(GtkWidget *widget)
{
  GtkOgre* ogre;

  g_return_if_fail(widget != NULL);
  g_return_if_fail(GTK_IS_OGRE(widget));

  ogre = GTK_OGRE(widget);

  g_return_if_fail(ogre->mRenderWindowName != NULL);
  g_return_if_fail(ogre->mRenderWindow == NULL);

  GdkWindow* parent = gtk_widget_get_parent_window(widget);

  //Create the GdkWindow:
  GdkWindowAttr attributes;
  memset(&attributes, 0, sizeof(attributes));

  //Set initial position and size of the Gdk::Window:
  attributes.x = widget->allocation.x;
  attributes.y = widget->allocation.y;
  attributes.width = widget->allocation.width;
  attributes.height = widget->allocation.height;

  //Set event mask as needed here
  attributes.event_mask = GDK_ALL_EVENTS_MASK;
  attributes.window_type = GDK_WINDOW_CHILD;
  attributes.wclass = GDK_INPUT_OUTPUT;

GTK_WIDGET_UNSET_FLAGS(widget, GTK_NO_WINDOW); widget->window = GDK_DRAWABLE(gdk_window_new(parent, &attributes, GDK_WA_X | GDK_WA_Y));

  Ogre::NameValuePairList params;
params["externalWindowHandle"] = Ogre::StringConverter::toString((unsigned long)GDK_WINDOW_HWND(widget->window));

ogre->mRenderWindow = Ogre::Root::getSingleton().createRenderWindow("GtkOgreWidget" + Ogre::StringConverter::toString(++s_wid), widget->allocation.width, widget->allocation.height, false, &params); gtk_widget_set_double_buffered(widget, FALSE);
  gdk_window_set_user_data(widget->window, G_OBJECT(widget));
  gdk_window_set_back_pixmap(widget->window, NULL, FALSE);

  /* Set realized flag */
  GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
}

Also, see this thread for details : http://www.ogre3d.org/phpBB2/viewtopic.php?t=21731&postdays=0&postorder=asc&start=0

Vincent Delannoy a écrit :
Hi,

I'm looking for a way to embed an Ogre3D visualisation in a GTK child widget while still being able to receive keyboard/mouse events in such a widget.

The ogre-gtk example app from the Ogre wiki successfully displays Ogre in child widgets, but for some reason, events can't be received anymore, despite gtk-signal-connect'ing them, as well as setting GDK_ALL_EVENTS_MASK on these widgets

There must be a way around this problem since I know it to be working with GTKmm.

Does anyone have suggestions/sample code regarding this issue?





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]