home *** CD-ROM | disk | FTP | other *** search
/ Monster Disc 2: The Best of 1992 / MONSTER2.ISO / prog / djgpp / cbgrx102.a01 / CONTRIB / LIBGRX / TEST / POLYTEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-12  |  4.4 KB  |  181 lines

  1. /**
  2.  ** POLYTEST.C
  3.  **
  4.  **  Copyright (C) 1992, Csaba Biegl
  5.  **    820 Stirrup Dr, Nashville, TN, 37221
  6.  **    csaba@vuse.vanderbilt.edu
  7.  **
  8.  **  This file is distributed under the terms listed in the document
  9.  **  "copying.cb", available from the author at the address above.
  10.  **  A copy of "copying.cb" should accompany this file; if not, a copy
  11.  **  should be available from where this file was obtained.  This file
  12.  **  may not be distributed without a verbatim copy of "copying.cb".
  13.  **  You should also have received a copy of the GNU General Public
  14.  **  License along with this program (it is in the file "copying");
  15.  **  if not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  16.  **  Cambridge, MA 02139, USA.
  17.  **
  18.  **  This program is distributed in the hope that it will be useful,
  19.  **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20.  **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21.  **  GNU General Public License for more details.
  22.  **/
  23.  
  24. #include "test.h"
  25. #include <string.h>
  26.  
  27. static int red;
  28.  
  29. #ifdef __GNUC__
  30. #define clock() rawclock()
  31. #endif
  32.  
  33. extern long clock();
  34.  
  35. unsigned char mybits[] = { 0x88, 0x44, 0x22, 0x11 };
  36. GrBitmap mybitmap = { 0, 4, mybits };
  37.  
  38. GrPattern *p1;
  39. GrPattern *p2 = (GrPattern *)&mybitmap;
  40.  
  41. static void initpatterns(void)
  42. {
  43.     GrContext tmp,save;
  44.     GrFBoxColors bc;
  45.  
  46.     mybitmap.bmp_fgcolor = GrAllocColor(255,0,0);
  47.     mybitmap.bmp_bgcolor = GrNOCOLOR;
  48.  
  49.     GrCreateContext(20,20,NULL,&tmp);
  50.     GrSaveContext(&save);
  51.     GrSetContext(&tmp);
  52.     bc.fbx_intcolor = GrAllocColor(0,140,140);
  53.     bc.fbx_leftcolor = bc.fbx_topcolor = GrAllocColor(0,200,200);
  54.     bc.fbx_rightcolor = bc.fbx_bottomcolor = GrAllocColor(0,80,80);
  55.     GrFramedBox(2,2,17,17,2,&bc);
  56.     p1 = GrConvertToPixmap(&tmp);
  57.     GrSetContext(&save);
  58. }
  59.  
  60. static void testpoly(int n,int points[][2])
  61. {
  62.     GrClearScreen(GrBlack());
  63.     GrSetClipBox(100,100,700,500);
  64.     GrFilledPolygon(n,points,red);
  65.     GrSetClipBox(0,0,GrMaxX(),GrMaxY());
  66.     GrBox(99,99,701,501,GrWhite() | GrXOR);
  67.     GrPolygon(n,points,GrWhite() | GrXOR);
  68.     getkey();
  69.     GrClearScreen(GrBlack());
  70.     GrPatternFilledPolygon(n,points,p1);
  71.     getkey();
  72.     GrPatternFilledPolygon(n,points,p2);
  73.     getkey();
  74.     if(n <= 3) {
  75.         GrClearScreen(GrBlack());
  76.         GrFilledPolygon(n,points,red);
  77.         GrFilledConvexPolygon(n,points,GrWhite() | GrXOR);
  78.         getkey();
  79.     }
  80. }
  81.  
  82. static void speedtest(void)
  83. {
  84.     int pts[4][2];
  85.     int ww = GrSizeX() / 10;
  86.     int hh = GrSizeY() / 10;
  87.     int sx = (GrSizeX() - 2*ww) / 32;
  88.     int sy = (GrSizeY() - 2*hh) / 32;
  89.     int ii,jj,color;
  90.     long t1,t2,t3;
  91.  
  92.     t1 = clock();
  93.     pts[0][1] = 0;
  94.     pts[1][1] = hh;
  95.     pts[2][1] = 2*hh;
  96.     pts[3][1] = hh;
  97.     color = 0;
  98.     for(ii = 0; ii < 32; ii++) {
  99.         pts[0][0] = ww;
  100.         pts[1][0] = 2*ww;
  101.         pts[2][0] = ww;
  102.         pts[3][0] = 0;
  103.         for(jj = 0; jj < 32; jj++) {
  104.         GrFilledPolygon(4,pts,color | GrXOR);
  105.         color = (color + 1) & 15;
  106.         pts[0][0] += sx;
  107.         pts[1][0] += sx;
  108.         pts[2][0] += sx;
  109.         pts[3][0] += sx;
  110.         }
  111.         pts[0][1] += sy;
  112.         pts[1][1] += sy;
  113.         pts[2][1] += sy;
  114.         pts[3][1] += sy;
  115.     }
  116.     t2 = clock();
  117.     pts[0][1] = 0;
  118.     pts[1][1] = hh;
  119.     pts[2][1] = 2*hh;
  120.     pts[3][1] = hh;
  121.     color = 0;
  122.     for(ii = 0; ii < 32; ii++) {
  123.         pts[0][0] = ww;
  124.         pts[1][0] = 2*ww;
  125.         pts[2][0] = ww;
  126.         pts[3][0] = 0;
  127.         for(jj = 0; jj < 32; jj++) {
  128.         GrFilledConvexPolygon(4,pts,color | GrXOR);
  129.         color = (color + 1) & 15;
  130.         pts[0][0] += sx;
  131.         pts[1][0] += sx;
  132.         pts[2][0] += sx;
  133.         pts[3][0] += sx;
  134.         }
  135.         pts[0][1] += sy;
  136.         pts[1][1] += sy;
  137.         pts[2][1] += sy;
  138.         pts[3][1] += sy;
  139.     }
  140.     t3 = clock();
  141.     sprintf(exit_message,
  142.         "Times to scan 1024 polygons\n"
  143.         "   with 'GrFilledPolygon': %.2f (s)\n"
  144.         "   with 'GrFilledConvexPolygon': %.2f (s)\n",
  145.         (double)(t2 - t1) / 18.2,
  146.         (double)(t3 - t2) / 18.2
  147.     );
  148. }
  149.  
  150. TESTFUNC(ptest)
  151. {
  152.     char buff[300];
  153.     int  pts[300][2];
  154.     int  ii,collect;
  155.     FILE *fp;
  156.  
  157.     fp = fopen("polytest.dat","r");
  158.     if(fp == NULL) return;
  159.     collect = 0;
  160.     red = GrAllocColor(255,0,0);
  161.     GrSetColor((red ^ GrWhite()),0,50,255);
  162.     initpatterns();
  163.     while(fgets(buff,299,fp) != NULL) {
  164.         if(!collect) {
  165.         if(strncmp(buff,"begin",5) == 0) {
  166.             collect = 1;
  167.             ii = 0;
  168.         }
  169.         continue;
  170.         }
  171.         if(strncmp(buff,"end",3) == 0) {
  172.         testpoly(ii,pts);
  173.         collect = 0;
  174.         continue;
  175.         }
  176.         if(sscanf(buff,"%d %d",&pts[ii][0],&pts[ii][1]) == 2) ii++;
  177.     }
  178.     speedtest();
  179. }
  180.  
  181.