admin管理员组

文章数量:1122832

I can display an interface with buttons in it but when using a GLArea, I can't seem to get it right:

#include "ui.h"
#include <GL/gl.h>
#include <gtk/gtk.h>

static gboolean render (GtkGLArea *area, GdkGLContext *context) {

    glClear(GL_COLOR_BUFFER_BIT);

    // Set the color to red
    glColor3f(1.0f, 0.0f, 0.0f);

    // Draw a square
    glBegin(GL_QUADS);
    glVertex2f(-0.5f, -0.5f);
    glVertex2f( 0.5f, -0.5f);
    glVertex2f( 0.5f,  0.5f);
    glVertex2f(-0.5f,  0.5f);

    glEnd();
    glFlush();

        return TRUE;
}

int start_ui(int argc, char **argv) {
    GtkBuilder *builder;
    GObject *window;
        GError *error = NULL;

    gtk_init (&argc, &argv);

    /* Construct a GtkBuilder instance and load our UI description */
    builder = gtk_builder_new ();
    if (gtk_builder_add_from_file (builder, "builder.ui", &error) == 0) {
        g_printerr ("Error loading file: %s\n", error->message);
        g_clear_error (&error);
        return 1;
    }

        window = gtk_builder_get_object (builder, "window");
        g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);

        gl_area = gtk_gl_area_new ();
        g_signal_connect (gl_area, "render", G_CALLBACK (render), NULL);

    gtk_main ();

    return 0;
}

I also have a builder.ui file:

<interface>
  <object id="window" class="GtkWindow">
    <property name="visible">True</property>
    <property name="title">Grid</property>
    <property name="border-width">10</property>
    <child>
      <object id="grid" class="GtkGrid">
        <property name="visible">True</property>
        <child>
          <object id="glarea" class="GtkGLArea">
        <property name="visible">True</property>
        <property name="width-request">400</property>
        <property name="height-request">300</property>
      </object>
      <packing>
        <property name="left-attach">0</property>
        <property name="top-attach">1</property>
        <property name="width">4</property>
      </packing>
    </child>
    </child>
  </object>
</interface>

My problem is that the output is a black screen as such:

How can I fix this?

本文标签: cOpenGL doesn39t display anything when used with GTKStack Overflow