home *** CD-ROM | disk | FTP | other *** search
/ gondwana.ecr.mu.oz.au/pub/ / Graphics.tar / Graphics / voglew.zip / SHAPES.C < prev    next >
C/C++ Source or Header  |  1993-05-28  |  3KB  |  114 lines

  1.  
  2. #include <stdio.h>
  3. #include "vogle.h"
  4.  
  5. /*
  6.  * This program shows some of the simple primitives.
  7.  */
  8. main()
  9. {
  10.     vinit("mswin");
  11.  
  12.     /*
  13.      * the two lines below clear the screen to white if we have
  14.      * colours, on a monochrome device color is ignored so the
  15.      * screen will be cleared to its background color, normally black.
  16.      */
  17.     color(BLACK);
  18.     clear();
  19.  
  20.     /*
  21.      * set the screen to be 2.0 units wide and 2.0 units wide, with
  22.      * the drawable coordinates going from -1.0 to 1.0.
  23.      */
  24.     ortho2(-1.0, 1.0, -1.0, 1.0);
  25.  
  26.     /*
  27.      * set the text size. After this call no characters in the
  28.      * current font will be wider than 0.1 or higher than 0.1 in
  29.      * world units. As the window is currently 2.0 units wide and
  30.      * 2.0 units high text will be about one twentieth of the screen
  31.      * size.
  32.      */
  33.     textsize(0.1, 0.1);
  34.  
  35.     color(MAGENTA);
  36.  
  37.     /*
  38.      * okay, so we want to draw in the range -1 to 1, but we
  39.      * only want to draw in the top lefthand corner of the
  40.      * screen. The call to viewport allows us to do this. As
  41.      * viewport always takes screen coordinates, which are 
  42.      * always in the range of -1 to 1 we can change always
  43.      * change the viewport to somewhere else on the screen
  44.      * by giving a range in -1 to 1.
  45.      */
  46.     viewport(-1.0, 0.0, 0.0, 1.0);
  47.  
  48.     move2(-0.9, -0.5);        /* write out a heading */
  49.     drawstr("rect");
  50.  
  51.     /*
  52.      * draw a rectangle around the points (-0.2, -0.2), (-0.2, 0.2),
  53.      * (0.3, 0.2), and (0.3, -0.2).
  54.      */
  55.     rect(-0.2, -0.2, 0.3, 0.2);
  56.  
  57.     color(BLUE);
  58.  
  59.     /*
  60.      * now we want to draw in the top right corner of the screen
  61.      */
  62.     viewport(0.0, 1.0, 0.0, 1.0);
  63.  
  64.     move2(-0.9, -0.5);
  65.     drawstr("circle");
  66.  
  67.     /*
  68.      * draw a circle of radius 0.4 around the point (0.0, 0.0)
  69.      */
  70.     circle(0.0, 0.0, 0.4);
  71.  
  72.     color(GREEN);
  73.  
  74.     viewport(-1.0, 0.0, -1.0, 0.0);        /* draw in bottom left corner */
  75.  
  76.     move2(-0.9, -0.5);
  77.     drawstr("ellipse");
  78.  
  79.     /*
  80.      * To draw an ellipse we change the aspect ratio so it is no longer
  81.      * 1 and call circle. In this case we use ortho2 to make the square
  82.      * viewport appear to be higher than it is wide. Alternatively you
  83.      * could use arc to construct one.
  84.      *
  85.      * The call to pushmatrix saves the current viewing transformation.
  86.      * After the ortho2 has been done, we restore the current viewing
  87.      * transformation with a call to popmatrix. (Otherwise everything
  88.      * after the call to ortho would come out looking squashed as the
  89.      * world aspect ratio is no longer 1).
  90.      */
  91.     pushmatrix();
  92.         ortho2(-1.0, 1.0, -1.0, 2.0);
  93.         circle(0.0, 0.5, 0.4);
  94.     popmatrix();
  95.  
  96.     color(RED);
  97.  
  98.     viewport(0.0, 1.0, -1.0, 0.0);    /* now draw in bottom right corner */
  99.  
  100.     move2(-0.9, -0.5);
  101.     drawstr("arc");
  102.  
  103.     /*
  104.      * draw an arc centered at (0.0, 0.0), radius of 0.4. 0.0 is the start
  105.      * angle and 90.0 is the end angle of the arc being drawn. So this
  106.      * draws a quarter circle.
  107.      */
  108.     arc(0.0, 0.0, 0.4, 0.0, 90.0);
  109.  
  110.     getkey();
  111.  
  112.     vexit();
  113. }
  114.