rshankar@top.cis.syr.edu (Ravi V. Shankar) (01/24/91)
I seem to be running into a problem when I use XDrawLine to draw a set
of lines. My program is pretty basic. It reads from a text file
4 values at a time and draws a line using the read values as coordinates
for the two endpoints.
The program does not give any errors during compilation. But I seem to
get different results each time I execute the compiled code. Sometimes
I get all lines drawn properly, sometimes none, sometimes a few.
I've given a portion of the code below for anyone who has patience to
read it. I would appreciate any comments/suggestions. Please reply
directly to me through email.
Thanks,
Ravi
P.S. I use a color monitor on a Sun/4 (just in case you need this info)
----------------------------------------------------------------------
.....
theWindowAttributes.border_pixel = BlackPixel(theDisplay, theScreen);
theWindowAttributes.background_pixel = WhitePixel(theDisplay, theScreen);
theWindowAttributes.override_redirect = False;
theWindowMask = (CWBackPixel | CWBorderPixel | CWOverrideRedirect );
theNewWindow = XCreateWindow( theDisplay,
RootWindow( theDisplay, theScreen ),
0, 0,
512, 512,
border_width,
theDepth,
InputOutput,
theVisual,
theWindowMask,
&theWindowAttributes );
theGC = XCreateGC (theDisplay, theNewWindow,(unsigned long)0, &theGCValues);
theColormap = DefaultColormap(theDisplay, theScreen);
XSetFunction(theDisplay, theGC, GXset);
XSetForeground(theDisplay, theGC, BlackPixel(theDisplay, theScreen));
XMapWindow(theDisplay, theNewWindow);
XFlush(theDisplay);
line_fin = fopen("data/lines.dat","r");
for (i=0; i<44; i++) {
fscanf(line_fin,"%d %d %d %d\n", &x1, &y1, &x2, &y2);
XDrawLine(theDisplay, theNewWindow, theGC, x1, y1, x2, y2);
}
XFlush(theDisplay);
fclose(line_fin);
sleep(2);
XDestroyWindow( theDisplay, theNewWindow);
XFlush(theDisplay);
.......
----------------------------------------------------------------------------
jan@golf.canberra.edu.au (Jan Newmarch) (01/25/91)
In <1991Jan23.235111.23319@rodan.acs.syr.edu> rshankar@top.cis.syr.edu (Ravi V. Shankar) writes: > I seem to be running into a problem when I use XDrawLine to draw a set > of lines. My program is pretty basic. It reads from a text file > 4 values at a time and draws a line using the read values as coordinates > for the two endpoints. Standard question, standard answer: you MUST wait for the first expose event before attempting to draw. See e.g O'Reilly vol 1 (Xlib Programming) section 3.2.14 When can I draw? +----------------------+---+ Jan Newmarch, Information Science and Engineering, University of Canberra, PO Box 1, Belconnen, Act 2616 Australia. Tel: (Aust) 6-2522422. Fax: (Aust) 6-2522999 AARnet: jan@ise.canberra.edu.au ARPA: jan%ise.canberra.edu.au@uunet.uu.net UUCP: {uunet,ukc}!munnari!ise.canberra.edu.au!jan JANET: jan%au.edu.canberra.ise@EAN-RELAY +--------------------------+
mouse@lightning.mcrcim.mcgill.EDU (01/25/91)
> I seem to be running into a problem when I use XDrawLine to draw a > set of lines. My program [...] reads from a text file 4 values at a > time and draws a line using the read values as coordinates for the > two endpoints. > The program does not give any errors during compilation. But I seem > to get different results each time I execute the compiled code. > Sometimes I get all lines drawn properly, sometimes none, sometimes a > few. > theNewWindow = XCreateWindow( [...] ); > XMapWindow(theDisplay, theNewWindow); > XFlush(theDisplay); > for (i=0; i<44; i++) { > fscanf(line_fin,"%d %d %d %d\n", &x1, &y1, &x2, &y2); > XDrawLine(theDisplay, theNewWindow, theGC, x1, y1, x2, y2); > } See the FAQ, question #74. Briefly: the window does not necessarily appear on the screen immediately when you XMapWindow(). The window manager typically redirects the request and does the map itself at a slightly later time. All drawing done before the map actually happens will be lost. You should create the window with ExposureMask in the event-mask, then draw whenever you get an Expose event. der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu