[comp.windows.x] Problem with Sparc X11R4

dave@csis.dit.csiro.au (David Campbell) (06/21/91)

/* This code demonstrates a problem I am experiencing with line drawing
   under X11R4 on a standard Color Sparcstation IPC running MIT X11R4.
   I draw a two lines, a horizontal one and a vertical one, in the shape of
   an upside-down capital T.  The problem is that the vertical line
   crosses over the horizontal line by 1 pixel.

   Can somebody please criticize my code or tell me this is some problem
   with X?

   The system I am using is a standard Color Sparcstation IPC running MIT
   X11R4, but the problem occurs on every color system here (that I tried)
   running X11R4.

   The problem does not occur when:
	-Displaying on a machine running OpenWindows.
	-Compiled and running on a machine displaying on a decstation.
	-Compiled and running on a decstation displaying on a decstation.
	-Displaying on an Sparc SLC (monochrome).

   This is what happens:

			|
			|
			|
			|
   ---------------------+---------------------
			|  <-bonus pixel

   This program lets you turn the horizontal line on and off with the first
   two mouse buttons, making it easy to see the extra pixel that gets drawn.
   The third mouse button exits.

   Compile with cc -o problem problem.c -lX11
*/

#define XVAL 100
#define YVAL 95
#define DIST 40

#include <X11/Xlib.h>
#include <X11/Xutil.h>

char why[]= "WHY WHY WHY?";

Display *display;
Window window;
GC gc;

drawhoriz()
{
	/* horizontal line */
	XDrawLine(display, window, gc,
		XVAL - DIST, YVAL,
		XVAL + DIST, YVAL);
}

drawboth()
{
	drawhoriz();

	/* vertical line - THE PROBLEM */
	XDrawLine(display, window, gc,
		XVAL, YVAL,
		XVAL, YVAL - DIST);
}


main(argc,argv)
int argc;
char **argv;
{
	XEvent event;
	KeySym key;
	XSizeHints hint;
	int screen;
	unsigned long foreground, background;
	int i;
	char text[10];
	int done;

	display = XOpenDisplay("");
	screen = DefaultScreen(display);
	background = WhitePixel(display,screen);
	foreground = BlackPixel(display,screen);
	hint.x = 200;
	hint.y = 300;
	hint.width = 350;
	hint.height = 250;
	hint.flags = PPosition | PSize;
	window = XCreateSimpleWindow(display, DefaultRootWindow(display),
		hint.x, hint.y, hint.width, hint.height,
		5, foreground, background);
	XSetStandardProperties(display, window, why, why, None,
		argv, argc, &hint);
	gc = XCreateGC(display, window, 0, 0);
	XSetBackground(display, gc, background);
	XSetForeground(display, gc, foreground);
	XSelectInput(display, window, ButtonPressMask | ExposureMask);
	XMapRaised(display, window);

	for(;;) {
		XNextEvent(display, &event);
		switch(event.type) {
		case Expose:
			drawboth();
			break;
		case ButtonPress:
			switch(event.xbutton.button) {
			case Button1:
				/* draw both lines */
				XSetForeground(display, gc, foreground);
				drawboth();
				break;
			case Button2:
				/* blank out the horizontal */
				XSetForeground(display, gc, background);
				drawhoriz();
				break;
			case Button3:
				goto bye;
			}
		}
	}
bye:
	XFreeGC(display, gc);
	XDestroyWindow(display, window);
	XCloseDisplay(display);
	exit(0);
}

/*

Regards,

-- Dave Campbell
-- dave@csis.dit.csiro.au

*/

-- 
dave campbell

gu@yoko.rutgers.edu (zp gu) (06/25/91)

<code that demonstrates an extra pixel was drawn when drawing an
 upside down T on Sparc using MIT X11R4                         >

The problem is caused by drawing using line width 0, which is kind
of device (vendor) dependent. Using non-zero width should yield
correct result.
(but on the other hand, there is no excuse for broken 0-width lines :)


/zp