[comp.windows.x] Problem with GXxor Function???

steve@wizard.UUCP (Steve Mansour) (09/23/89)

Hello,

I have a small program that works with some X servers and not
with others.  I'm not sure what I'm doing wrong.  It involves 
setting the graphics context function to GXxor mode.  Once the 
GXxor mode is set, the program draws some rectangles.  The 
rectangles appear when we direct the output to the X servers
for the following machines:
		MIT's for the Sun 4/260
		xnews  (pre-FCS)
		Solbourne 4/600
		MAC IIx AUX 1.1
Nothing appears when we send the output to the servers for these
machines:
		DEC 3100
		Apollo DN4500 (SR10.2)
		a PC Clone (ISC Unix 2.0)

Essentially, the program is as follows:

    {
      // create a window, create a gc
      // set foreground to black and background to white

      XSetFunction( display, gc, GCxor );
      // draw some rectangles
      // wait
    }

What am I forgetting????

Any help would be greatly apprecicated.

Steve Mansour

rws@EXPO.LCS.MIT.EDU (Bob Scheifler) (09/25/89)

    What am I forgetting????

That not all pixel values are created equal.  You haven't said what the
foreground value in the GC is, or what the pixel values in the window are.
My guess is that you've forgotten that WhitePixel and BlackPixel (or
any other pixel, for that matter) can be arbitrary values, e.g. either
one can be zero, and zero doesn't xor too well.

If you have two pixel values F and B and you want xor to work, set the
foreground value in the GC to (F^B).  Try reading the color chapter
in the O'Reilly books (or look at the excerpt in R3 in doc/tutorials).

tom@elan.elan.com (Tom Smith) (09/26/89)

From article <521@wizard.UUCP>, by steve@wizard.UUCP (Steve Mansour):
[ Sample program using GXxor function that sometimes works removed ]
> What am I forgetting????

You are forgetting that the server released from MIT is considered
a "sample" X11 server, and that it is supposedly meant to be an
illustration of how vendors could go about writing their own.  It
was apparently not intended to be product-quality itself, because
it has quite a few bugs in it -- particularly the R2 version.  This
means that if your favorite vendor merely ported the MIT X11R2
distribution without QA'ing it themselves, they ported the bugs too.

One of those bugs is that the xor function (and many of the inverting
functions as well) have the foreground and background colors reversed.
On a server that doesn't show the xor'd box, try setting the foreground
color to white.

  Hope this helps,
    Thomas Smith
    Elan Computer Group, Inc.
    tom@elan.com, {ames, uunet, hplabs}!elan!tom

rune.johansen%odin.re.nta.uninett@NAC.NO (Rune Henning Johansen) (09/27/89)

        >       I have a small program that works with some X servers and not
        >       with others.  I'm not sure what I'm doing wrong.  It involves
        >       setting the graphics context function to GXxor mode. 

Have you tried specifying the line-width (with XSetLineAttributes)?

        <rune.johansen@odin.re.nta.uninett>

mouse@LARRY.MCRCIM.MCGILL.EDU (der Mouse) (09/29/89)

> [ Sample program using GXxor function that sometimes works removed ]
>> What am I forgetting????
> You are forgetting that the server released from MIT is considered a
> "sample" X11 server, and that it is supposedly meant to be an
> illustration of how vendors could go about writing their own.  [It is
> buggy.]

> One of those bugs is that the xor function (and many of the inverting
> functions as well) have the foreground and background colors
> reversed.  On a server that doesn't show the xor'd box, try setting
> the foreground color to white.

While the MIT sample server is doubtless buggy, I don't think this
problem can be laid at MIT's door.  More likely, from the original
posting, is that the programmer made a certain (apparently common)
mistake when using GXxor.

The mistake is to set the GC foreground and background colors to the
foreground and background colors desired, draw with GXxor, and expect
the drawn areas to interchange foreground and background colors.  It
doesn't work this way: drawn areas get XORed with the GC foreground
color and nothing else, in particular, not (GC fg) XOR (GC bg).

In particular, on a one-bit visual (eg, your typical vanilla monochrome
server), the mistaken approach will work if, and only if, the GC
foreground value is 1.  On some servers this may be white, on others it
may be black; this is why the "switch fg and bg and it'll work" tactic
appears to work (because on a one-bit visual, one or the other will).

The solution?  Set the GC's foreground to the XOR of the desired
foreground and background pixel values.

(On a visual with more than one bit per pixel, things get hairier.)

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu