home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / VGATUT2.ZIP / VGALINES.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-06  |  3.6 KB  |  140 lines

  1. ////////////////////////////////////////
  2. // VGA Lines           - Barny Mercer //
  3. //                                    //
  4. // Created : 1/8/95 @ 6:45pm          //
  5. ////////////////////////////////////////
  6.  
  7. #include <conio.h>
  8. #include "vgafunc.h"
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <sys/timeb.h>
  12.  
  13. void Intro(void);
  14. void Outro(void);
  15. void TestFloatLine(void);
  16. void TestBresLine(void);
  17. void ScrollFloatLine(void);
  18. void ScrollBresLine(void);
  19.  
  20. void main(void)
  21. {
  22.     // make sure that we are in text mode
  23.     VidMode( VID_TEXT );
  24.  
  25.     Intro();
  26.  
  27.     TestFloatLine();
  28.     ScrollFloatLine();
  29.     TestBresLine();
  30.     ScrollBresLine();
  31.  
  32.     Outro();
  33. }
  34.  
  35. void Intro(void)
  36. {
  37.     printf( "Hi there & welcome to the second installment of my VGA tutorial.\n\n" );
  38.     printf( "This program concerns it's self with lines and looks at two functions\n");
  39.     printf( "for drawing them....\n\n");
  40.     printf( "1.  This routine uses the PutPixel function that we developed in part I\n");
  41.     printf( "    As you will see, it's pretty fast, but let's get faster.....\n\n");
  42.     printf( "2.  Ta da!  By restricting this function to integer math and making no\n");
  43.     printf( "    function calls we have increased the speed tremendously.\n\n");
  44.     printf( "Each function is put through the following tests : \n\n");
  45.     printf( "   5000 lines of random length, colour & orientation are drawn. \n");
  46.     printf( "   25 screens of 200 lines are drawn to create a scrolling effect. \n");
  47.  
  48.     getch();
  49.  
  50.     // clear screen by re-selecting text mode
  51.     VidMode(VID_TEXT);
  52. }
  53.  
  54. void Outro(void)
  55. {
  56.     printf( "Well...  there you have it.  A nice fast DrawLine routine.\n\n");
  57.     printf( "I hope you've enjoyed this tutorial and that you'll find it useful.\n\n");
  58.     printf( "Many thanks to Richard Griffiths who's been porting this code to Pascal\n");
  59.     printf( "for me.\nAs yet, this tutorial is still not available by FTP but I'm working\n");
  60.     printf( "on it.\n\nBye for now......  \n\n" );
  61.     printf( "Barny Mercer      : barny.mercer@zetnet.co.uk \n" );
  62.     printf( "                  : http://www.zetnet.co.uk/users/bmercer/ \n\n");
  63.     printf( "Richard Griffiths : richard.griffiths@zetnet.co.uk \n" );
  64.     printf( "                  : http://www.zetnet.co.uk/users/rgriff/\n");
  65.  
  66.     getch();
  67.  
  68. }
  69.  
  70. void TestFloatLine(void)
  71. {
  72.     printf( "Floating Point line drawing.....\n" );
  73.     getch();
  74.  
  75.     VidMode(VID_320x200);
  76.  
  77.     for (int Tmp=0; Tmp<5000; Tmp++)
  78.     {
  79.     FloatDrawLine( (rand()%319),(rand()%199),(rand()%319),(rand()%199),(rand()%255) );
  80.     }
  81.  
  82.     getch();
  83.  
  84.     VidMode(VID_TEXT);
  85. }
  86.  
  87. void ScrollFloatLine(void)
  88. {
  89.     printf( "Floating point scroller.....\n" );
  90.     getch();
  91.     VidMode(VID_320x200);
  92.  
  93.     for (int Tmp=0; Tmp<25; Tmp++)
  94.     {
  95.     for (int YLoops=0; YLoops<200; YLoops++)
  96.     {
  97.         FloatDrawLine( 0, YLoops, 319, YLoops, YLoops+Tmp);
  98.     }
  99.     }
  100.  
  101.     getch();
  102.  
  103.     VidMode(VID_TEXT);
  104. }
  105.  
  106. void TestBresLine(void)
  107. {
  108.     printf( "Optimised (Bresenham's Algorithm) line drawing..\n" );
  109.     getch();
  110.     VidMode(VID_320x200);
  111.  
  112.     for (int Tmp=0; Tmp<5000; Tmp++)
  113.     {
  114.     BresDrawLine( (rand()%319),(rand()%199),(rand()%319),(rand()%199),(rand()%255) );
  115.     }
  116.  
  117.     getch();
  118.  
  119.     VidMode(VID_TEXT);
  120. }
  121.  
  122. void ScrollBresLine(void)
  123. {
  124.     printf( "Bressenham scroller.....\n" );
  125.     getch();
  126.     VidMode(VID_320x200);
  127.  
  128.     for (int Tmp=0; Tmp<25; Tmp++)
  129.     {
  130.     for (int YLoops=0; YLoops<200; YLoops++)
  131.     {
  132.         BresDrawLine( 0, YLoops, 319, YLoops, YLoops+Tmp);
  133.     }
  134.     }
  135.  
  136.     getch();
  137.  
  138.     VidMode(VID_TEXT);
  139. }
  140.