[GtkGLExt] GDK + gtkglext help



Hi guys! I'm trying to make a basic program that just displays a quad, but all I get is a black window. Here is my code. Not sure what I'm doing wrong. I don't want to use GTK+. I wasn't able to find working GDK + GTKGLExt code in the examples.

#include <gdk/gdk.h>
#include <gdk/gdkgl.h>
#include <GL/gl.h>

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

        int config_attributes[] = {
                GDK_GL_DOUBLEBUFFER,
                GDK_GL_RGBA,
                GDK_GL_RED_SIZE,        1,
                GDK_GL_GREEN_SIZE,      1,
                GDK_GL_BLUE_SIZE,       1,
                GDK_GL_DEPTH_SIZE,      12,
                GDK_GL_ATTRIB_LIST_NONE
        };
        GdkGLConfig *glc = gdk_gl_config_new(config_attributes);

        GdkWindowAttr attr;
        attr.title = argv[0];
        attr.event_mask = 0;
        attr.window_type = GDK_WINDOW_TOPLEVEL;
        attr.wclass = GDK_INPUT_OUTPUT;
        attr.width = 800;
        attr.height = 600;
        GdkWindow *win = gdk_window_new(NULL, &attr, 0);

        GdkGLWindow *glwin = gdk_gl_window_new(glc, win, NULL);
        GdkGLContext *glcontext = gdk_gl_context_new(GDK_GL_DRAWABLE(glwin), NULL, true, GDK_GL_RGBA_TYPE);

        gdk_window_show(win);

        bool done = false;
        while(!done) {
                GdkEvent *ev = gdk_event_get();
                if(ev) {
                        switch(ev->type) {
                                case GDK_MAP:
                                        gdk_gl_drawable_make_current(GDK_GL_DRAWABLE(glwin), glcontext);
                                        break;
                                case GDK_DELETE:
                                        done = true;
                                        break;
                                case GDK_EXPOSE:
                                        gdk_gl_drawable_gl_begin(GDK_GL_DRAWABLE(glwin), glcontext);
                                        glClearColor(1.0, .5, .2, 1.0);
                                        glClear(GL_COLOR_BUFFER_BIT);
                                        glMatrixMode(GL_PROJECTION);
                                        glLoadIdentity();
                                        glOrtho(0, 800, 600, 0, -1, 1);
                                        glMatrixMode(GL_MODELVIEW);
                                        glLoadIdentity();
                                        glBegin(GL_QUADS);
                                        glVertex2i(100, 100);
                                        glVertex2i(400, 100);
                                        glVertex2i(400, 500);
                                        glVertex2i(100, 500);
                                        glEnd();
                                        gdk_gl_drawable_swap_buffers(GDK_GL_DRAWABLE(glwin));
                                        gdk_gl_drawable_gl_end(GDK_GL_DRAWABLE(glwin));
                                        break;
                        }
                        gdk_event_free(ev);
                }
        }

        gdk_gl_window_destroy(glwin);
        gdk_window_destroy(win);

        return 0;
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]