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

static gboolean
render (GtkGLArea *area, GdkGLContext *context)
{
  glClearColor (0, 0, 0, 0);
  glClear (GL_COLOR_BUFFER_BIT);

  return TRUE;
}

void
button_clicked (GtkButton *button,
                gpointer   user_data)
{
  GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  GtkWidget *gl_area = gtk_gl_area_new ();
  gtk_container_add (GTK_CONTAINER (window), gl_area);
  gtk_widget_show_all (window);
}

int main(int argc, char **argv)
{
  gtk_init (&argc, &argv);

  GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
  GtkWidget *button = gtk_button_new_with_label ("push me");
  GtkWidget *gl_area = gtk_gl_area_new ();
  g_signal_connect (gl_area, "render", G_CALLBACK (render), NULL);
  gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
  gtk_box_pack_start (GTK_BOX (box), gl_area, TRUE, TRUE, 0);
  gtk_container_add (GTK_CONTAINER (window), box);
  gtk_widget_show_all (window);

  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
  g_signal_connect (button, "clicked", G_CALLBACK (button_clicked), window);

  gtk_main ();

  return 0;
}
