Hi again! I figured it out in the meanwhile! Here is the new code. Seems
that whatever I do, the GDK_EXPOSE event is never received, even if I set
the proper event mask (or all events mask). This is a GDK issue, I guess,
not glext. Also, I'll have to figure out a way to make the events block.
Right now it uses up 100% cpu, cause the event function is non-blocking.
Someone said I'll have to use a glib main loop.

Thanks! Hope this helps someone. It just displays a white rectangle on an
orange background.

#include <stdlib.h>
#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 = GDK_KEY_PRESS_MASK | GDK_STRUCTURE_MASK;
        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);

        gdk_window_show(win);

        GdkGLWindow *glwin = NULL;
        GdkGLContext *glcontext = NULL;
        glwin = gdk_window_set_gl_capability(win, glc, NULL);
        glcontext = gdk_gl_context_new(GDK_GL_DRAWABLE(glwin), NULL, true,
GDK_GL_RGBA_TYPE);
        printf("glwin=%p glcontext=%p\n", glwin, glcontext);

        bool done = false;
        while(!done) {
                GdkEvent *ev = gdk_event_get();
                if(ev) {
                        switch(ev->type) {
                                case GDK_MAP:
                                        break;
                                case GDK_DELETE:
                                        done = true;
                                        break;
                                case GDK_KEY_PRESS:
                                        printf("key pressed\n");
                                        break;
                                case GDK_EXPOSE:
                                        printf("got expose\n");
                                        break;
                                case GDK_CONFIGURE:

if(gdk_gl_drawable_gl_begin(gdk_window_get_gl_drawable(win), glcontext)) {
                                                glViewport(0, 0,
ev->configure.width, ev->configure.height);

if(gdk_gl_drawable_is_double_buffered(gdk_window_get_gl_drawable(win))) {

gdk_gl_drawable_swap_buffers(gdk_window_get_gl_drawable(win));
                                                } else
                                                        glFlush();

gdk_gl_drawable_gl_end(gdk_window_get_gl_drawable(win));
                                        }
                                        break;
                        }

if(gdk_gl_drawable_gl_begin(gdk_window_get_gl_drawable(win), 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();


if(gdk_gl_drawable_is_double_buffered(gdk_window_get_gl_drawable(win))) {

gdk_gl_drawable_swap_buffers(gdk_window_get_gl_drawable(win));
                                                } else
                                                        glFlush();

gdk_gl_drawable_gl_end(gdk_window_get_gl_drawable(win));
                                        }
                        gdk_event_free(ev);
                }
        }

        gdk_gl_window_destroy(glwin);
        gdk_window_destroy(win);

        return 0;
}



On Wed, Jul 22, 2009 at 5:08 AM, Mihai Draghicioiu <
[email protected]> wrote:

> 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;
> }
>
>
_______________________________________________
gtkglext-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtkglext-list

Reply via email to