gpt4 book ai didi

c - Gtk+ 和 OpenGL 绑定(bind)

转载 作者:太空狗 更新时间:2023-10-29 15:03:02 25 4
gpt4 key购买 nike

简单而简短:最先进的 GTK+ OpenGL 绑定(bind)是什么?我更喜欢一个允许我使用它类似于 QGLWidget 的小部件。

注意:我偶然发现了 gtkglext、gtkglarea 和 clutter。我读到前两个有缺点/严重问题。

最佳答案

更新:

Gtk+-3.16 以后,使用以下任何内容!

如果你想使用当前最先进的顶点/像素着色器,你应该使用最新的 gnome 并依赖它的 caps:

广泛涵盖在 https://www.bassi.io/articles/2015/02/17/using-opengl-with-gtk/


好的,我在过去的 2 个小时里读了很多东西,我的结果是:

  • gtkglext 将后端完全替换为 OpenGL,这不是我的本意
  • clutter 将所有 native gl 调用封装到对象中并且根本不支持 native gl 调用,尽管它提供了许多预定义的过滤器和有趣的东西
  • gtkglarea 看起来不错,它的设计很可爱。它与Qt中的QGLWidget的使用风格相同(据我所知)simple demo of gtkglarea :

    #include <math.h>
    #include <gtk/gtk.h>
    #include <GL/gl.h>
    #include <gtkgl/gtkglarea.h>

    int init (GtkWidget *widget)
    {
    if (gtk_gl_area_make_current (GTK_GL_AREA(widget)))
    {
    glViewport(0,0, widget->allocation.width, widget->allocation.height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0,100, 100,0, -1,1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    }

    return TRUE;
    }

    int draw (GtkWidget *widget, GdkEventExpose *event)
    {
    if (event->count > 0) return TRUE;

    if (gtk_gl_area_make_current (GTK_GL_AREA(widget)))
    {
    glClearColor(0,0,0,1);
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1,1,1);
    glBegin(GL_TRIANGLES);
    glVertex2f(10,10);
    glVertex2f(10,90);
    glVertex2f(90,90);
    glEnd();
    gtk_gl_area_swap_buffers (GTK_GL_AREA(widget));
    }

    return TRUE;
    }

    int reshape (GtkWidget *widget, GdkEventConfigure *event)
    {
    if (gtk_gl_area_make_current (GTK_GL_AREA(widget)))
    glViewport(0,0, widget->allocation.width, widget->allocation.height);

    return TRUE;
    }

    int main (int argc, char **argv)
    {
    GtkWidget *window, *glarea;

    int attrlist[] = {
    GDK_GL_RGBA,
    GDK_GL_RED_SIZE,1,
    GDK_GL_GREEN_SIZE,1,
    GDK_GL_BLUE_SIZE,1,
    GDK_GL_DOUBLEBUFFER,
    GDK_GL_NONE };

    gtk_init (&argc, &argv);
    if (gdk_gl_query () == FALSE) return 0;

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW(window), "Simple");
    gtk_container_set_border_width (GTK_CONTAINER(window), 10);
    g_signal_connect (window, "delete_event",
    G_CALLBACK (gtk_main_quit), NULL);

    /* You should always delete gtk_gl_area widgets before exit or else
    GLX contexts are left undeleted, this may cause problems (=core dump)
    in some systems.
    Destroy method of objects is not automatically called on exit.
    You need to manually enable this feature. Do gtk_quit_add_destroy()
    for all your top level windows unless you are certain that they get
    destroy signal by other means. */

    gtk_quit_add_destroy (1, GTK_OBJECT(window));

    glarea = GTK_WIDGET(gtk_gl_area_new (attrlist));
    gtk_widget_set_size_request (GTK_WIDGET(glarea), 100, 100);

    gtk_widget_set_events (GTK_WIDGET(glarea), GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK);

    g_signal_connect (glarea, "expose_event", G_CALLBACK(draw), NULL);
    g_signal_connect (glarea, "configure_event", G_CALLBACK(reshape), NULL);
    g_signal_connect (glarea, "realize", G_CALLBACK(init), NULL);

    gtk_container_add (GTK_CONTAINER(window), GTK_WIDGET(glarea));
    gtk_widget_show (GTK_WIDGET(glarea));
    gtk_widget_show (GTK_WIDGET(window));

    gtk_main ();
    return 0;
    }

注意:gtkglarea 仍然存在一些问题,例如退出时的核心转储(至少 1.99)

注2:2.0.1版本修复了这个问题

编辑:对于那些寻求 2D 的人来说,只有 cairo 似乎是最合适的。

关于c - Gtk+ 和 OpenGL 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3815806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com