home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_04 / 1n04068a < prev    next >
Text File  |  1990-08-06  |  3KB  |  140 lines

  1. /* wrld8.cpp */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6.  
  7. #include <typedefs.hpp>
  8.  
  9. extern "C"
  10. {
  11.     #include <tiga.h>
  12.     #include <extend.h>
  13. }
  14.  
  15. #define gspPoints( n, p, q )        \
  16.     dm_ptrx( USER_DM( gspWorld | 0 ), n * sizeof(POINT), \
  17.         p, n * sizeof(POINT), q )
  18. #define gspDraw( )        cp_cmd( USER_CP( gspWorld | 1 ), 0 )
  19.  
  20. struct    POINT
  21. {
  22.   int    x;
  23.   int    y;
  24. };
  25.  
  26. int    gspWorld;
  27.  
  28. POINT    snd_points[5] =
  29. {
  30.   25, 25, 75, 25, 50, 50, 25, 75, 75, 75
  31. };
  32.  
  33. POINT    rcv_points[5];
  34.  
  35. void        reportPositionTable( )
  36. {
  37.   printf( "Text displayed at:\n" );
  38.   for( int i = 0; i < 5; i++ )
  39.     printf( "  %4d, %4d  ==> %4d  %4d \n", snd_points[i].x,
  40.         snd_points[i].y, rcv_points[i].x, rcv_points[i].y );
  41. }
  42.  
  43. int        main( int argc, char argv[ ] )
  44. {
  45.   
  46.   if( set_videomode( TIGA, INIT | CLR_SCREEN ) )
  47.   { 
  48.     if( install_primitives( ) >= 0 )
  49.     {
  50.       gspWorld = install_rlm( "gspWrld8.rlm" );
  51.       if( gspWorld < 0 )
  52.       {
  53.         printf("ERROR: could not load gspWrld8.rlm\n");
  54.         printf("Error code = %d\n", gspWorld );
  55.         exit( 7 );
  56.       }
  57.       gspPoints( 5, snd_points, rcv_points );
  58.       gspDraw( );
  59.       reportPositionTable( );
  60.     }
  61.     else
  62.     {
  63.       printf( "ERROR: Can not load TIGA primitives.\n" );
  64.       return 1;
  65.     }
  66.     set_videomode( PREVIOUS, NO_INIT );
  67.   }
  68.   else
  69.   {
  70.     printf( "ERROR: Please install TIGA and try again.\n" );
  71.     return 2;
  72.   }
  73.   return 0;
  74. }
  75.  
  76. /* gspWrld8.c */
  77.  
  78. #include <gsptypes.h>
  79. #include <gspglobs.h>
  80. #include <gsptiga.h>
  81.  
  82. #define XSIZE    (config.mode.disp_hres)
  83. #define YSIZE    (config.mode.disp_vres)
  84. #define    XOR    10
  85.  
  86. #define    MAX_POINTS    10
  87.  
  88. static    int    pointCount;
  89. static    int    xPosition[MAX_POINTS];
  90. static    int    yPosition[MAX_POINTS];
  91.  
  92. void        gspPoints( p )
  93. short*    p;
  94. {
  95.   int count;
  96.   int x, y, i;
  97.   
  98.   count = *p++;            /* get count (in bytes).    */
  99.   count = count /4;        /* number of points        */
  100.   if( count > MAX_POINTS )    /* protect against array
  101.                                    overflow */
  102.     count = MAX_POINTS;
  103.  
  104.   for( i = 0; i < count; i++ )
  105.   {
  106.     *p++ = xPosition[i] = *p * XSIZE / 100;
  107.     *p++ = yPosition[i] = *p * YSIZE / 100;
  108.   }
  109.   pointCount = count;
  110. }
  111.  
  112. void        gspDraw( )
  113. {
  114.   int count;
  115.   int i;
  116.   int tw;
  117.   char* hello;
  118.   
  119.   count = pointCount;        /* number of points        */
  120.  
  121.   set_fcolor( WHITE );
  122.   set_bcolor( BLACK );
  123.  
  124.   hello = "   H e l l o   W o r l d   ";
  125.   tw = text_width( hello );    /* string width for
  126.                                    centering    */
  127.   
  128.   for( i = 0; i < count; i++ )
  129.   {
  130.     text_out( xPosition[i] - tw/2, yPosition[i],
  131.                  "   H e l l o   W o r l d   " );
  132.   }
  133. }
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.