EGL on X11 only black screen on Linux

I have a strange problem at the moment, I have this sample application using GTK2, OpenGL and EGL. The strange behaviour I describe only happens on nVidia GPUs on Linux with the official nVidia driver. In the program you see a comment, if you dont use glFlush OR glGetError at this point in the code, the code will not draw the triangle, it will only display red (the clear color). If you call glGetError or glFlush, it works.

Can somebody explain to me why this is happening? Here is the code:

#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <EGL/egl.h>
#include <GL/gl.h>

static EGLDisplay egl_display;
static EGLSurface egl_surface;
static EGLContext egl_context;

static void realize_cb (GtkWidget *widget)
    EGLConfig egl_config;
    EGLint n_config;
                            EGL_NONE };
    EGLint surf_attrs[] = {

    egl_display = eglGetDisplay ((EGLNativeDisplayType) gdk_x11_display_get_xdisplay (gtk_widget_get_display (widget)));
    eglInitialize (egl_display, NULL, NULL);
    eglChooseConfig (egl_display, attributes, &egl_config, 1, &n_config);
    egl_surface = eglCreateWindowSurface (egl_display, egl_config, GDK_WINDOW_XID (gtk_widget_get_window (widget)), NULL);
    eglBindAPI (EGL_OPENGL_API);   
    egl_context = eglCreateContext (egl_display, egl_config, EGL_NO_CONTEXT, NULL);
    eglMakeCurrent(egl_display, egl_surface, egl_surface, egl_context);
    printf("GL Version: %s\n", glGetString(GL_VERSION));

static gboolean on_configure (GtkWidget *widget, GdkEvent *event, gpointer user_data)
    return FALSE;

static gboolean draw_cb (GtkWidget *widget, GdkEventExpose *expose, gpointer userdata)
    eglMakeCurrent (egl_display, egl_surface, egl_surface, egl_context);

    GtkAllocation alloc;
    gtk_widget_get_allocation(widget, &alloc);
    glViewport (0, 0, alloc.width, alloc.height);

    glClearColor (1, 0, 0, 1);
    glClear (GL_COLOR_BUFFER_BIT);

    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    glOrtho (0, 100, 0, 100, 0, 1);

    glBegin (GL_TRIANGLES);
    glColor3f (1, 0, 0);
    glVertex2f (50, 10);
    glColor3f (0, 1, 0);
    glVertex2f (90, 90);
    glColor3f (0, 0, 1);
    glVertex2f (10, 90);
    glEnd ();

     * It does not matter if you call glGetError or glFlush here, if you do, it
     * works, if not, it only displays a red surface
    eglSwapBuffers (egl_display, egl_surface);

    return TRUE;

int main (int argc, char **argv)
    GtkWidget *w;

    gtk_init (&argc, &argv);

    w = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_double_buffered (GTK_WIDGET (w), FALSE);
    g_signal_connect_after (G_OBJECT (w), "realize", G_CALLBACK (realize_cb), NULL);
    g_signal_connect (G_OBJECT (w), "expose-event", G_CALLBACK (draw_cb), NULL);
    g_signal_connect (G_OBJECT (w), "configure-event", G_CALLBACK (on_configure), NULL);
    gtk_widget_show (w);

    gtk_main ();

    return 0;

Compile with:

g++ -o gtkegl -lEGL -lGL $(pkg-config --libs --cflags gtk+-2.0) -lX11

Its been over a month now without any reaction from nvidia, this is really sad. This was confirmed by many people by now in my company, at stackoverflow and a few fellas in some development IRC channels. This seems to be a bug in the nvidia driver, as this code runs very niceley with all other video cards and with the nouveau driver.