I can't understand the difference output of only a line differ



Hi,

I tried gdk_draw_image with a small program, but the behavior is very
confusing, please help me find out whats happening.

With the sleep(1) the program shows nothing, but without it the window
will show, why?

Thanks.
Bin

#include <gtk/gtk.h>

main(int argc, char **argv)
{
        int ret;

        gtk_init(&argc, &argv);

        GtkWidget *win;
        GtkWidget *drawing;
        GdkImage *img;
        GdkGC *gc;

        win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        drawing = gtk_drawing_area_new();
        gtk_widget_set_size_request(drawing, 200, 200);
        gtk_container_add(GTK_CONTAINER(win), drawing);
        img = gdk_image_new(GDK_IMAGE_FASTEST, gdk_visual_get_system(),
                        200, 200);

        memset(img->mem, 1, 200 * 200 * 2);

        gtk_widget_show_all(win);

        gc = gdk_gc_new(drawing->window);

        while (1) {
                sleep(1);
                gdk_draw_image(drawing->window, gc, img, 0, 0, 0, 0, 200, 200);
        }

        gtk_main();

}




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