Path: utzoo!attcan!uunet!lll-winken!ames!mailrus!tut.cis.ohio-state.edu!bloom-beacon!ANDREW.CMU.EDU!yt07+ From: yt07+@ANDREW.CMU.EDU (Yin-Cheng Tsai) Newsgroups: comp.windows.x Subject: Question about colormap!! Message-ID: Date: 31 Jan 89 23:08:06 GMT Sender: daemon@bloom-beacon.MIT.EDU Organization: The Internet Lines: 98 Hi, folks, Could someone help me to find the bug in my code? I tried to make some exercises on Colormap, nevertheless, I got an unsolvable problem. If I use the default colormap, everything is going very fine. However, if I create the colormap with the default visual, the XStoreNamedColor seems not working. Thanks for any comment and suggestion. -- yin-cheng ##----------------- tst.c start from here -------------------## #include #include #define NPLANES 1 #define NCOLORS 4 main () { unsigned long plane_mask[NPLANES], pixels[NCOLORS], pixel; Display *display; XColor color; Window simple; Colormap cmap; int flag = 0; GC gc; if (!(display = XOpenDisplay (NULL))) { fprintf (stderr, "cannot open display\n"); exit (-1); } simple = XCreateSimpleWindow (display, DefaultRootWindow (display), 100, 100, 300, 300, 2, 0); ==> cmap = DefaultColormap (display, DefaultScreen (display)); ==>/* cmap = XCreateColormap (display, simple, DefaultVisual (display, DefaultScreen (display)), AllocNone); XSetWindowColormap (display, simple, cmap);*/ color.red = 255 << 8; color.green = 0; color.blue = 0; if (!XAllocColor (display, cmap, &color)) fprintf (stderr, "allocation error\n"); color.red = 0; color.green = 255 << 8; color.blue = 0; if (!XAllocColor (display, cmap, &color)) fprintf (stderr, "allocation error\n"); color.red = 0; color.green = 0; color.blue = 255 << 8; if (!XAllocColor (display, cmap, &color)) fprintf (stderr, "allocation error\n"); if (!XAllocColorCells (display, cmap, False, plane_mask, NPLANES, pixels, NCOLORS)) { fprintf (stderr, "cannot allocate any color cell\n"); exit (-1); } pixel = pixels[0]; gc = XCreateGC (display, simple, 0, NULL); XSetForeground (display, gc, pixel); XMapWindow (display, simple); XFlush (display); sleep (5); /* window must come up before next drawing command is executed */ XFillRectangle (display, simple, gc, 50, 50, 200, 200); XFlush (display); fprintf (stderr, "press '^C' to exit! "); fflush (stderr); while (1) { if (flag) { flag = 0; XStoreNamedColor (display, cmap, "gold", pixel, ~0); XFlush (display); sleep (1); } else { flag = 1; XStoreNamedColor (display, cmap, "navy", pixel, ~0); XFlush (display); sleep (1); } } }