[comp.sys.amiga.tech] How to pick colors on custom screens?

zerkle@iris.ucdavis.edu (Dan Zerkle) (10/13/90)

When I open a custom screen, I seem to inherit the default WB colors.
I seem to have figured out how to pick the register from which I draw
any particular image, but I don't know how to pick what colors go into
those registers.

1. #registers == 2^#bitplanes, right?  How do I set these registers so
   that the colors will be there immediately upon opening the screen?

2. What about if I want to change the colors on the fly?  What's an
   established way to let the user to it via a requestor?

3. What do the different values in the registers mean?  I assume that
   |Palette| = 4096 <=> register size = 12 bits.  This would in turn
   imply 4 bits per color.  How are these split up to chose the exact
   colors.

4. This information should be more easily available.  I looked in the
   Libraries & Devices and couldn't find it in screens, colors,
   windows (I'm trying to stick with Intuition).  Where should I be
   looking?

Details:  Using A3000 & WB2.0, but want compatible w/ 1.3.  Aztec C.
I would love examples of what values make what colors, and example
code would make my day.  Also, references to your sources of
information would also be helpful, so I can find it myself next time.

             Dan Zerkle  zerkle@iris.ucdavis.edu  (916) 754-0240
           Amiga...  Because life is too short for boring computers.

bj@cbmvax.commodore.com (Brian Jackson) (10/13/90)

In article <7819@ucdavis.ucdavis.edu> zerkle@iris.ucdavis.edu (Dan Zerkle) writes:
>When I open a custom screen, I seem to inherit the default WB colors.
>I seem to have figured out how to pick the register from which I draw
>any particular image, but I don't know how to pick what colors go into
>those registers.
>
>1. #registers == 2^#bitplanes, right?  How do I set these registers so
>   that the colors will be there immediately upon opening the screen?

You need to deal with the ViewPort and ColorMap structures to so this
Take a look at Pages 348-349 of the Libraries and Devices (Blue)
RKM.  This shows you how to use the LoadRGB4() or SetRGB4CM() calls.
The ViewPort you will need can be found in your screen structure.
Be sure that you use the system calls to do this stuff!

Of course, you need to have your screen already opened to do this so
you can use the SCREENBEHIND flag to have all these transformations
take place behind the WB screen until you are ready to display it
with ScreenToFront().

>2. What about if I want to change the colors on the fly?  What's an
>   established way to let the user to it via a requestor?

Same way.

>3. What do the different values in the registers mean?  I assume that
>   |Palette| = 4096 <=> register size = 12 bits.  This would in turn
>   imply 4 bits per color.  How are these split up to chose the exact
>   colors.

The color registers are set up like this:

	bits		color
	----		-----
	15-12		unused
	11-8		red
	 7-4		green
	 3-0		blue


	----RRRRGGGGBBBB


>4. This information should be more easily available.  I looked in the
>   Libraries & Devices and couldn't find it in screens, colors,
>   windows (I'm trying to stick with Intuition).  Where should I be
>   looking?

You need to go through Graphics.library to do some of this stuff.
Look both there and in Intuition.  The RKM docs on Graphics Primitives
are also most illuminating.

>Details:  Using A3000 & WB2.0, but want compatible w/ 1.3.  Aztec C.
>I would love examples of what values make what colors, and example
>code would make my day.  Also, references to your sources of
>information would also be helpful, so I can find it myself next time.

Using Manx version < 5.0 ?? Remember to be real careful about the
size of the args passed to OS functions. Anything not a pointer should
be cast to Long:

    static UWORD colortable[] = {
        0x000,   /* black */
        0xf00,   /* red   */
        0x0f0,   /* green */
        0x00f    /* blue  */
        } ;

    LoadRGB4(&viewport, colortable, 4L ) ;
                                    ^^ 

>Dan Zerkle 

 -----------------------------------------------------------------------
 | Brian Jackson  Software Engineer @ Commodore-Amiga Inc.  GEnie: B.J. |
 | bj@cbmvax.commodore.com    or  ...{uunet|rutgers}!cbmvax!bj          |
 | "Now there's a look in your eyes, like black holes in the sky"       |
 -----------------------------------------------------------------------