Lisp HUG Maillist Archive

Alpha channel on windows

I can't seem to draw a transparent rectangle on windows.  I do the
following test:

(setq p (capi:contain
          (make-instance 'capi:output-pane)))
(capi:apply-in-pane-process p
 (lambda ()
   (gp:clear-rectangle p 0 0 120 120)
   (gp:draw-line p 0 0 300 300
      :foreground :red
      :thickness 3)
   (gp:draw-rectangle p 10 10 100 100
      :filled t
      :foreground (color:make-rgb 0.9 0.9 0.9 0.5))))

On my mac, the red line shows through the gray rectangle.  On my
Windows XP box, it doesn't.  Any idea why this might be?

Thanks,
Gail


Re: Alpha channel on windows

If I'm not mistaken, LW on Windows uses GDI to draw all kinds of graphics. GDI doesn't support transparency, antialiasing, another niceties. GDI+ does.. And Direct2D does (Win7 and Vista SP2).

Best,
 Art

--- On Tue, 10/19/10, Gail Zacharias <gz@clozure.com> wrote:

> From: Gail Zacharias <gz@clozure.com>
> Subject: Alpha channel on windows
> To: lisp-hug@lispworks.com
> Date: Tuesday, October 19, 2010, 11:48 AM
> 
> I can't seem to draw a transparent rectangle on windows.
>  I do the
> following test:
> 
> (setq p (capi:contain
>           (make-instance 'capi:output-pane)))
> (capi:apply-in-pane-process p
>  (lambda ()
>    (gp:clear-rectangle p 0 0 120 120)
>    (gp:draw-line p 0 0 300 300
>       :foreground :red
>       :thickness 3)
>    (gp:draw-rectangle p 10 10 100 100
>       :filled t
>       :foreground (color:make-rgb 0.9 0.9 0.9 0.5))))
> 
> On my mac, the red line shows through the gray rectangle.
>  On my
> Windows XP box, it doesn't.  Any idea why this might be?
> 
> Thanks,
> Gail
> 
> 


Re: Alpha channel on windows

Gail Zacharias wrote:

> (capi:apply-in-pane-process p
>  (lambda ()
>    (gp:clear-rectangle p 0 0 120 120)
>    (gp:draw-line p 0 0 300 300
>       :foreground :red
>       :thickness 3)
>    (gp:draw-rectangle p 10 10 100 100
>       :filled t
>       :foreground (color:make-rgb 0.9 0.9 0.9 0.5))))
>
> On my mac, the red line shows through the gray rectangle.  On my
> Windows XP box, it doesn't.

I had the same problem a while ago.  My workaround was to copy the
existing pane contents (your red line) to a pixmap, draw the new objects
(your rectangle) on that pixmap, and then use GP:DRAW-IMAGE with the
GLOBAL-ALPHA keyword parameter to draw everything with the desired alpha
on the output pane.

Here's an example:

(defun simple-display-transparency-test (pane x y width height)
   (declare (ignore x y width height))
   (let ((width 100)
         (height 100))
     (gp:draw-rectangle pane 10 10 80 80
                        :filled t
                        :foreground :blue)
     (gp:with-pixmap-graphics-port (port pane width height)
       ;; Draw the original image on the pixmap.
       (let ((original-image (gp:make-image-from-port pane)))
         (gp:draw-image port original-image 0 0))
       ;; Draw the new object on the pixmap.
       (gp:draw-circle port 25 25 25 :filled t :foreground :yellow)
       ;; Make an image from the pixmap and draw it half transparently.
       (let ((image (gp:make-image-from-port port)))
         (gp:draw-image pane image 0 0 :use-source-alpha t :global-alpha 0.5
                        :to-width 50 :to-height 50
                        :from-width 50 :from-height 50)))
     ;; Show a plain yellow circle for reference.
     (gp:draw-circle pane 75 75 20 :filled t :foreground :yellow)))


It's ugly and slow, but better than nothing.

Arthur


Re: Alpha channel on windows

I applied this technique to my situation and it works great.  Thanks!

On Tue, Oct 19, 2010 at 4:00 PM, Arthur Lemmens <alemmens@xs4all.nl> wrote:
> Gail Zacharias wrote:
>
>> (capi:apply-in-pane-process p
>>  (lambda ()
>>   (gp:clear-rectangle p 0 0 120 120)
>>   (gp:draw-line p 0 0 300 300
>>      :foreground :red
>>      :thickness 3)
>>   (gp:draw-rectangle p 10 10 100 100
>>      :filled t
>>      :foreground (color:make-rgb 0.9 0.9 0.9 0.5))))
>>
>> On my mac, the red line shows through the gray rectangle.  On my
>> Windows XP box, it doesn't.
>
> I had the same problem a while ago.  My workaround was to copy the
> existing pane contents (your red line) to a pixmap, draw the new objects
> (your rectangle) on that pixmap, and then use GP:DRAW-IMAGE with the
> GLOBAL-ALPHA keyword parameter to draw everything with the desired alpha
> on the output pane.
>
> Here's an example:
>
> (defun simple-display-transparency-test (pane x y width height)
>  (declare (ignore x y width height))
>  (let ((width 100)
>        (height 100))
>    (gp:draw-rectangle pane 10 10 80 80
>                       :filled t
>                       :foreground :blue)
>    (gp:with-pixmap-graphics-port (port pane width height)
>      ;; Draw the original image on the pixmap.
>      (let ((original-image (gp:make-image-from-port pane)))
>        (gp:draw-image port original-image 0 0))
>      ;; Draw the new object on the pixmap.
>      (gp:draw-circle port 25 25 25 :filled t :foreground :yellow)
>      ;; Make an image from the pixmap and draw it half transparently.
>      (let ((image (gp:make-image-from-port port)))
>        (gp:draw-image pane image 0 0 :use-source-alpha t :global-alpha 0.5
>                       :to-width 50 :to-height 50
>                       :from-width 50 :from-height 50)))
>    ;; Show a plain yellow circle for reference.
>    (gp:draw-circle pane 75 75 20 :filled t :foreground :yellow)))
>
>
> It's ugly and slow, but better than nothing.
>
> Arthur
>


Updated at: 2020-12-10 08:38 UTC