2011-01-13 4 views
2

XLib를 사용하여 간단한 X 창에 하드 코딩 된 XBM 이미지를 그립니다. 다음 코드를 사용하고 있지만 이미지 대신 창의 왼쪽 위 모서리에 검은 색 사각형 만 나타납니다. 도움?XLib을 사용하여 XBM 그리기, 검정색 사각형 얻기

#include <stdio.h> 
#include <stdlib.h> 
#include <X11/Xlib.h> 

/* From http://commons.wikimedia.org/wiki/File:2008-07-25_Geese_over_00.svg 
    Creative Commons BY-SA */ 
#define goose_width 32 
#define goose_height 31 
static const unsigned char goose_bits[] = { 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x1c, 
    0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x00, 0x80, 0x0f, 
    0x00, 0x00, 0xc0, 0x0f, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 
    0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0xf8, 0x01, 0x00, 0x00, 0xfc, 0x01, 
    0x00, 0x00, 0xfc, 0x01, 0x00, 0x07, 0xfe, 0x01, 0x10, 0x07, 0xff, 0x00, 
    0x78, 0x0e, 0xff, 0x00, 0x80, 0x9f, 0x7f, 0x00, 0x00, 0xfe, 0x3f, 0x00, 
    0x00, 0xfc, 0x1f, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0xf0, 0x0f, 0x00, 
    0x00, 0xe0, 0x3f, 0x00, 0x00, 0x80, 0xff, 0x01, 0x00, 0x00, 0xf8, 0x01, 
    0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
    0x00, 0x00, 0x00, 0x00 }; 

void windowinit(Display *display, Window *window) { 
    int screennum = DefaultScreen(display); 
    long background = WhitePixel(display, screennum); 
    long foreground = BlackPixel(display, screennum); 
    *window = XCreateSimpleWindow(display, DefaultRootWindow(display), 10, 10, 800, 600, 2, foreground, background); 
    XMapRaised(display, *window); 
    XSync(display, False); 

    /* Register for events */ 
    XSelectInput(display, *window, ButtonPressMask|ButtonReleaseMask|ExposureMask|ButtonMotionMask|KeyPressMask); 
} 

int main(void) { 
    Display* display; 
    Window window; 
    GC gc; 
    Pixmap i; 

    /* Open display from $DISPLAY, handle errors */ 
    if(!(display = XOpenDisplay(NULL))) { 
     fprintf(stderr, "Cannot connect to X display\n"); 
     return EXIT_FAILURE; 
    } 

    /* Set up window */ 
    windowinit(display, &window); 

    /* Creat GC, handel errors */ 
    if((int)(gc = XCreateGC(display, window, 0, 0)) < 0) { 
     fprintf(stderr, "XCreateGC: \n"); 
     return EXIT_FAILURE; 
    } 

    /* Draw image -- why does this draw a black rectangle ?? */ 
    i = XCreateBitmapFromData(display, DefaultRootWindow(display), goose_bits, goose_width, goose_height); 
    XCopyPlane(display, i, window, gc, 0, 0, goose_width, goose_height, 0, 0, 1); 

    XSync(display, False); 
    sleep(3); 

    /* Cleanup */ 
    XFreeGC(display, gc); 
    XDestroyWindow(display, window); 
    XCloseDisplay(display); 

    return EXIT_SUCCESS; 
} 

답변

1

이 문제점을 발견했습니다. 전화해야했습니다 :

XSetBackground (display, gc, WhitePixel (display, DefaultScreen (display))));

관련 문제