home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l350 / 3.ddi / EXAMPLES / GDEMO / GDEMO.C next >
Encoding:
C/C++ Source or Header  |  1992-12-21  |  3.3 KB  |  160 lines

  1. /* gdemo.c - Graphics demo program */
  2.  
  3. /************************************************************************/
  4. /*    Copyright (C) 1986-1993 Phar Lap Software, Inc.            */
  5. /*    Unpublished - rights reserved under the Copyright Laws of the    */
  6. /*    United States.  Use, duplication, or disclosure by the         */
  7. /*    Government is subject to restrictions as set forth in         */
  8. /*    subparagraph (c)(1)(ii) of the Rights in Technical Data and     */
  9. /*    Computer Software clause at 252.227-7013.            */
  10. /*    Phar Lap Software, Inc., 60 Aberdeen Ave., Cambridge, MA 02138    */
  11. /************************************************************************/
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <time.h>
  16. #include "gserver.h"
  17.  
  18. /*
  19.  * Include the Microsoft graphics library definition file.  Before we do
  20.  * this, we will undefine the keywords '__far' and '__huge' so that we will
  21.  * be able to compile the function prototypes with all 32-bit compilers.
  22.  *
  23.  * Also, for MetaWare High C/C++, define '__cdecl' so all the prototypes
  24.  * in graph.h work.
  25.  */
  26. #undef __far
  27. #undef __huge
  28. #define __far
  29. #define __huge
  30. #ifdef __HIGHC__
  31. #define __cdecl
  32. #endif
  33. #ifndef _MSC_VER
  34. #define _MSC_VER 700    /* so __far and __huge don't get defined again */
  35. #endif
  36. #include "graph.h"
  37.  
  38. /*
  39.  * Prototypes for routines in this file
  40.  */
  41. int randline();
  42. short randx();
  43. short randy();
  44.  
  45. /*
  46.  
  47. main - Main routine
  48.  
  49. */
  50.  
  51. int main()
  52. {
  53.     struct _videoconfig vc;    /* Video configuration */
  54.     int btime;        /* Execution time for buffered mode */
  55.     int ubtime;        /* Execution time for unbuffered mode */
  56.  
  57.     /* Get the current video mode */
  58.  
  59.     _getvideoconfig(&vc);
  60.  
  61.     /* Switch to CGA medium res 4-color graphics mode */
  62.  
  63.     _setvideomode(_MRES4COLOR);
  64.     _selectpalette(0);
  65.  
  66.     /* Run the demo first in buffered mode if protected mode */
  67.  
  68.     _gbuffmode(1);
  69.     btime = randline();
  70.     
  71.     /* Run the demo again in unbuffered mode */
  72.  
  73.     _gbuffmode(0);
  74.     ubtime = randline();
  75.  
  76.     /* Restore the original video mode */
  77.  
  78.     _setvideomode(vc.mode);
  79.  
  80.     /* Print out the buffered and unbuffered execution times */
  81.  
  82.     printf("\n\n");
  83.     printf("Buffered mode execution time = %i milliseconds.\n",
  84.            btime);
  85.     printf("Unbuffered mode execution time = %i milliseconds.\n",
  86.            ubtime);
  87.  
  88.     /* Exit back to DOS */
  89.  
  90.     return 0;    
  91.  
  92. }
  93.  
  94.  
  95. /*
  96.  
  97. randline - Random line demo
  98.  
  99. */
  100.  
  101. int randline()
  102. {
  103.     int i;        /* Loop counter */
  104.     clock_t stime;    /* Start type */
  105.     clock_t etime;    /* End time */
  106.  
  107.     /* Reseed the random number generator to a constant 100 so that
  108.        we always generate the same random lines. */
  109.  
  110.     srand(100);
  111.  
  112.     /* Start the clock */
  113.  
  114.     stime = clock();
  115.  
  116.     /* The demo code clears the screen and randomly draws 1000 lines 
  117.        in random colors */
  118.  
  119.     _clearscreen(_GCLEARSCREEN);
  120.     for(i = 0; i < 1000; ++i)
  121.     {
  122.         _setcolor((short) (rand() % 4));
  123.         _fmoveto(randx(), randy());
  124.         _lineto(randx(), randy());
  125.     }
  126.  
  127.     /* Stop the clock */
  128.  
  129.     etime = clock();
  130.  
  131.     /* Return withe the elapse execution time in milliseconds */
  132.  
  133.     return (int)((1000L * (etime - stime)) / CLOCKS_PER_SEC);
  134.  
  135. }
  136.  
  137.  
  138. /*
  139.  
  140. randx - Generate a random X coordinate value
  141.  
  142. */
  143.  
  144. short randx()
  145. {
  146.     return (short) (rand() % 320);
  147. }
  148.  
  149.  
  150. /*
  151.  
  152. randy - Generate a random Y coordinate value
  153.  
  154. */
  155.  
  156. short randy()
  157. {
  158.     return (short) (rand() % 200);
  159. }
  160.