home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 543a.lha / Nebula / source.LZH / source / views.c < prev   
Encoding:
C/C++ Source or Header  |  1991-06-10  |  3.9 KB  |  178 lines

  1. /*
  2.  
  3. ------------------------------------------------------------------
  4.  
  5. Black Nebula
  6.  
  7. File :                viewports.c
  8. Programmer:        Colin Adams
  9. Date:                26/4/91
  10. Last Modified :    10/6/91
  11.  
  12. Description:
  13.  
  14. Allocates two bitmapped views for the main display.
  15.  
  16. ------------------------------------------------------------------
  17.  
  18. */
  19.  
  20. #define AMIGA_INCLUDES
  21. #include "3d.h"
  22.  
  23.  
  24. extern UWORD Palette2[];
  25. extern short swapflag, store1, store2;
  26.  
  27. struct View my_view;
  28. struct View back_view;
  29.  
  30. struct View *my_old_view;
  31.  
  32. struct ViewPort my_view_port;
  33. struct ViewPort back_view_port;
  34.  
  35. struct RasInfo my_ras_info;
  36. struct RasInfo back_ras_info;
  37.  
  38. struct BitMap my_bit_map;
  39. struct BitMap back_bit_map;
  40.  
  41. struct RastPort my_rast_port;
  42. struct RastPort back_rast_port;
  43.  
  44. void SetUpViews(void)
  45. {
  46.   UWORD *pointer;
  47.     int loop;
  48.     char *temppoint, *temp2;
  49.     
  50.   my_old_view = GfxBase->ActiView;
  51.  
  52.   InitView(&my_view);
  53.     InitView(&back_view);
  54.     
  55.   my_view.ViewPort = &my_view_port;
  56.     back_view.ViewPort = &back_view_port;
  57.  
  58.   InitVPort(&my_view_port);
  59.     InitVPort(&back_view_port);
  60.     
  61.   back_view_port.DWidth = my_view_port.DWidth = G;
  62.   back_view_port.DHeight = my_view_port.DHeight = HEIGHT;
  63.     
  64.   my_view_port.RasInfo = &my_ras_info;
  65.   my_view_port.Modes = NULL;
  66.  
  67.     back_view_port.RasInfo = &back_ras_info;
  68.     back_view_port.Modes = NULL;
  69.  
  70.   my_view_port.ColorMap = (struct ColorMap *) GetColorMap(COLOURS);
  71.   if(my_view_port.ColorMap == NULL)
  72.     CleanUpandExit();
  73.       
  74.     back_view_port.ColorMap = (struct ColorMap *) GetColorMap(COLOURS);
  75.   if(back_view_port.ColorMap == NULL)
  76.     CleanUpandExit();
  77.  
  78.   pointer = (UWORD *) my_view_port.ColorMap->ColorTable;
  79.  
  80.   for(loop = 0; loop<COLOURS; loop++)
  81.     *pointer++ = Palette2[loop];
  82.      
  83.     pointer = (UWORD *) back_view_port.ColorMap->ColorTable;
  84.  
  85.   for(loop = 0; loop < COLOURS; loop++)
  86.             *pointer++ = Palette2[loop];
  87.  
  88.   InitBitMap(&my_bit_map, DEPTH, G, HEIGHT);
  89.     InitBitMap(&back_bit_map, DEPTH, G, HEIGHT);
  90.     
  91.   temppoint = AllocMem(40960, MEMF_CHIP);
  92.   if(!temppoint)
  93.       CleanUpandExit();
  94.     
  95.     temp2 = AllocMem(40960, MEMF_CHIP);
  96.     if(!temp2)
  97.         CleanUpandExit();
  98.     
  99.     for(loop=0; loop<DEPTH; loop++)
  100.     {
  101.         my_bit_map.Planes[loop] = (PLANEPTR) temppoint + 10240*loop;
  102.         back_bit_map.Planes[loop] = (PLANEPTR) temp2 + 10240*loop;
  103.     }
  104.     
  105.   BltClear(temppoint, 40960, 0);
  106.     BltClear(temp2, 40960, 0);
  107.  
  108.   my_ras_info.BitMap = &my_bit_map;
  109.   my_ras_info.RxOffset = 0;
  110.   my_ras_info.RyOffset = 0;
  111.   my_ras_info.Next = NULL;
  112.     
  113.     back_ras_info.BitMap = &back_bit_map;
  114.   back_ras_info.RxOffset = 0;
  115.   back_ras_info.RyOffset = 0;
  116.   back_ras_info.Next = NULL;
  117.                                   
  118.  
  119.   /* Create the display: */
  120.     
  121.   MakeVPort(&my_view, &my_view_port);
  122.     MakeVPort(&back_view, &back_view_port);
  123.     
  124.   MrgCop(&my_view);
  125.     MrgCop(&back_view);
  126.  
  127.   InitRastPort( &my_rast_port );
  128.   my_rast_port.BitMap = &my_bit_map;
  129.     
  130.     InitRastPort( &back_rast_port );
  131.   back_rast_port.BitMap = &back_bit_map;
  132.  
  133.     InitArea(&my_area_info, areabuffer, MAX_POINTS);
  134.     
  135.     back_rast_port.AreaInfo = my_rast_port.AreaInfo = &my_area_info;
  136.     
  137.     if(!(extra_space = (PLANEPTR) AllocRaster(G,256)))
  138.         CleanUpandExit();
  139.     
  140.     back_rast_port.TmpRas = my_rast_port.TmpRas = (struct TmpRas *)
  141.         InitTmpRas(&my_temp_ras, (APTR) extra_space, RASSIZE(G,HEIGHT));
  142.  
  143.     rastport = &back_rast_port;
  144.  
  145.     BNDRYOFF(&my_rast_port); /* no boundaries around objects */
  146.     BNDRYOFF(&back_rast_port);
  147.     
  148.     loadpic("screen.iff");
  149.   LoadView(&my_view);
  150. }
  151.  
  152. void FreeView(void)
  153. {
  154.   LoadView(my_old_view);
  155.  
  156.   FreeVPortCopLists(&my_view_port);
  157.     FreeVPortCopLists(&back_view_port);
  158.     
  159.   FreeCprList(my_view.LOFCprList);
  160.   FreeCprList(back_view.LOFCprList);
  161.     
  162.   if(my_bit_map.Planes[0])
  163.       FreeMem(my_bit_map.Planes[0], 40960);
  164.  
  165.   if(back_bit_map.Planes[0])
  166.         FreeMem(back_bit_map.Planes[0], 40960);
  167.  
  168.   if(my_view_port.ColorMap) FreeColorMap(my_view_port.ColorMap);
  169.     if(back_view_port.ColorMap) FreeColorMap(back_view_port.ColorMap);
  170.     if(extra_space)
  171.         FreeRaster(extra_space, G, 256);
  172.     swapflag = 1;
  173.     store1 = store2 = 0;
  174.     active_list[0] = NULL;
  175. }
  176.  
  177. /* end of module views.c */
  178.