[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference hydra::amiga_v1

Title:AMIGA NOTES
Notice:Join us in the *NEW* conference - HYDRA::AMIGA_V2
Moderator:HYDRA::MOORE
Created:Sat Apr 26 1986
Last Modified:Wed Feb 05 1992
Last Successful Update:Fri Jun 06 1997
Number of topics:5378
Total number of notes:38326

1258.0. "'C' and graphics" by AUNTB::PRESSLEY () Fri Mar 18 1988 15:17

    I have been learning 'C' and Amiga Graphics for the past 2 months
    and I have been impressed with what I've seen.  My first project
    was drawing a picture of a man and moving him across the screen.
    I used the raw graphics utilities and a simple sprite.  The
    hardest part was plotting the pixel colors to produce the image
    of a little man.  I soon found out that I could draw the picture
    of a man using Deluxe Paint and then convert the IFF file to
    a 'C' structure using a PD utility.  This was great.  I then
    decided to paint an entire scene on the screen.  I produced an
    eight color low res picture using Deluxe Paint and then converted
    the iff file to a 'C' structure.  The structure was 24000 words,
    that's 8000 words per bit plane.  After compiling and linking
    the image became 56000 bytes in size.  I ran the image and the picture
    appeared on the screen.  I then decided to edit the program and
    make a change.  That's when I got the error message can't open window.
     I then double checked the code to see if I was releasing memory.
    I was using the FreeMemory function from the Amiga Rom Kernal Manual.
    I'm going to load the 24000 word array at run time tonight to see
    if that makes a difference.  I'm also going to free the copper list
    using the interlace option, even though I'm not using interlace.
    I'll let you know my findings.
    
    Randy
T.RTitleUserPersonal
Name
DateLines
1258.1the source of the problemAUNTB::PRESSLEYSat Mar 19 1988 16:53161
    I'm still having troubles opening a window after running the display
    program.  I'm going to include a copy of my c program.  It is basically
    the same program which is in the rom kernel manual.  If anyone would
    like to take a look, here it is...
         
#include "exec/types.h"
#include "graphics/gfx.h"
#include "hardware/dmabits.h"
#include "hardware/custom.h"
#include "hardware/blit.h"
#include "graphics/copper.h"
#include "graphics/view.h"
#include "graphics/gels.h"
#include "graphics/regions.h"
#include "exec/exec.h"
#include "graphics/text.h"
#include "graphics/gfxbase.h"
#include "graphics/clip.h"
#include "graphics/rastport.h"

#define DEPTH 3
#define WIDTH 320
#define HEIGHT 200
#define NOT_ENOUGH_MEMORY - 1000
/* CONSTRUCT A SIMPLE DISPLAY */

struct View v;
struct ViewPort vp;
struct ColorMap *cm;   /* pointer to colormap structure,dynamic alloc */
struct RasInfo ri;
struct BitMap b;
struct RastPort rp;

LONG i,kk;
SHORT j,k,n;

extern struct ColorMap *GetColorMap();
struct GfxBase *GfxBase;

struct View *oldview;   /*save pointer to old View so can restore */

         /* black,white,red,green,blue,yellow,brown,light blue */
USHORT colortable[] = {0x000,0xeca,0xb00,0x080,0x24c,0xdc2,0xc82,0x0cc}; /* my own colors */
SHORT boxoffsets[] = {802,2010,3218};      /* where to draw boxes */
union {
   UBYTE *displaymem;
   UWORD *w;
} ptr;
UWORD *colorpalette;


main()
{
   GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
   if(GfxBase == NULL)exit(1);
   oldview = GfxBase->ActiView; /*save current View to restore later */
   /* example steals screen from Intuition if Intuition is around */

   InitView(&v);      /* initialize View */
   InitVPort(&vp);      /* init ViewPort */
   v.ViewPort = &vp;   /* link View into ViewPort */

   /* init bit map (for RasInfo and RastPort) */
   InitBitMap(&b,DEPTH,WIDTH,HEIGHT);

   /* (init RasInfo) */
   ri.BitMap = &b;
   ri.RxOffset = 0;
   ri.RyOffset = 0;
   ri.Next = NULL;

   /* now specify critical characteristics */
   vp.DWidth = WIDTH;
   vp.DHeight = HEIGHT;
   vp.RasInfo = &ri;

   /* (init color table) */
   cm = GetColorMap(8);      /* 4 entries, since only 2 planes deep */
   colorpalette = (UWORD *)cm->ColorTable;
   for(i=0;i<8;i++) {
      *colorpalette++ = colortable[i];
   }
   /* copy my colors into this data structure */
   vp.ColorMap = cm;   /* link it with the ViewPort */

   /* allocate space for bitmap */
   for(i=0;i<DEPTH;i++)
   {
      b.Planes[i] = (PLANEPTR)AllocRaster(WIDTH,HEIGHT);
      if(b.Planes[i] == NULL)exit(NOT_ENOUGH_MEMORY);
   }



   MakeVPort(&v,&vp);   /* construct Copper instruction (prelim) list */
   MrgCop(&v);      /* merge preliminary lists together into a real
             * Copper list in the view structure */

   for(i=0;i<DEPTH;i++)
   {
      ptr.displaymem = (UBYTE *)b.Planes[i];
      BltClear(ptr.displaymem,RASSIZE(WIDTH,HEIGHT),0);
   }

   LoadView(&v);
   DisplayMem();

   Delay(50*10);      /* wait for 10 seconds */

   LoadView(oldview);   /* put back the old View */

   for(i=0; i<3; i++)
   {
      FreeRaster(b.Planes[i],320,200);
   }
   /* free the color map created by GetColorMap() */
   FreeColorMap(cm);
   /* free dynamically created structures */
   FreeVPortCopLists(&vp);
   FreeCprList(v.LOFCprList);



   CloseLibrary(GfxBase);   /* since program opened library, close it */

}    /* end of main() */
DisplayMem()
{
/* Paint the sky blue and the grass green */

   ptr.displaymem = b.Planes[0];
   for(i=0;i < 3200;i++)
   {
   *ptr.w++ = 0xffff;
   }
   for(i=0;i < 4800;i++)
   {
   *ptr.w++ = 0xffff;
   }
   ptr.displaymem = b.Planes[1];
   for(i=0;i < 3200;i++)
   {
   *ptr.w++ = 0xffff;
   }
   for(i=0;i < 4800;i++)
   {
   *ptr.w++ = 0xffff;
   }
   ptr.displaymem = b.Planes[2];
   for(i=0;i < 3200;i++)
   {
   *ptr.w++ = 0xffff;
   }
   for(i=0;i < 4800;i++)
   {
   *ptr.w++ = 0x0000;
   }
   ptr.displaymem = b.Planes[2];
}

    
1258.2The solutionAUNTB::PRESSLEYSun Mar 20 1988 09:408
    Well I found the problem.  It seems that I forgot that the array
    in the example I copied is in bytes where as the array I'm building
    is in words therefore the screen takes up 4000 words not 8000.
    
    I have also copied several animation utilities from the rom kernel
    manual onto disk.  They include things like MakeBob, ReadyGels,
    MakeVSprite etc.  If anyone would like a copy of these utilities
    I'll post them.
1258.3I'm interested!BONKER::DUPREThe Sherrif of Noting-hamMon Mar 21 1988 09:388

Randy,

		I would be interested in those utilities also what is the
	PD utility you used to convert the DPAINT to C structure?

						JimBo
1258.4YES Thanks!HSK03::HAKALATuomo Hakala, ES FinlandMon Mar 21 1988 14:009
    YES, YES !!!
    
    Please make the routines and the PD utility available. I've been
    studying the Amy graphics in C lately and found it *awful* to copy
    those manual programs into Amiga by hand. What is that PD utility?
    
    Thanks in advance! 

              - Tuomo
1258.5I will postitAUNTB::PRESSLEYMon Mar 21 1988 15:046
    I will post the utilities and the pd program tonight.  The pd utility
    is called ilbmdump and will take as input an iff file and convert
    it to either bob or sprite format which you then include into your
    'C' program.
    
    auntb::$1$dua0:[pressley.amiga.public]
1258.6c animation utilitiesAUNTB::PRESSLEYMon Mar 21 1988 20:4936
    It has been posted.  All of the utilities are in one file.  I have
    successfully compiled the functions.
    
    ReadyGels(* gelsinfo, *rastport);
    PurgeGels(* gelsinfo);
    struct VSprite *makeVSprite(lineheight, *image, *colorset, x, y,
    			wordwidth, imagedepth, flags);
                         
    DeleteVSprite(&VSprite);
    struct Bob *MakeBob(bitwidth, lineheight, imagedepth, *image,
    			planePick, planeOnOff, x, y);
    DeleteBob(&Bob);
    
    ReadyGels sets up the defaults of the gel system by initializing
    the GelsInfo structure you provide.  First it allocates room for
    and links in lastcolor and nextline.  It then uses information in
    your RastPort structure to establish boundary collision defaults
    at the outer edges of the raster.  It then links together the GelsInfo
    and the RastPort which you provide.  Next it allocates space for
    two dummy virtual sprite structures, calls InitGels and SetCollision.
     You must already have run LoadView before ReadyGels is called.
    
    PurgeGels deallocates all memory which ReadyGels and NewGelList
    have allocated.  The system will crash if you have not used these
    routines to allocate the space (you can't deallocate something which
    you haven't allocated in the first place).
    
    MakeVSprite allocates enough space for and inits a normal vsprite.
     DeleteVSprite deallocates the memory it used.
    
    MakeBob initializes a standard bob and allocates as much memory
    as is needed for a normal bob and its vsprite structure, links them
    together.  To find the associated vsprite, look at the back-pointer.
    DeleteBob deallocates the memory it used.
                         
    
1258.7Thank you!HSK03::HAKALATuomo Hakala, ES FinlandThu Mar 24 1988 15:073
    Many, many thanks, I really appreciate your effort.
    
    	- Tuomo
1258.8the shadow knowsAUNTB::PRESSLEYThu Apr 28 1988 21:251
    My new device is $1$dus13: