about XWindow programming

Started by
0 comments, last by gyh 22 years, 5 months ago
How can I create a window with 24 depth in color . I have tried the following code , but it doesn't work. who can help me!!!! " /* ---- XGraph.c ---- */ #include #include #include #include main() { Display *display; Window window; XSetWindowAttributes attr; Colormap colormap; XGCValues gcvalue; GC gc; XSizeHints *sz; unsigned long lBlackPixel, lWhitePixel; int i; XColor color; int depth, class; XVisualInfo visulInfo; Status stat; display = XOpenDisplay("0:0"); //create true color colormap depth = 24; class = TrueColor; stat = XMatchVisualInfo( display, DefaultScreen(display), depth, class , &visulInfo ); if( 0 == stat ) printf("could not create true color visual !!!\n"); colormap = XCreateColormap( display, XDefaultRootWindow(display), visulInfo.visual, AllocNone); lBlackPixel = BlackPixel( display, DefaultScreen(display) ); lWhitePixel = WhitePixel( display, DefaultScreen(display) ); /* build and set window attribute */ attr.background_pixel = lWhitePixel; /* background color */ window = XCreateWindow(display, XDefaultRootWindow(display), 100, 100, 300, 300, 8, visulInfo.depth, InputOutput, visulInfo.visual, CWBackPixel, &attr); XStoreName(display, window, "hello!! world!!"); /* show */ printf("Map window\n"); XMapWindow(display, window); XFlush(display); /* build and set GC */ gc = XCreateGC(display, window, 0, &gcvalue); XSetForeground(display, gc, lBlackPixel); XSetBackground(display, gc, lWhitePixel); XSetLineAttributes(display, gc, 1, LineSolid, CapButt, JoinRound); for( i = 0 ; i < 256 ; i ++ ) { color.red = 0; color.green = i * 256 ; color.blue = 0; color.flags = DoRed | DoGreen | DoBlue; stat = XAllocColor( display , colormap, &color ); if( 0 == stat ) { printf("error alloc color for %d \n",i ); continue; } XSetForeground( display, gc, color.pixel ); XDrawLine( display , window, gc , i , 0 , i , 300 ); } XFlush(display); getchar(); /* close window */ printf("Destory Window\n"); XDestroyWindow(display, window); XFlush(display); printf("close display\n"); XCloseDisplay(display); //getchar(); } /* how to compile gcc -o XTest XTest.c -L/usr/X11R6/lib -lX11 */ Edited by - gyh on November 1, 2001 7:05:22 AM
Advertisement
You can change between the resolutions that you have in your XF86Config file but I do not think that you can change color depth. If this is in the config file does X starts in 24 bit colors
DefaultDepth 24
Subsection "Display"
Depth 24
Modes "1024x768" "800x600" "640x480"
EndSubSection

This topic is closed to new replies.

Advertisement