Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!hplabs!hpfcso!hpfcdq!brown From: brown@hpfcdq.HP.COM (John Brown) Newsgroups: comp.graphics Subject: Re: Wanted: Example code using DirectColor 24 bit Visual Message-ID: <390055@hpfcdq.HP.COM> Date: 15 Apr 91 14:34:48 GMT References: <1991Apr10.190204.20085@pixar.com> Organization: Hewlett-Packard - Fort Collins, CO Lines: 189 Mark writes . . . > I am having trouble with a current project that requires the use of a > 24 bit directcolor visual under X windows. Everytime I do a XCreateWindow, > I get a XBadMatch error, which I cannot figure out the cause of. (gosh, > leave that preposition dangling). > > The steps I need to do is: > > 1. Use XMatchVisual to decide if a 24 bit visual is available > (it is not my default visual) > 2. Use XCreateWindow to create a window. > 3. Create an XImage to be used with the window. > > If anyone has a simple program or program fragment that you know works, then > please send it to me. I am also open to any hints on how to proceed, as > I am strictly a novice X programmer. > > If it helps, I have tested this on an HP9000 300 series, which supports > X11R3. I thought I'd just post a short example which shows how to create the 24 bit window and gopen it with Starbase. For your needs, you'll want to ignore the Starbase part and add code for the XImage. The code to open the X window will work fine on HP s300 X servers which support the 24 bit DirectColor visual, but I can't promise it will work on other vendors' X servers. Good Luck! John Brown HP Graphics Technology Division This response does not represent the official position of, or statement by, the Hewlett-Packard Company. The above data is provided for informational purposes only. It is supplied without warranty of any kind. ----------------------------------- cut here ---------------------------------- #include #include #include #include /* 24bit.c Sample program to illustrate how to create a 24-bit X window and then gopen it with Starbase. If running on 8.0 or greater, use shared libraries and compile as: cc -o 24bit 24bit.c -DHPUX_80 -L/usr/lib/X11R4 -lXwindow \ -lsb -ldld -lXhp11 -lX11 -lm If running on pre-8.0, compile as (where xxxx is the driver for your display device, e.g. 98731): cc -o 24bit 24bit.c -lddxxxx -lXwindow -lsb1 -lsb2 -lXhp11 -lX11 -lm To run the program on an 8.0 or greater system, simply invoke as "24bit". If running on pre-8.0, either set the SB_OUTDRIVER environment variable first, or invoke as "24bit drivername" (where drivername is the appropriate driver name for your device, e.g. hp98731). ****************************************************************** * This program does not represent the official position of, * * or statement by, the Hewlett-Packard Company. This program * * is provided for informational purposes only. It is supplied * * without warranty of any kind. * ****************************************************************** */ main(argc, argv) int argc; char *argv[]; { Display *display; int screen, fildes; XVisualInfo my_visualinfo; Visual *my_visual; XSetWindowAttributes my_attributes; Window my_window; Colormap my_colormap; XEvent my_event; char *device, *driver, reply[80]; /* Open the X display */ if ( (display = XOpenDisplay(NULL)) == NULL ) { printf("ERROR: Could not open the X display.\n"); printf(" Check the DISPLAY environment variable.\n"); exit(-1); } screen = DefaultScreen( display ); /* Then, see if the desired visual exists. Although this sample program checks specifically for the 24-bit visual, a well-behaved application should really be willing to use other visuals if it can't find the ideal one. */ if ( XMatchVisualInfo(display,screen,24,DirectColor,&my_visualinfo) ) { my_visual = my_visualinfo.visual; } else { printf("ERROR: Could not create a 24-bit DirectColor window.\n"); exit(-1); } /* Next, it is necessary to create a colormap for the window */ my_colormap = XCreateColormap( display, RootWindow(display,screen), my_visual, AllocAll ); /* Finally, we need to specify a few other window attributes so that we can successfully create the 24-bit window */ my_attributes.colormap = my_colormap; my_attributes.border_pixel = 0; my_attributes.background_pixel = 0; my_window = XCreateWindow( display, RootWindow(display,screen), 10,10, 1024, 800, 0, 24, InputOutput, my_visual, CWBorderPixel|CWColormap|CWBackPixel, &my_attributes ); /* Map the window, and wait for the map to occur */ XSelectInput(display, my_window, ExposureMask | StructureNotifyMask ); XMapWindow( display, my_window ); XWindowEvent( display, my_window, ExposureMask, &my_event ); /* Create a device string for a Starbase gopen */ device = make_X11_gopen_string( display, my_window ); /* Now, do the actual gopen. Notice that, beginning with 8.0 (including the initial release on the s700) the actual driver name can be replaced with NULL and the gopen is smart enough to determine the correct driver name. */ #ifdef HPUX_80 /* We're being complied for 8.0 or greater */ fildes = gopen( device, OUTDEV, NULL, INIT ); #else /* We must be on a pre-8.0 system. Try to get the drivername from the arg list if possible, then look for the env var if not in the arg list */ if ( argc > 1 ) driver = argv[1]; else driver = (char *) getenv("SB_OUTDRIVER"); fildes = gopen( device, OUTDEV, driver, INIT ); #endif /* Check to verify that we did indeed open the device correctly. */ if ( fildes >= 0 ) { /* Let the user know about the gopen */ printf("gopen was successful . . . clearing window to red\n"); /* Clear the window to red just to show that we did open it */ shade_mode( fildes, CMAP_FULL|INIT, FALSE ); background_color( fildes, 1.0, 0.0, 0.0 ); clear_view_surface( fildes ); make_picture_current( fildes ); printf("Hit return when finished viewing . . ."); gets( reply ); gclose( fildes ); } else { /* Let the user know about the failure */ printf("ERROR: Could not gopen window with driver '%s'\n", driver ); exit( -1 ); } } /* end of main */