From: Jonathan Bailleul
Subject: CLX-Newbie: How to 'change the drawing color' in CLX?
Date: 
Message-ID: <3DB44EAB.211CA252@greyc.ismra.fr>
Hello,

I used to draw white points in a black background using a gcontext
defined in B/W and the draw-point function. I would like to be able to
write pixels of different color, but I can't figure a straightforward
way to make it. 

It seems that I have to create a colormap for it, but it still seems
fuzzy to me at this point. Can anyone help me out?

In advance, thank you for your help


-- 
--------------------------
Jonathan BAILLEUL
Doctorant au GREYC Image
ISMRA, Universit� de Caen
From: Donald Fisk
Subject: Re: CLX-Newbie: How to 'change the drawing color' in CLX?
Date: 
Message-ID: <3DB5C3B2.A45C1EB0@enterprise.net>
Jonathan Bailleul wrote:
> 
> Hello,
> 
> I used to draw white points in a black background using a gcontext
> defined in B/W and the draw-point function. I would like to be able to
> write pixels of different color, but I can't figure a straightforward
> way to make it.
> 
> It seems that I have to create a colormap for it, but it still seems
> fuzzy to me at this point. Can anyone help me out?

I assume you've figured out how to create displays, screens and
windows.

To do what you want, look up the colour in the existing colormap,
then allocate it, then write it to the graphics context foreground.
Feel free to use this:

(defun find-color (name)
  (let ((colormap (xlib:screen-default-colormap *screen*)))
    (xlib:alloc-color colormap (xlib:lookup-color colormap name))))

This process may fail, depending on your hardware and what's
currently on your screen.

Next, create a graphics context for your window.

(xlib:create-gcontext :drawable window)

Then, change your graphics context foreground each time you draw
something:

    (setf (xlib:gcontext-foreground gcontext) (find-color "green"))
    (xlib:draw-line window gcontext 100 100 200 200)
    (setf (xlib:gcontext-foreground gcontext) (find-color "red"))
    (xlib:draw-line window gcontext 150 100 200 150)
(xlib:display-force-output *display*)

As well as the documentation that comes with CLX, you may find
the Xlib programming Manual by Adrian Nye useful.   It's about
Xlib programming in C but helps you understand the X-windows
system and the function calls in C and Lisp are similar.

Le Hibou
-- 
Dalinian: Lisp. Java. Which one sounds sexier?
RevAaron: Definitely Lisp. Lisp conjures up images of hippy coders,
drugs,
sex, and rock & roll. Late nights at Berkeley, coding in Lisp fueled by
LSD.
Java evokes a vision of a stereotypical nerd, with no life or social
skills.