On Sun, 2007-09-02 at 00:31 +0200, Philipp Klaus Krause wrote: > Murray Cumming schrieb: > > > I guess I'd need to see a complete compileable simple test case to > > figure this out. Here is a self-contained test that uses libglademm and a test that does not, with the build command in a comment at the top of each file. I see that on_realize() is indeed not called when using get_widget_derived(). From the g_warning() about using set_gl_capability() after realize, it seems that the realize signal has already been called before our C++ instance was constructed. That's unusual. However, the default signals are being used in general. I added an on_expose_event() override to show that. You are not the first person to discover this, it seems: http://lists.ximian.com/pipermail/glade-users/2005-March/002430.html And here's a message about the same problem with regular libglade: http://mail.gnome.org/archives/gtk-list/2006-June/msg00065.html which maybe has your solution, though it seems odd. " Solution: don't enable the visible attribute on widgets that you want to catch the realize event and show this widgets manually with your own code " -- murrayc murrayc com www.murrayc.com www.openismus.com
//Build this with: //g++ krause_test.cc `pkg-config libglademm-2.4 gtkglextmm-1.2 --libs --cflags` #include <libglademm.h> #include <gtkglmm.h> class Display : public Gtk::DrawingArea, public Gtk::GL::Widget<Display> { public: Display(BaseObjectType *da, Glib::RefPtr<Gnome::Glade::Xml>& refGlade); protected: void on_realize(); bool on_expose_event(GdkEventExpose* event); }; #include <iostream> #include <GL/gl.h> #include <GL/glu.h> #include <gtkmm/messagedialog.h> Display::Display(BaseObjectType *da, Glib::RefPtr<Gnome::Glade::Xml>& refGlade) : Gtk::DrawingArea(da)//, Gtk::GL::Widget<Display>() { std::cout << "Constructor called." << std::endl; //These don't cause on_realize() to be called either: //signal_realize().connect( sigc::mem_fun (*this, &Display::on_realize), false ); //signal_realize().connect( sigc::mem_fun (*this, &Display::on_realize), true ); Glib::RefPtr<Gdk::GL::Config> glconfig; glconfig = Gdk::GL::Config::create(Gdk::GL::MODE_RGB | Gdk::GL::MODE_DOUBLE); if(!glconfig) { Gtk::MessageDialog e("Couldn't find OpenGL visual.\nPlease ensure that OpenGL drivers are installed correctly.", Gtk::MESSAGE_ERROR); e.run(); } if(!set_gl_capability(glconfig) || !is_gl_capable()) { Gtk::MessageDialog e("Couldn't set OpenGL capability.\nPlease ensure that OpenGL drivers are installed correctly.", Gtk::MESSAGE_ERROR); e.run(); } } void Display::on_realize() { std::cout << "on_realize() called." << std::endl; Gtk::DrawingArea::on_realize(); Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window(); glwindow->gl_begin(get_gl_context()); glClearColor(1.0, 0.0, 0.0, 1.0); glMatrixMode(GL_PROJECTION); glOrtho(-0.5, 0.5, -0.5, 0.5, -0.1, 0.1); glColor3f(1.0f, 0.0f, 0.0f); glDisable(GL_DEPTH_TEST); glwindow->gl_end(); } bool Display::on_expose_event(GdkEventExpose* event) { std::cout << "on_expose_event() called." << std::endl; Gtk::DrawingArea::on_expose_event(event); } #include <iostream> #include <libglademm/xml.h> #include <gtkmm.h> #include <gtkglmm.h> #ifdef ENABLE_NLS # include <libintl.h> #endif /* For testing propose use the local (not installed) glade file */ /* #define GLADE_FILE PACKAGE_DATA_DIR"/ttedit/glade/ttedit.glade" */ #define GLADE_FILE "ttedit.glade" int main (int argc, char *argv[]) { Gtk::Main kit(argc, argv); if(!Gtk::GL::init_check(argc, argv)) { Gtk::MessageDialog e("Couldn't initilize gtkglextmm.\nPlease ensure that OpenGL drivers are installed.", Gtk::MESSAGE_ERROR); e.run(); return(-1); } //Load the Glade file and instiate its widgets: Glib::RefPtr<Gnome::Glade::Xml> refXml; try { refXml = Gnome::Glade::Xml::create(GLADE_FILE); } catch(const Gnome::Glade::XmlError& ex) { std::cerr << ex.what() << std::endl; return 1; } Display *display = 0; refXml->get_widget_derived("display", display); Gtk::Window* main_win = 0; refXml->get_widget("main_window", main_win); if (main_win) { kit.run(*main_win); } return 0; }
//Build this with: //g++ krause_test.cc `pkg-config gtkmm-2.4 gtkglextmm-1.2 --libs --cflags` #include <gtkglmm.h> class Display : public Gtk::DrawingArea, public Gtk::GL::Widget<Display> { public: Display(); protected: void on_realize(); bool on_expose_event(GdkEventExpose* event); }; #include <iostream> #include <GL/gl.h> #include <GL/glu.h> #include <gtkmm/messagedialog.h> Display::Display() { std::cout << "Constructor called." << std::endl; Glib::RefPtr<Gdk::GL::Config> glconfig; glconfig = Gdk::GL::Config::create(Gdk::GL::MODE_RGB | Gdk::GL::MODE_DOUBLE); if(!glconfig) { Gtk::MessageDialog e("Couldn't find OpenGL visual.\nPlease ensure that OpenGL drivers are installed correctly.", Gtk::MESSAGE_ERROR); e.run(); } if(!set_gl_capability(glconfig) || !is_gl_capable()) { Gtk::MessageDialog e("Couldn't set OpenGL capability.\nPlease ensure that OpenGL drivers are installed correctly.", Gtk::MESSAGE_ERROR); e.run(); } //These don't cause on_realize() to be called either: //signal_realize().connect( sigc::mem_fun (*this, &Display::on_realize), false ); //signal_realize().connect( sigc::mem_fun (*this, &Display::on_realize), true ); } void Display::on_realize() { std::cout << "on_realize() called." << std::endl; Gtk::DrawingArea::on_realize(); Glib::RefPtr<Gdk::GL::Window> glwindow = get_gl_window(); glwindow->gl_begin(get_gl_context()); glClearColor(1.0, 0.0, 0.0, 1.0); glMatrixMode(GL_PROJECTION); glOrtho(-0.5, 0.5, -0.5, 0.5, -0.1, 0.1); glColor3f(1.0f, 0.0f, 0.0f); glDisable(GL_DEPTH_TEST); glwindow->gl_end(); } bool Display::on_expose_event(GdkEventExpose* event) { std::cout << "on_expose_event() called." << std::endl; Gtk::DrawingArea::on_expose_event(event); } #include <iostream> #include <gtkmm.h> #include <gtkglmm.h> #ifdef ENABLE_NLS # include <libintl.h> #endif /* For testing propose use the local (not installed) glade file */ /* #define GLADE_FILE PACKAGE_DATA_DIR"/ttedit/glade/ttedit.glade" */ #define GLADE_FILE "ttedit.glade" int main (int argc, char *argv[]) { Gtk::Main kit(argc, argv); if(!Gtk::GL::init_check(argc, argv)) { Gtk::MessageDialog e("Couldn't initilize gtkglextmm.\nPlease ensure that OpenGL drivers are installed.", Gtk::MESSAGE_ERROR); e.run(); return(-1); } Gtk::Window window; Display display; window.add(display); display.show(); kit.run(window); return 0; }
Attachment:
ttedit.glade
Description: application/glade