Hi BBB,
I have been spending the last few months writing a game using just XLib on a X11R6 (Irix 6.5) and doing colour in Xlib wasnt very obvious. Basically you will need to allocate a colour map from the xserver before you can switch to any colours.
By far the best way I have seen to do this is by asking the xserver for a colormap using the DefaultColormap() function. After doing this you will need to set the 'window' you are creating to use this colormap, I dont know if XCreateSimpleWindow() automatically uses the default colormap but I use XCreateWindow() which is a bit more drawn out code-wise but is great for doing all the manky bits in one hit :)
Window win; Display* display; XVisualInfo visual_info; int default_screen; int default_depth; Colormap default_cmap; Visual *default_visual; XSetWindowAttributes swa; default_screen = DefaultScreen(display); default_visual = DefaultVisual(display,default_screen); default_depth = DefaultDepth(display,default_screen); default_cmap = DefaultColormap(display,default_screen); visual_info.visual = default_visual; swa.background_pixel = BlackPixel(display,default_screen); swa.event_mask = ExposureMask | StructureNotifyMask | KeyPressMask | ButtonPressMask; swa.colormap = default_cmap; win = XCreateWindow( display, RootWindow(display, visual_info.screen), 0, 0, /* Spawn window at x,y (the xserver knows best) */ WIN_WIDTH, WIN_HEIGHT, 0, /* Border Width (again the xserver knows best) */ visual_info.depth, InputOutput, /* Class (InputOnly/InputOutput) */ visual_info.visual, CWBackPixel|CWEventMask|CWColormap, /* Value Masks */ &swa ); XMapWindow(display, win); XSetForeground(display, gc, WhitePixel(display,visual_info.screen));[...]/*for setting an 'RGB string' colour you will need something like this */XColor fontcolor;if(XParseColor(display, default_cmap, "rgb:EE/00/66", &fontcolor)){ XAllocColor(display, default_cmap,&fontcolor); XSetForeground(display, gc, fontcolor.pixel);} else { printf("failed to allocate colour\n");}
Sorry the code is a bit spotty I just cut bits of it out and removed my error_handling code. This should at least give you an idea of how it works.
I got these two Xlib books and I havent needed to google since :)
XLIB Reference Manual: Release 5.0 v.1XLIB Reference Manual: Release 5.0 v.2Hope this helps.