slg3x@cc.usu.edu (04/09/91)
Hi X-folks, Could you take a look my portion of codes? I can not draw the color I want; I just got all "white" color. Did I make some mistake in somewhere? I wonder I didn't create a correct colormap. I used the following method to create pallete (colormap). Does it has anything wrong? Please mail to me directly. Thanks in advance. Kchen kchen@nit.cs.usu.edu --------------------------------------------------------------------------- vTemplate.screen = myscreen; vTemplate.colormap_size = 256; vTemplate.depth = 8; visualList = XGetVisualInfo (mydisplay, VisualScreenMask | VisualDepthMask, &vTemplate, &visualsMatched); if ((visualsMatched == 0) && (visualList != NULL)) { printf("FATAL ERROR\n"); exit(0); } /* Set up window attributes */ attributes.background_pixel = mybackground; attribute_mask = CWBackPixel | CWBorderPixel | CWEventMask; /* colormap creation */ colormap1 = XCreateColormap (mydisplay, RootWindow(mydisplay, myscreen), visualList[0].visual, AllocNone); /* allocate four colors in palette and each color has 65 indexes */ if (XAllocColorCells(mydisplay, colormap1, True, NULL, 0, cells, 256)) { /* pink */ color[0].red = 62207; color[0].green = 9; color[0].blue = 8351; color[0].flags = DoRed | DoGreen | DoBlue; for (i = 0; i < 65; i++) { color[i].pixel = cells[i]; color[i].red -= 971.984375; color[i].green -= 0.140625; color[i].blue -= 130.484375; color[i].flags = DoRed | DoGreen | DoBlue; } ... ... ... color[193].red = 2047; color[193].green = 65535; color[193].blue = 17477; color[193].flags = DoRed | DoGreen | DoBlue; for (i = 193; i < 256; i++) { color[i].pixel = cells[i]; color[i].red -= 31.984375; color[i].green -= 1023.9844; color[i].blue -= 273.078125; color[i].flags = DoRed | DoGreen | DoBlue; } XStoreColors(mydisplay, colormap1, color, 256);*/ XSetWindowColormap(mydisplay, mywindow, colormap1); XFree(visualList); } else printf("Warnning: Couldn't allocate color cells\n"); ... ... .. /* test what's the color looking */. for (i = 0; i < 256; i++) { XSetForeground(mydisplay, mygc, color[i].pixel); for (k = 0; k < 3; k++) for (j = 0; j < 256; j++) XDrawPoint(mydisplay, mywindow, mygc, m+k, j); m += 3; }