SGI Example

The tables 4.3.8 and [*] give a simple example for an application that uses the sgi routines. The output is shown in figure 4.3.8.


Table 4.1: The Entry Points: Making sgi_demo
 
LIBS=-g -lm -lc -L/usr/X11R6/lib -lX11

GRA_LIBRARY=directory_containing_gra_lib.a

sgi_demo : sgi_demo.o
        gcc $(LIBS) sgi_demo.o $(GRA_LIBRARY)/gra_lib.a atvme_dummy.o -o sgi_demo

sgi_demo.o: sgi_demo.c
        gcc -c sgi_demo.c -o sgi_demo.o



Table 4.2: The Entry Points: sgi_demo.c
 
/*
   this file demonstrates how to use the
     Simple Graphical Interface
*/
#include <math.h>

main()
{
  int ws;

  while(1)
    {
      printf("\nChoose WS (1 X11, 2 Postscript, 3 REGIS, 4 TEKxxx, 5 Exit): ");
      scanf("%d", &ws);

      if( ws >= 1 && ws <= 4)
        {
          spirale( ws);
        }
      else
        {
          break;
        }
    }

  return;
}

int spirale( int ws)
{
  double t, r = 1.0;
  double x, y;
  int i = 0;

  sgi_open( ws);

  sgi_cls();

  /*
     Colours:
      0 white
      1 black
      2 red
      3 green
      4 blue
      5 ...

     */
  sgi_colour( 2);

  sgi_move_to( 0.5, 0.5);

  sgi_text( "Hello world");

  sgi_move_to( 1.0, 0.5);

  for( t=0.; t < 200.; t += 0.1)
    {
      i++;
      sgi_colour( i % 10);
      y = 0.5*(r*sin(t) + 1.);  
      x = 0.5*(r*cos(t) + 1.);
      r *= 0.999;
      sgi_line_to( x, y);
    }

  sgi_move_to( 0.1, 0.1);
  sgi_update();
  sleep(2);
  
  sgi_close();

}


Figure 4.1: The output of sgi_demo.c
Image sgi_demo