From: ccsw@bristol.ac.uk (EthaStorm)
Newsgroups: comp.sys.amiga.programmer
Subject: Re: Need help with "Graphics Primitives"...
Date: 16 Oct 92 09:26:25 GMT
Organization: University of Bristol, England

In article <1bhkmiINNj1f@darkstar.UCSC.EDU> smythe@cats.ucsc.edu (Brian Matthew Aljian) writes:
>
>Question: Can someone give me some guidelines on what I need to do to set
>up and perform an area fill operation?
>
Hello Brian.

  This is a subject that I've just tackled (fairly successfully) in Assembler.
Here's what I did.

First, you need to set up an AreaInfo structure. This is 24 bytes in size, and
should be word aligned (start on a even address boundary). The AreaInfo 
structure looks like this:

 AreaInfo   Address   Size   Contents
            =======   ====   ========

              0       LONG   VctrTbl
              4       LONG   VctrPtr
              8       LONG   FlagTbl
             12       LONG   FlagPtr
             16       WORD   Count
             18       WORD   MaxCount
             20       WORD   FirstX
             22       WORD   FirstY

I won't pretend to know the proper meanings of the contents, but I think they're
fairly self-explanatory.

To set up your AreaInfo structure, you need to create a pointer to the
AreaInfo structure (A0 in assembler) and a pointer to a word aligned block
of memory (A1). The size of the (A1) block of memory is 5 BYTES * (maximum
number of edges) that you wish to use.

Once you have your two pointers, you should call the InitArea routine.

Now, you need to allocate some memory for your TmpRas structure. Probably the
best way that I've heard of, is to create a block of memory as large as a
single bitplane of your screen. On the advice that I've received over the last
few months, the AllocRaster routine is best for this purpose.

So, you next need to AllocRaster(WIDTH,HEIGHT) where WIDTH is the width of
your screen in pixels, and HEIGHT is the height of the screen in pixels.

Maintain the pointer to the allocated (raster) memory block, you'll need it
in the next step.

You now need a TmpRas structure, for the Area routines to use in their
calculations. The TmpRas structure is 8 bytes long, and word aligned. It looks
like

   TmpRas     Address  Size  Contents
              =======  ====  ========

                 0     LONG   RasPtr
                 4     LONG   Size


Take the pointer to the allocated (raster) memory (A1), generate a pointer to
your TmpRas structure (A0) and also a register to hold the BYTE size of the
(raster) memory block ( you can do this in C with RASSIZE(), I think). Then,
issue a call to InitTmpRas().

Now,  you need to link your TmpRas structure into your RastPort structure.
Do this by pushing the address of the TmpRas structure into the Rastport
structure at relative address 12.

  ie. In Assembler,

         move.l   TmpRas,a0    ;  TmpRas structure address into A0
         move.l   Rastport,a1  ;  Rastport structure address into A1
         move.l   a0,12(a1)    ; Link TmpRas structure to Rastport structure

   In C (Apologies... My C programming is CRUD!!)

        Rastport->TmpRas = *TmpRas    ; or something like that!!!


That SHOULD be that (but I hold no immediate responsibility for accuracy).

From meory, I seem to recall that to perform an Area() routine (AreaMove/
AreaDraw/AreaEnd), you now just need a pointer to your Rastport structure,
and you also need to supply to X and Y co-ordinates of the end of the line
you are drawing.

The Area() routines work something like this. First, do an AreaMove() to
the first point you wish to use. Then, call AreaDraw() with the co-ordinates
of the next point. The Area() routines will create a line from your first
point to your second point. After operation, the second point becomes your
CURRENT point, so another AreaDraw() will create a line from this point to
another that you specify. To finish your polygon and render it to the screen,
you need to call the AreaEnd() routine.

That's about it. Sorry if it seems a bit garbled. Hope it is of some use to
you.

    EthaStorm  *8)
===============================================================================
= The opinions contained in this transmission are my own. No-one else's.      =
= My very own. They belong to me. They used to belong to my girlfriend.       =
=                                                                             =
=  E-Mail:- Steff.Watkins@bristol.ac.uk  Telephone:- +44 (272) 303531         =
===============================================================================
Newsgroups: comp.sys.amiga.programmer