Murray Cumming schrieb:
> I guess I'd need to see a complete compileable simple test case to
> figure this out.
I really think this is a problem of me not understanding how to use a
derived widget. In main():
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;
}
The get_widget_derived() calls created a widget of type Display, I want
it to be used as the widget called "display" in main_window, but it
seems there's something else in main_window (probably an ordinary
Gtk::DrawingArea).
I've gzipped the Makefile so it will make it to the list (40KB limit).
#include "display.h"
#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::cout.flush();
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(void)
{
std::cout << "\non_realize() called.";
std::cout.flush();
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();
}
#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);
void on_realize(void);
};
#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"
#include "display.h"
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;
}
Attachment:
Makefile.gz
Description: GNU Zip compressed data
Attachment:
ttedit.glade
Description: application/glade