C  O  P  P  E  R  T  R  I  C  K  S
----------------------------------




There are a couple of ways to do this, one is to much with UCopList
and the other is to simply set up two viewports with different colors. 
Have the second one start where you want the colors to change. Then you 
can MrgCop()/LoadView() and poof. I wrote a little program that did it 
this way.


/* 
 *   dualvp.c - Dual Viewports on the amiga
 *   Written 9/2/90 by C. McManis using Lattice C 5.02
 */

#include <exec/types.h>
#include <exec/memory.h>
#include <graphics/gfx.h>
#include <graphics/view.h>
#include <graphics/gfxbase.h>
#include <graphics/rastport.h>

extern struct GfxBase *GfxBase;

char   *TextString = "Amiga Graphics Example";

         /* Viewport 0 colors */
UWORD         colors0[4] = {0xccc, 0x000, 0x0f0, 0x00f},
         /* Viewport 1 colors */
         colors1[4] = {0x0f0, 0xc0c, 0xf00, 0xfff};
void
_main()
{
   struct View   MyView, *OldView;
   struct ViewPort   Vp0, Vp1;
   struct BitMap   Bits;
   struct RasInfo   MyRaster;
       struct RastPort   rp;
   int      i;

   /* Open the resident graphics library */
   GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0L);
   if (!GfxBase) 
      exit(1);

   OldView = GfxBase->ActiView; /* Save this away */

   /* Initialize the View structures */
   InitView(&MyView);
   InitVPort(&Vp0);
   InitVPort(&Vp1);

   Vp1.Next = NULL;
   Vp0.Next = &Vp1;   /* create a linked list of viewports */
   MyView.ViewPort = &Vp0;   /* With the first one being Vp0 */

   /* Set up some display memory */

   InitBitMap(&Bits, 2, 640, 200); 
   Bits.Planes[0] = (PLANEPTR)
          AllocMem(2*RASSIZE(640, 200),MEMF_CHIP+MEMF_CLEAR);
   Bits.Planes[1] = Bits.Planes[0] + RASSIZE(640, 200);
   if (!Bits.Planes[0]) 
      goto cleanup;

   MyRaster.BitMap = &Bits;
   MyRaster.RxOffset = 0;
   MyRaster.RyOffset = 0;
   MyRaster.Next = NULL;

   /* Both viewports are looking at the same display memory but have
         * different sets of colors
    */

   Vp0.RasInfo = &MyRaster;
   Vp0.DWidth  = 320;
   Vp0.DHeight = 175;
   Vp0.ColorMap = (struct ColorMap *)GetColorMap(4);
   LoadRGB4(&Vp0, colors0, 4);
   
   Vp1.RasInfo = &MyRaster;
   Vp1.DWidth  = 640;
   Vp1.DHeight = 20;
   Vp1.DyOffset = 179;
   Vp1.Modes   = HIRES;
   Vp1.ColorMap = (struct ColorMap *)GetColorMap(4);
   LoadRGB4(&Vp1, colors1, 4);

   
   /* Initialize a RastPort so that we can draw into that memory. */
   InitRastPort(&rp);
   rp.BitMap = &Bits;
   SetAPen(&rp, 1);   /* Foreground color */
   SetBPen(&rp, 0);   /* Background color */
   Move(&rp, 3, 12);   /* Move the graphics cursor to (3, 12) */
   /* Write something */
   Text(&rp, TextString, strlen(TextString));
   
   MakeVPort(&MyView, &Vp0); /* Build the copper list for Viewport 0 */
   MakeVPort(&MyView, &Vp1); /* Build the copper list for Viewport 1 */
   MrgCop(&MyView);      /* Merge it into the final list */

   LoadView(&MyView);     /* Show it off */

   /* SPIN FOR A WHILE */
   for (i=0; i<1000000; i++)
      ;

   LoadView(OldView);      /* Return to the old view */

   
cleanup:
   /* Now give back the memory other tasks may need it */

   if (!Vp0.ColorMap)
      FreeColorMap(Vp0.ColorMap);

   if (!Vp1.ColorMap)
      FreeColorMap(Vp1.ColorMap);

   FreeVPortCopLists(&Vp0);
   FreeVPortCopLists(&Vp1);
   FreeCprList(MyView.LOFCprList);


   if (!Bits.Planes[0]) 
      FreeMem(Bits.Planes[0], 2*RASSIZE(640, 200));

   if (!GfxBase) 
      CloseLibrary(GfxBase);

   exit(0);
}
--Chuck McManis




