home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / vopl / glvopl.lha / glvopl / examples / cex1.c next >
Encoding:
C/C++ Source or Header  |  1993-10-07  |  1.4 KB  |  100 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. #ifdef SGI_GL
  5. #include "gl.h"
  6. #include "device.h"
  7. #else
  8. #include "vogl.h"
  9. #include "vodevice.h"
  10. #endif
  11.  
  12. #define PI    3.14159265358979
  13. #define    N    300
  14.  
  15. float    x[N], y[N];
  16.  
  17. /*
  18.  *    A very simple test program for vopl.
  19.  *
  20.  *     This one draws a graph of y = sin(x) 0 <= x <= 2 * PI
  21.  */
  22. main()
  23. {
  24.     float    t, dt;
  25.     int    i;
  26.     short    val;
  27.     Screencoord    left, right, bottom, top;
  28.  
  29. /*
  30.  *    Generate the points
  31.  */
  32.     t = 0.0;
  33.     dt = 2 * PI / N;
  34.  
  35.     for (i = 0; i != N; i++) {
  36.         x[i] = t;
  37.         y[i] = sin(t);
  38.         t = t + dt;
  39.     }
  40.  
  41. /*
  42.  *    Adjust the scaling according to x and y arrays
  43.  */
  44.     adjustscale(x, N, 'x');
  45.     adjustscale(y, N, 'y');
  46. /*
  47.  *    As we are now about to do some graphics we initialise VOGLE
  48.  *    and clear to BLACK
  49.  */
  50.     hfont("times.r");
  51.     winopen("VOPL");
  52.     qdevice(KEYBD);
  53.  
  54.     color(0);
  55.     clear();
  56. /*
  57.  *    Now set the color to GREEN
  58.  */
  59.     color(2);
  60.  
  61. /*
  62.  *    Draw the default set of axes (in GREEN)
  63.  */
  64.     drawaxes2();
  65. /*
  66.  *    Set color to RED
  67.  */
  68.     color(1);
  69. /*
  70.  *    Draw the Graph
  71.  */
  72.     plot2(x, y, N);
  73. /*
  74.  *    Wait around a bit
  75.  */
  76.     qread(&val);
  77. /*
  78.  *    Now draw a little one in the top right hand corner
  79.  *    by reseting the VOGL viewport.
  80.  */
  81.     getviewport(&left, &right, &bottom, &top);
  82.     viewport((left + right) / 2, right, (top + bottom) / 2, top);
  83. /*
  84.  *    Draw it again, but do the plot first (in BLUE) then the axes
  85.  *    (in YELLOW)
  86.  */
  87.     color(4);
  88.     plot2(x, y, N);
  89.     color(3);
  90.     drawaxes2();
  91. /*
  92.  *    Hang around again
  93.  */
  94.     qread(&val);
  95. /*
  96.  * bugger off
  97.  */
  98.     gexit();
  99. }
  100.