OpenGL + gtkglextmm +林间空地

发布于 2024-08-14 17:03:32 字数 363 浏览 4 评论 0原文

当我使用“gtkmm”编程时,有一个小部件“Gtk::DrawingArea”
我可以“手动”对该小部件进行编程(因此编写代码),或者更优雅的方式是使用“glade”用户界面设计器,我可以在其中“以图形方式”执行相同的操作嗯>。

现在我尝试通过“gtkglextmm”库将OpenGL与gtkmm连接起来。在该库中,有一个小部件“Gtk::GL::DrawingArea” - 但此小部件“不是”在空地中可用。

那么有没有什么方法可以使用“glade”(对于“图形用户界面”部分)来使用“OpenGL + gtkglextmm”进行编程?

谢谢。

when I am programming with "gtkmm", there is a widget "Gtk::DrawingArea".
I can program that widget "by hand" (so write the code) or more elegant way is to use "glade" user interface designer, where I can do the same "graphically".

Now I am trying to connect OpenGL with gtkmm through "gtkglextmm" library. In that library, there is a widget "Gtk::GL::DrawingArea" - but this widget "IS NOT" available in glade.

So is there any way to program with "OpenGL + gtkglextmm" using "glade" (for the "graphical user interface" part)?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离笑几人歌 2024-08-21 17:03:32

首先,libglade 是一个古老的库。如果您正在编写新项目,请从 gtk builder 开始。

正如您在此处 gtkmm 提供了创建您自己的小部件并(几乎)在 Glade 工具中查看它们的简单方法。您只需将普通的 DrawinArea 小部件插入到窗口中,然后告诉 gtk-builder 将您的派生类放入此位置。

全部内容如下:

设置 gtk-builder:

refBuilder = Gtk::Builder::create_from_file(ui_file);

GlDrawingArea*glArea = NULL;
refBuilder->get_widget_derived("drawing_gl",glArea);

Opengl DrawingArea 类:

 class GlDrawingArea : public Gtk::DrawingArea ,
                       public Gtk::GL::Widget<GlDrawingArea>
 {                   
 public:             
         GlDrawingArea(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder);
         virtual ~GlDrawingArea();
 protected:          
         void on_realize();
         bool on_expose_event(GdkEventExpose* event);
         bool on_configure_event(GdkEventConfigure* event);          
 private:
         Glib::RefPtr<Gtk::Builder> refBuilder;
 };

构造 opengl DrawingArea:

// GlDrawingArea:
GlDrawingArea::GlDrawingArea(BaseObjectType*cobject, const Glib::RefPtr<Gtk::Builder>& builder)
        : Gtk::DrawingArea(cobject),
          refBuilder(builder),
          screen_tex(0)
{                                                                                               
        //
        // Configure OpenGL-capable visual.
        //
        Glib::RefPtr<Gdk::GL::Config> glconfig;

        // Try double-buffered visual
        glconfig = Gdk::GL::Config::create(Gdk::GL::MODE_RGB    |
                                           Gdk::GL::MODE_DEPTH  |
                                           Gdk::GL::MODE_DOUBLE);
        if (!glconfig) {
                std::cerr << "*** Cannot find the double-buffered visual.\n"
                          << "*** Trying single-buffered visual.\n";

                // Try single-buffered visual
                glconfig = Gdk::GL::Config::create(Gdk::GL::MODE_RGB |Gdk::GL::MODE_DEPTH);
                if (!glconfig) {
                        std::cerr << "*** Cannot find any OpenGL-capable visual.\n";
                        std::exit(1);
                }
        }

        // print frame buffer attributes.
        GLConfigUtil::examine_gl_attrib(glconfig);

        //
        // Set OpenGL-capability to the widget.
        //
        set_gl_capability(glconfig);
}

First of all libglade is an old library. If you are writing new project start with gtk builder.

As you can see here gtkmm provide easy way to create your own widgets and see them (almost) in glade tool. You simply insert plain DrawinArea widget to window and then tell gtk-builder to put in this place yours derived class.

Here is all together:

Setting up gtk-builder:

refBuilder = Gtk::Builder::create_from_file(ui_file);

GlDrawingArea*glArea = NULL;
refBuilder->get_widget_derived("drawing_gl",glArea);

Opengl DrawingArea class:

 class GlDrawingArea : public Gtk::DrawingArea ,
                       public Gtk::GL::Widget<GlDrawingArea>
 {                   
 public:             
         GlDrawingArea(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder);
         virtual ~GlDrawingArea();
 protected:          
         void on_realize();
         bool on_expose_event(GdkEventExpose* event);
         bool on_configure_event(GdkEventConfigure* event);          
 private:
         Glib::RefPtr<Gtk::Builder> refBuilder;
 };

Constructing opengl drawingarea:

// GlDrawingArea:
GlDrawingArea::GlDrawingArea(BaseObjectType*cobject, const Glib::RefPtr<Gtk::Builder>& builder)
        : Gtk::DrawingArea(cobject),
          refBuilder(builder),
          screen_tex(0)
{                                                                                               
        //
        // Configure OpenGL-capable visual.
        //
        Glib::RefPtr<Gdk::GL::Config> glconfig;

        // Try double-buffered visual
        glconfig = Gdk::GL::Config::create(Gdk::GL::MODE_RGB    |
                                           Gdk::GL::MODE_DEPTH  |
                                           Gdk::GL::MODE_DOUBLE);
        if (!glconfig) {
                std::cerr << "*** Cannot find the double-buffered visual.\n"
                          << "*** Trying single-buffered visual.\n";

                // Try single-buffered visual
                glconfig = Gdk::GL::Config::create(Gdk::GL::MODE_RGB |Gdk::GL::MODE_DEPTH);
                if (!glconfig) {
                        std::cerr << "*** Cannot find any OpenGL-capable visual.\n";
                        std::exit(1);
                }
        }

        // print frame buffer attributes.
        GLConfigUtil::examine_gl_attrib(glconfig);

        //
        // Set OpenGL-capability to the widget.
        //
        set_gl_capability(glconfig);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文