home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / agl103p.lha / src / agl / RCS / poly.c,v < prev    next >
Encoding:
Text File  |  1994-12-09  |  11.1 KB  |  696 lines

  1. head    1.2;
  2. branch    1.2.1.99;
  3. access;
  4. symbols;
  5. locks; strict;
  6. comment    @ * @;
  7.  
  8.  
  9. 1.2
  10. date    93.02.19.01.41.33;    author jason;    state Exp;
  11. branches
  12.     1.2.1.1;
  13. next    ;
  14.  
  15. 1.2.1.1
  16. date    94.03.29.05.41.32;    author jason;    state Exp;
  17. branches;
  18. next    1.2.1.2;
  19.  
  20. 1.2.1.2
  21. date    94.04.06.02.41.16;    author jason;    state Exp;
  22. branches;
  23. next    1.2.1.3;
  24.  
  25. 1.2.1.3
  26. date    94.09.13.03.51.13;    author jason;    state Exp;
  27. branches;
  28. next    1.2.1.4;
  29.  
  30. 1.2.1.4
  31. date    94.11.16.06.25.54;    author jason;    state Exp;
  32. branches;
  33. next    1.2.1.5;
  34.  
  35. 1.2.1.5
  36. date    94.12.09.05.29.56;    author jason;    state Exp;
  37. branches;
  38. next    ;
  39.  
  40.  
  41. desc
  42. @points, lines, and polygons
  43. @
  44.  
  45.  
  46. 1.2
  47. log
  48. @Initial RCS Version
  49. @
  50. text
  51. @#include"agl.h"
  52.  
  53.  
  54. /******************************************************************************
  55. void    recti(long x1,long y1,long x2,long y2)
  56.  
  57. ******************************************************************************/
  58. /*PROTOTYPE*/
  59. void recti(long x1,long y1,long x2,long y2)
  60.     {
  61.     bgnline();
  62.     rectvert((float)x1,(float)y1,(float)x2,(float)y2,TRUE);
  63.     endline();
  64.     }
  65.  
  66.  
  67. /******************************************************************************
  68. void    rectfi(long x1,long y1,long x2,long y2)
  69.  
  70. ******************************************************************************/
  71. /*PROTOTYPE*/
  72. void rectfi(long x1,long y1,long x2,long y2)
  73.     {
  74.     if(OneToOne[CurrentWid])    /* bypass transforms if no effect */
  75.         {
  76.         y1=CurrentHeight-y1-1;
  77.         y2=CurrentHeight-y2-1;
  78.  
  79.         RectFill(DrawRPort,x1,y2,x2,y1);
  80.         return;
  81.         }
  82.  
  83.     bgnpolygon();
  84.     rectvert((float)x1,(float)y1,(float)x2,(float)y2,FALSE);
  85.     endpolygon();
  86.     }
  87.  
  88.  
  89. /******************************************************************************
  90. void    rects(short x1,short y1,short x2,short y2)
  91.  
  92. ******************************************************************************/
  93. /*PROTOTYPE*/
  94. void rects(short x1,short y1,short x2,short y2)
  95.     {
  96.     bgnline();
  97.     rectvert((float)x1,(float)y1,(float)x2,(float)y2,TRUE);
  98.     endline();
  99.     }
  100.  
  101.  
  102. /******************************************************************************
  103. void    rectfs(short x1,short y1,short x2,short y2)
  104.  
  105. ******************************************************************************/
  106. /*PROTOTYPE*/
  107. void rectfs(short x1,short y1,short x2,short y2)
  108.     {
  109.     bgnpolygon();
  110.     rectvert((float)x1,(float)y1,(float)x2,(float)y2,FALSE);
  111.     endpolygon();
  112.     }
  113.  
  114.  
  115. /******************************************************************************
  116. void    rect(float x1,float y1,float x2,float y2)
  117.  
  118. ******************************************************************************/
  119. /*PROTOTYPE*/
  120. void rect(float x1,float y1,float x2,float y2)
  121.     {
  122.     bgnline();
  123.     rectvert(x1,y1,x2,y2,TRUE);
  124.     endline();
  125.     }
  126.  
  127.  
  128. /******************************************************************************
  129. void    rectf(float x1,float y1,float x2,float y2)
  130.  
  131. ******************************************************************************/
  132. /*PROTOTYPE*/
  133. void rectf(float x1,float y1,float x2,float y2)
  134.     {
  135.     bgnpolygon();
  136.     rectvert(x1,y1,x2,y2,FALSE);
  137.     endpolygon();
  138.     }
  139.  
  140.  
  141. /******************************************************************************
  142. void    rectvert(float x1,float y1,float x2,float y2,long line)
  143.  
  144. ******************************************************************************/
  145. /*PROTOTYPE*/
  146. void rectvert(float x1,float y1,float x2,float y2,long line)
  147.     {
  148.     static float vert[4][2];
  149.     short n;
  150.  
  151.     vert[0][0]=x1;
  152.     vert[0][1]=y1;
  153.     vert[1][0]=x2;
  154.     vert[1][1]=y1;
  155.     vert[2][0]=x2;
  156.     vert[2][1]=y2;
  157.     vert[3][0]=x1;
  158.     vert[3][1]=y2;
  159.  
  160.     for(n=0;n<4;n++)
  161.         v2f(vert[n]);
  162.  
  163.     if(line)
  164.         v2f(vert[0]);
  165.     }
  166.  
  167.  
  168. /*******************************************************************************
  169. void    bgnpoint(void)
  170.  
  171. *******************************************************************************/
  172. /*PROTOTYPE*/
  173. void bgnpoint(void)
  174.     {
  175.     if(DrawType)
  176.         GL_error("bgnpoint(): bad command order");
  177.  
  178.     DrawType=GL_POINT;
  179.     }
  180.  
  181.  
  182. /*******************************************************************************
  183. void    endpoint(void)
  184.  
  185. *******************************************************************************/
  186. /*PROTOTYPE*/
  187. void endpoint(void)
  188.     {
  189.     if(DrawType!=GL_POINT)
  190.         GL_error("endpoint(): bad command order");
  191.  
  192.     DrawType=FALSE;
  193.     }
  194.  
  195.  
  196. /*******************************************************************************
  197. void    bgnline(void)
  198.  
  199. *******************************************************************************/
  200. /*PROTOTYPE*/
  201. void bgnline(void)
  202.     {
  203.     if(DrawType)
  204.         GL_error("bgnline(): bad command order");
  205.  
  206.     DrawType=GL_LINE;
  207.     BgnLine=TRUE;
  208.     }
  209.  
  210.  
  211. /*******************************************************************************
  212. void    endline(void)
  213.  
  214. *******************************************************************************/
  215. /*PROTOTYPE*/
  216. void endline(void)
  217.     {
  218.     if(DrawType!=GL_LINE)
  219.         GL_error("endline(): bad command order");
  220.  
  221.     DrawType=FALSE;
  222.     }
  223.  
  224.  
  225. /*******************************************************************************
  226. void    bgnpolygon(void)
  227.  
  228. *******************************************************************************/
  229. /*PROTOTYPE*/
  230. void bgnpolygon(void)
  231.     {
  232.     if(DrawType)
  233.         GL_error("bgnpolygon(): bad command order");
  234.  
  235.     DrawType=GL_POLYGON;
  236.     Verts=0;
  237.     }
  238.  
  239.  
  240. /*******************************************************************************
  241. void    endpolygon(void)
  242.  
  243. *******************************************************************************/
  244. /*PROTOTYPE*/
  245. void endpolygon(void)
  246.     {
  247.     if(DrawType!=GL_POLYGON)
  248.         GL_error("endpolygon(): bad command order");
  249.  
  250.     AreaEnd(DrawRPort);
  251.  
  252.     DrawType=FALSE;
  253.     }
  254.  
  255.  
  256. /*******************************************************************************
  257. void    render_vertex(short vert[2])
  258.  
  259. *******************************************************************************/
  260. /*PROTOTYPE*/
  261. void render_vertex(short vert[2])
  262.     {
  263.     long x,y;
  264.  
  265.     x=vert[0];
  266.     y=CurrentHeight-vert[1]-1;
  267.  
  268.     switch(DrawType)
  269.         {
  270.         case FALSE:
  271.             GL_error("v2s(): bad command order");
  272.             break;
  273.         case GL_POINT:
  274.             WritePixel(DrawRPort,x,y);
  275.             break;
  276.         case GL_LINE:
  277.             if(BgnLine)
  278.                 {
  279.                 BgnLine=FALSE;
  280.                 Move(DrawRPort,x,y);
  281.                 }
  282.             else
  283.                 Draw(DrawRPort,x,y);
  284.             break;
  285.         case GL_POLYGON:
  286.             if(Verts==MAX_POLY_VERTS)
  287.                 GL_error("Exceeded max points in polygon");
  288.             else
  289.                 {
  290.                 if(Verts)
  291.                     AreaDraw(DrawRPort,x,y);
  292.                 else
  293.                     AreaMove(DrawRPort,x,y);
  294.                 Verts++;
  295.                 }
  296.             break;
  297.         }
  298.     }
  299.  
  300.  
  301. /******************************************************************************
  302. void    mapcolor(long m,long r,long g,long b)
  303.  
  304.     maintain 256 shade standard
  305. ******************************************************************************/
  306. /*PROTOTYPE*/
  307. void mapcolor(long m,long r,long g,long b)
  308.     {
  309.     char string[100];
  310.  
  311.     if(m<0 || m>15)
  312.         {
  313.         sprintf(string,"mapcolor(): bad index %d",m);
  314.         GL_error(string);
  315.         return;
  316.         }
  317.  
  318.     r=(r+7)/16;
  319.     g=(g+7)/16;
  320.     b=(b+7)/16;
  321.  
  322.     ColorMap[m]= (((r<<4)+g)<<4)+b;
  323.     SetRGB4(GLView,m,r,g,b);
  324.     }
  325.  
  326.  
  327. /******************************************************************************
  328. void    getmcolor(long m,long *r,long *g,long *b)
  329.  
  330. ******************************************************************************/
  331. /*PROTOTYPE*/
  332. void getmcolor(long m,long *r,long *g,long *b)
  333.     {
  334.     *r=ColorMap[m];
  335.  
  336.     *b= *r&15;
  337.     *r= *r>>4;
  338.     *g= *r&15;
  339.     *r= *r>>4;
  340.  
  341.     *r *=16;
  342.     *g *=16;
  343.     *b *=16;
  344.     }
  345.  
  346.  
  347. /*******************************************************************************
  348. void    color(long c)
  349.  
  350. *******************************************************************************/
  351. /*PROTOTYPE*/
  352. void color(long c)
  353.     {
  354.     CurrentColor=c;
  355.     SetAPen(DrawRPort,c);
  356.     }
  357.  
  358.  
  359. /*******************************************************************************
  360. long    getcolor(void)
  361.  
  362. *******************************************************************************/
  363. /*PROTOTYPE*/
  364. long getcolor(void)
  365.     {
  366.     return CurrentColor;
  367.     }
  368.  
  369.  
  370. /*******************************************************************************
  371. void    clear(void)
  372.  
  373. *******************************************************************************/
  374. /*PROTOTYPE*/
  375. void clear(void)
  376.     {
  377. #if TRUE
  378.  
  379.     /* clear window */
  380.     RectFill(DrawRPort,0,0,CurrentWidth-1,CurrentHeight-1);
  381.  
  382. #else
  383.  
  384.     /* clear whole screen (clipped to window) */
  385.     SetRast(DrawRPort,CurrentColor);
  386.  
  387. #endif
  388.     }
  389. @
  390.  
  391.  
  392. 1.2.1.1
  393. log
  394. @Added RCS Header
  395. @
  396. text
  397. @a0 16
  398.  
  399. /******************************************************************************
  400.  
  401. $Id: poly.c,v 1.2.1.1 2002/03/26 22:04:19 jason Exp jason $
  402.  
  403. $Log: poly.c,v $
  404.  * Revision 1.2.1.1  2002/03/26  22:04:19  jason
  405.  * Added RCS Header
  406.  *
  407.  * Revision 1.2.1.1  2002/03/26  22:00:51  jason
  408.  * RCS/agl.h,v
  409.  *
  410.  
  411. ******************************************************************************/
  412.  
  413.  
  414. @
  415.  
  416.  
  417. 1.2.1.2
  418. log
  419. @Back to rectangular clear
  420. @
  421. text
  422. @d4 1
  423. a4 1
  424. $Id: poly.c,v 1.2.1.1 1994/03/29 05:41:32 jason Exp jason $
  425. a6 3
  426.  * Revision 1.2.1.1  1994/03/29  05:41:32  jason
  427.  * Added RCS Header
  428.  *
  429. a342 8
  430.     long bit,value;
  431.     long m,line,screenwidth,offset,lineoff;
  432.     size_t linewidth;
  433.     PLANEPTR planes,planem;
  434.  
  435.     /* only activate one of the following three methods */
  436.  
  437.  
  438. d348 1
  439. a348 4
  440. #endif
  441.  
  442.  
  443. #if FALSE
  444. a351 51
  445.  
  446. #endif
  447.  
  448.  
  449. #if FALSE
  450.     size=ScreenDef.Width*ScreenDef.Height/8;
  451.  
  452.     /* individually clear each full plane */
  453.     for(m=0;m<ScreenDef.Depth;m++)
  454.         memset(DrawRPort->BitMap->Planes[m],2<<m,size);
  455.  
  456. #endif
  457.  
  458.  
  459. #if FALSE
  460.  
  461.     screenwidth=ScreenDef.Width/8+1;
  462.     offset=screenwidth*(ScreenDef.Height-CurrentPosY-CurrentHeight-1)+CurrentPosX/8;
  463.     linewidth=(CurrentWidth+7)/8+1;
  464.     bit=1;
  465.  
  466.     if(offset)
  467.         {
  468.         offset--;
  469.         linewidth++;
  470.         }
  471.  
  472.     /* individually clear area in each plane */
  473.     for(m=0;m<ScreenDef.Depth;m++)
  474.         {
  475.         if(CurrentColor&bit)
  476.             value=255;
  477.         else
  478.             value=0;
  479.  
  480.         lineoff=offset;
  481.         planem= (DrawRPort->BitMap->Planes[m]);
  482.  
  483.         for(line=0;line<CurrentHeight;line++)
  484.             {
  485.             memset(&(planem[lineoff]),value,linewidth);
  486.  
  487.             lineoff+=screenwidth;
  488.             }
  489.  
  490.         bit<<=1;
  491.         }
  492.  
  493. /*
  494.         BltClear((DrawRPort->BitMap->Planes[m])+offset,size,0);
  495. */
  496. @
  497.  
  498.  
  499. 1.2.1.3
  500. log
  501. @PolyDraw() test
  502. @
  503. text
  504. @d4 1
  505. a4 1
  506. $Id: poly.c,v 1.2.1.2 1994/04/06 02:41:16 jason Exp jason $
  507. a6 3
  508.  * Revision 1.2.1.2  1994/04/06  02:41:16  jason
  509.  * Back to rectangular clear
  510.  *
  511. a19 1
  512. #ifndef NOT_EXTERN
  513. a20 6
  514. #endif
  515.  
  516. #define POLYLINE        FALSE    /* use PolyDraw() instead of Move(), Draw() */
  517. #define MAX_LINE_VERTS    512        /* max # of lines vertices (2 times max lines) */
  518.  
  519. short LineBuffer[MAX_LINE_VERTS];
  520. a176 1
  521.     Verts=0;
  522. a189 7
  523. #if POLYLINE
  524.  
  525.     else
  526.         PolyDraw(DrawRPort,Verts/2,LineBuffer);
  527.  
  528. #endif
  529.  
  530. d240 1
  531. a240 1
  532.             GL_error("v??(): bad command order");
  533. a241 1
  534.  
  535. a244 1
  536.  
  537. a245 9
  538. #if POLYLINE
  539.             if(Verts==MAX_LINE_VERTS)
  540.                 GL_error("Exceeded max points in polyline");
  541.             else
  542.                 {
  543.                 LineBuffer[Verts++]=x;
  544.                 LineBuffer[Verts++]=y;
  545.                 }
  546. #else
  547. a252 1
  548. #endif
  549. a253 1
  550.  
  551. a262 1
  552.  
  553. @
  554.  
  555.  
  556. 1.2.1.4
  557. log
  558. @adjust for borders
  559. @
  560. text
  561. @d4 1
  562. a4 1
  563. $Id: poly.c,v 1.2.1.3 1994/09/13 03:51:13 jason Exp jason $
  564. a6 3
  565.  * Revision 1.2.1.3  1994/09/13  03:51:13  jason
  566.  * PolyDraw() test
  567.  *
  568. a254 6
  569.     if(Bordered[CurrentWid])
  570.         {
  571.         x+=BorderWidth;
  572.         y+=BorderWidth+BorderHeight;
  573.         }
  574.  
  575. d386 1
  576. a386 1
  577. #if FALSE
  578. d394 1
  579. a394 1
  580. #if TRUE
  581. @
  582.  
  583.  
  584. 1.2.1.5
  585. log
  586. @uses global screen settings instead of structure
  587. @
  588. text
  589. @d1 1
  590. d4 1
  591. a4 4
  592. Copyright © 1994 Jason Weber
  593. All Rights Reserved
  594.  
  595. $Id: poly.c,v 1.2.1.4 1994/11/16 06:25:54 jason Exp jason $
  596. a6 3
  597.  * Revision 1.2.1.4  1994/11/16  06:25:54  jason
  598.  * adjust for borders
  599.  *
  600. d412 1
  601. a412 1
  602.     size=ScreenWidth*ScreenHeight/8;
  603. d415 1
  604. a415 1
  605.     for(m=0;m<ScreenDeep;m++)
  606. d423 2
  607. a424 2
  608.     screenwidth=ScreenWidth/8+1;
  609.     offset=screenwidth*(ScreenHeight-CurrentPosY-CurrentHeight-1)+CurrentPosX/8;
  610. d435 1
  611. a435 1
  612.     for(m=0;m<ScreenDeep;m++)
  613. @
  614.  
  615.  
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667.  
  668.  
  669.  
  670.  
  671.  
  672.  
  673.  
  674.  
  675.  
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683.  
  684.  
  685.  
  686.  
  687.  
  688.  
  689.  
  690.  
  691.  
  692.  
  693.  
  694.  
  695.  
  696.