swansonk@skadi.physics.stolaf.edu (Kyle Swanson) (12/07/90)
I am looking for a simple X-window graphics routine, one that will take xposition, yposition, and color as arguments and will place the corresponding pixel on the window. Thanks in advance for all replies. swansonk@thor.acc.stolaf.edu
erc@pai.UUCP (Eric Johnson) (12/07/90)
In article <1990Dec7.010711.607@acc.stolaf.edu>, swansonk@skadi.physics.stolaf.edu (Kyle Swanson) writes: > I am looking for a simple X-window graphics routine, one that > will take xposition, yposition, and color as arguments and > will place the corresponding pixel on the window. > > Thanks in advance for all replies. > > swansonk@thor.acc.stolaf.edu How's this for simple? It's written using the low-level X library called Xlib: DrawPixel( display, drawable, gc, xposition, yposition, color ) Display *display; Drawable drawable; /* Window or Pixmap */ GC gc; int xposition, yposition; unsigned long color; /* pixel value */ { /* DrawPixel */ XSetForeground( display, gc, color ); XDrawPoint( display, drawable, gc, xposition, yposition ); } /* DrawPixel */ Before you use this, however, you need to allocate your colors from a Colormap. The unsigned long color value is a pixel entry in a Colormap. You also Need to create and map your Drawable (a Window in your case, but it could also be a Pixmap) and a GC, as well as opening a Display connection. Check out just about any book on Xlib programming to help you on the above, or dig in the X11 R4 sources (if you are so inclined). I have a feeling that your real question is how to allocate colors. Here's a list of some of the books that are out there. Please note that I'm definitely biased on this. Johnson, Eric F. and Kevin Reichard, X Window Applications Programming, MIS: Press, Portland, OR, 1989. ISBN 1-55828-016-2. Johnson, Eric F. and Kevin Reichard, Advanced X Window Applications Programming, MIS: Press, Portland, OR, 1990. ISBN 1-55828-029-4. Jones, Oliver, Introduction to the X Window System, Prentice Hall, Englewood Cliffs, NJ, 1989. ISBN 0-13-499997-5. Nye, Adrian, Xlib Programming Manual, vol. 1, 2nd ed., O'Reilly and Assoc., Sebastopol, CA, 1990. ISBN 0-937175-11-0. Nye, Adrian (ed.), Xlib Reference Manual, vol. 2, 2nd ed., O'Reilly and Assoc., Sebastopol, CA, 1990. ISBN 0-937175-12-9. Scheifler, Robert W. and James Gettys, with Jim Flowers, Ron Newman and David Rosenthal, 2nd ed., X Window System: The Complete Reference to Xlib, X Protocol, ICCCM, XLFD, Digital Press, Bedford, MA, 1990. ISBN (Digital Press) 1-5558-050-5, (Prentice Hall) 0-13-972050-2. Hope this helps, -Eric -- Eric F. Johnson phone: +1 612 894 0313 BTI: Industrial Boulware Technologies, Inc. fax: +1 612 894 0316 automation systems 415 W. Travelers Trail email: erc@pai.mn.org and services Burnsville, MN 55337 USA
mouse@LIGHTNING.MCRCIM.MCGILL.EDU (12/08/90)
>> I am looking for a simple X-window graphics routine, one that will >> take xposition, yposition, and color as arguments and will place the >> corresponding pixel on the window. ("the" window?) > [Eric offers a simple routine using XSetForeground and XDrawPoint] > Before you use this, however, you need to allocate your colors from a > Colormap. [...] You also Need to create and map your Drawable (a > Window in your case, but it could also be a Pixmap) and a GC, as well > as opening a Display connection. Lest anyone get confused: if you're using a Pixmap, ignore the bits about the colormap and about mapping the drawable. (Pixmaps don't use colormaps and don't get mapped or unmapped.) der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu