如何在EGL中使用gtkmm [英] How to use gtkmm with EGL

查看:96
本文介绍了如何在EGL中使用gtkmm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现博客文章一个有关如何在GTK中使用EGL的示例.但是我在项目上使用了gtkmm,因此我需要找到如何处理它的方法

I found this blog post that has an example on how to use EGL with GTK. However I use gtkmm on my project, therefore I need to find how to do things with it

我需要找到以下功能:

gdk_x11_display_get_xdisplay
gtk_widget_get_display
gdk_x11_window_get_xid
gtk_widget_get_window
gtk_widget_get_allocated_width
gtk_widget_get_allocated_height

gtkmm上的

.他们的gtkmm可能会返回类实例,所以我需要弄清楚如何获得这些类指向的C对象

on gtkmm. Their gtkmm probably return class instances, so I need to figure out how to get the C object these classes point to as well

如果我们看看GTK函数,让我们看一个示例:

If we look at the GTK functions, let's see an example:

Display*    gdk_x11_display_get_xdisplay ()

它返回一个Display*.同时,在用于显示的 gtkmm 中,我们看到gobj()返回了C对象GdkDisplay*:

It returns a Display*. Meanwhile, in the gtkmm for Display we see that gobj() returns the C object GdkDisplay*:

GdkDisplay*     gobj ()

这不是同一对象.

那么,如何找到这些函数的gtkmm版本?

So, how to find the gtkmm versions of these functions?

UPDATE2:

根据评论中的建议,我做了一个最小的可重现示例:

based on the suggestions in the comment, I made a minimal reproducible example:

#include <iostream>
#include <gtkmm.h>
#include <epoxy/gl.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GL/gl.h>
class MyOpenGLArea : public Gtk::Window
{
public:
    MyOpenGLArea()
    {
        set_title("Test");
        set_default_size(640, 360);

        add(vBox);

        glArea.set_hexpand(true);
        glArea.set_vexpand(true);
        glArea.set_auto_render(true);
        vBox.add(glArea);

        glArea.signal_realize().connect(sigc::mem_fun(*this, &MyOpenGLArea::realize));
        glArea.signal_render().connect(sigc::mem_fun(*this, &MyOpenGLArea::render), false);

        glArea.show();
        vBox.show();
    };

public:
    Gtk::GLArea glArea;
    Gtk::Box vBox{Gtk::ORIENTATION_VERTICAL, false};

    void realize()
    {
        EGLBoolean eglStatus;
        EGLConfig eglConfig;
        EGLint n_config;
        EGLint context_attribs[] = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE};

        eglDisplay = eglGetDisplay((EGLNativeDisplayType)gdk_x11_display_get_xdisplay(glArea.get_display()->gobj()));

        eglStatus = eglInitialize(eglDisplay, NULL, NULL);
        if (!eglStatus)
        {
            printf("Error at eglInitialize\n");
            switch (eglStatus)
            {
            case EGL_BAD_DISPLAY:
                printf("EGL_BAD_DISPLAY\n");
                break;
            case EGL_NOT_INITIALIZED:
                printf("EGL_NOT_INITIALIZED\n");
                break;
            case EGL_FALSE:
                printf("EGL_FALSE\n");
                break;
            }
        }
        eglStatus = eglChooseConfig(eglDisplay, context_attribs, &eglConfig, 1, &numConfigs);
        if (!eglStatus)
        {
            printf("Error at eglChooseConfig\n");
            switch (eglStatus)
            {
            case EGL_BAD_DISPLAY:
                printf("EGL_BAD_DISPLAY\n");
                break;
            case EGL_BAD_ATTRIBUTE:
                printf("EGL_BAD_ATTRIBUTE\n");
                break;
            case EGL_NOT_INITIALIZED:
                printf("EGL_NOT_INITIALIZED\n");
                break;
            case EGL_BAD_PARAMETER:
                printf("EGL_BAD_PARAMETER\n");
                break;
            case EGL_FALSE:
                printf("EGL_FALSE\n");
                break;
            }
        }
    };

    virtual bool render(const Glib::RefPtr<Gdk::GLContext> &context)
    {
        glDraw();
        glFinish();
        return true;
    }

    void glDraw()
    {
    }

private:
    EGLDisplay eglDisplay;
    EGLSurface eglSurface;
    EGLContext eglContext;
    int numConfigs;
};

int main(int argc, char **argv)
{
    auto app = Gtk::Application::create(argc, argv, "");
    MyOpenGLArea myOpenGLArea;
    return app->run(myOpenGLArea);
}

这是输出:

libEGL warning: DRI2: failed to authenticate
Error at eglChooseConfig
EGL_FALSE

显示的内容仍然不正确

推荐答案

我需要找到以下功能:

I need to find these functions:

gdk_x11_display_get_xdisplay
gtk_widget_get_display
gdk_x11_window_get_xid
gtk_widget_get_window
gtk_widget_get_allocated_width
gtk_widget_get_allocated_height

在gtkmm上.

其中一些在gtkmm中具有易于查找的包装器.毕竟有一个命名系统.一个名为"gtk_<thing>_<action>"的GTK函数通常对应于Gtk命名空间–中(大写的)<Thing>类的<action>方法.即Gtk::<Thing>::<action>.

Some of these have easy-to-find wrappers in gtkmm. There is a naming system in place, after all. A GTK function named "gtk_<thing>_<action>" usually corresponds to the <action> method of the (capitalized) <Thing> class in the Gtk namespace – i.e. Gtk::<Thing>::<action>.

留下X11交互.我不知道GDK的"x11"部分有C ++包装器,因此您可能需要混合使用C和C ++ API .只是要注意几个类似名称的类.例如,Gtk::WindowGdk::Window是不同的类.另外,Display(无命名空间)和GdkDisplay是不同的类. (尤其是Display既不是GTK也不是GDK的一部分;它不是X11的一部分.)

That leaves the X11 interaction. I am not aware of a C++ wrapper for the "x11" portion of GDK, so you might need to mix C and C++ APIs. Just be aware of several similarly-named classes. For example, Gtk::Window and Gdk::Window are distinct classes. Also, Display (without a namespace) and GdkDisplay are distinct classes. (In particular, Display is not part of GTK nor of GDK; it is part of X11.)

基于系统的工作方式(这意味着我尚未测试),以下几行应该是从gtkmm调用GDK的X11交互功能的一种方式.这些假设变量已声明为Gtk::GLArea glArea,例如示例代码中的数据成员.

Based on how the system is supposed to work (meaning that I have not tested this), the following lines should be a way to invoke GDK's X11 interaction functions from gtkmm. These assume a variable has been declared as Gtk::GLArea glArea, such as the data member from the example code.

gdk_x11_display_get_xdisplay(glArea.get_display()->gobj());
gdk_x11_window_get_xid(glArea.get_window()->gobj());

get_display方法返回指向Gdk::Display的智能指针.调用指向对象的 gobj 方法会给出,然后可以将其输入到gdk_x11_display_get_xdisplay.同样,get_window返回指向Gdk::Window的智能指针,该指针可以转换为指向gdk_x11_window_get_xid的C对象的指针.

The get_display method returns a smart pointer to a Gdk::Display. Calling the pointed-to object's gobj method gives a GdkDisplay* which could then be fed to gdk_x11_display_get_xdisplay. Similarly, get_window returns a smart pointer to a Gdk::Window, which can be converted to a pointer to the C object for gdk_x11_window_get_xid.

这篇关于如何在EGL中使用gtkmm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆