有谁知道如何为gtk / opengl添加三角形?

时间:2015-11-22 23:41:45

标签: c opengl gtk3

我想把opengl放到gtk中。我让我的窗户工作,我有一个gl_area。我试图寻找解决方案,但我只能在我的代码中添加一个带有gl_area的窗口,我似乎无法在窗口中添加一个三角形。这就是我到目前为止所做的。

#include <gtk/gtk.h>
#include <GL/gl.h>
#include <GL/glut.h>


/*This is my setup for opengl, I can only get glClearColor to work.*/
static gboolean render(GtkGLArea *area, GdkGLContext *context)
{
    glClearColor(.1, .1, .1, 1);
    glClear(GL_COLOR_BUFFER_BIT);

    /*This is commented out because it doesn't work.
    glColor3f(.9, .9, .9);
    glBegin(GL_POLYGON);
        glVertex3f(.50, .75, 0);
        glVertex3f(.25, .25, 0);
        glVertex3f(.75, .25, 0);
    glEnd();

    glFlush();
    */

    return TRUE;
}

//This is my gtk setup.
int main(int argc, char *argv[])
{
    GtkWidget *window, *gl_area;

    gtk_init(&argc, &argv);

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Testing");
    gtk_window_set_default_size(GTK_WINDOW(window), 500,500);
    gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    gtk_container_set_border_width(GTK_CONTAINER(window), 10);

    //These two lines setup opengl
    gl_area = gtk_gl_area_new();
    g_signal_connect(gl_area, "render", G_CALLBACK(render), NULL);

    gtk_container_add(GTK_CONTAINER(window), gl_area);
    gtk_widget_show_all(window);
    gtk_main();

    return 0;

}

任何人都可以帮助我,谢谢。

0 个答案:

没有答案