Пример #1
0
int main(int argc, char *argv[])
{
  ginit();
  prefsize(640, 480);
  winopen("Asteroids");
  init();
  event_loop();
  gexit();
  return 0;
}
Пример #2
0
void
reset_grafx()
{
#ifdef IRIS
#undef setvaluator
  setvaluator(MOUSEX,getgdesc(GD_XPMAX)/2,0,getgdesc(GD_XPMAX));
  setvaluator(MOUSEY,getgdesc(GD_YPMAX)/2,0,getgdesc(GD_YPMAX));
#define setvaluator gl_setvaluator
  attachcursor(MOUSEX,MOUSEY);
  setcursor(0,0,0);
  curson();
  gexit();
#endif
}
Пример #3
0
int main (int argc, char *argv[])
{
   static char cvs_info[] = "BMkGRP $Date: $ $Revision: $ $RCSfile: all2all_main.c,v $ $Name: $";

   int itr;
   int idx;
   brand_t br;
   timer t, t0, t1;
   double nsec;

   double total_time = 0.0;
  
   int status = 0;
  
   int64 i, seed, arg, msize, tsize, len, oldsize=0, rep, cksum;
   uint64 *tab=NULL;
  
   start_pes(0);
   SELF=_my_pe();
   SIZE=_n_pes();

   if (argc < 5) {
      if (SELF == 0)
         fprintf (stderr, "Usage:\t%s seed msg_size(B) table_size(MB) rep_cnt "
	          "[ms2 ts2 rc2 ..]\n", argv[0]);
         status = 1;
      goto DONE;
   }
   seed = atol (argv[1]);
   if (SELF == 0)
      printf ("base seed is %ld\n", seed);
   seed += SELF << 32;
   brand_init (&br, seed);  // seed uniquely per PE

   arg = 2;
  
   while (arg < argc) {
    
    
      msize = atol (argv[arg++]);               if (arg >= argc)  break;
      /* Table size * 1 million. */
      tsize = atol (argv[arg++]) * (1L << 20);  if (arg >= argc)  break;
      //rep   = atol (argv[arg++]);
      rep   = 1;
      arg++;

      if (SELF == 0)  printf ("tsize = %ldMB  msize = %dB\n",
			        tsize/(1L<<20), msize);
      if (msize < sizeof(long)) {
         if (SELF == 0)  printf ("msize too short!\n");
         //status = 1;
         goto DONE;
      }
      //itr=0;

      idx = 0;

      switch(SIZE){
         case 2:
            idx = 0;
            break;
         case 4:
            idx = 1;
            break;
         case 8:
            idx = 2;
            break;
         default:
            fprintf(stderr,"warning, check sum for (%d) pes not supported.\n",
                        SIZE);
      }
 
      while (rep-- > 0) {

         /* START TIMING */
         //timer_clear (&t0);
         //timer_clear (&t1);
         //timer_start (&t0);
	    
         if ((tab == NULL) || (tsize > oldsize)) {
	   if (tab != NULL) {
	      dram_shfree (tab);
	      oldsize = 0;
	   }
	   if (SELF == 0)  printf ("trying dram_shmalloc of %ld bytes\n", tsize);
	   tab = (uint64 *) dram_shmalloc (tsize);
	
	   if (tab == NULL) {
	      if (SELF == 0)  printf ("dram_shmalloc failed!\n");
               status = 1;
	      goto DONE;
	  
	   }
	   oldsize = tsize;
         }
      
         // length in words
         len = tsize / sizeof(uint64);
      
         // important to init table
         // to ensure cksum consistency on different platforms
         memset(tab,0,tsize);
      
         for (i = 0; i < len; i+=64){
            tab[i] = brand(&br);
         }
     
         // we'll have destination/source arrays each of half size
         len /= 2;

         //timer_stop (&t0);
         // source checksum
         cksum = do_cksum (&tab[len], len);
         if (SELF == 0)  printf ("cksum is %016lx\n", cksum);
         if (SELF == 0){
            //if(cksum!=ckv[itr++]){
            /* Set up for one iteration only. */
            if(cksum!=ckv[idx]){
               printf ("cksum  %016lx != ckv[%d] %016x\n",cksum,idx,ckv[idx]);
	         gexit(1);
	   }
          
         }      	      

         //timer_start (&t1);
         len = do_all2all (&tab[0], &tab[len], len, msize/sizeof(uint64));
      
         shmem_barrier_all();
      
         //timer_stop (&t1);
         /* END TIMING */
#if 0

         // dest checksum
         i = do_cksum (&tab[0], len);
         if (i != cksum) {
	   printf ("PE %4ld  ERROR: %016lx != %016lx\n", SIZE, i, cksum);
	   status = 1;
	   goto DONE;
         }

#ifndef CHECKOFF
         if (i != known_v[gv]) {
            printf ("CHECKSUM PE %4ld  ERROR: %016lx != %016lx\n", SIZE, i, known_v[gv]);
            status = 1;
            goto DONE;
         }
         gv++;
#endif


         //t.accum_wall = t0.accum_wall + t1.accum_wall;
         //t.accum_cpus = t0.accum_cpus + t1.accum_cpus;


         /*if (SELF == 0) {

#ifdef PTIMES
	   printf ("%8.3f %8.3f\n",    t0.accum_wall , t1.accum_wall);
	   printf ("%8.3f %8.3f\n",    t0.accum_cpus , t1.accum_cpus);
#endif
	   printf ("wall reports %8.3f secs  cpus report %8.3f secs\n",
		    t.accum_wall, t.accum_cpus);
	   nsec = MAX(t.accum_wall, t.accum_cpus);
            total_time += nsec;
	   if (nsec > 0)
	     printf ("%8.3f MB/sec with %ld bytes transfers\n",
		     len*sizeof(uint64)/(double)(1L<<20)/nsec, msize);
         }*/
#endif
      }
      //if (SELF == 0)
         //printf ("\n");
   }
   //if (SELF == 0)
   //{
      //printf ("total time = %14.9f\n", total_time);

   //}
 
 DONE: 
   shmem_barrier_all();
   return status;
}
Пример #4
0
/*
 * display all the hershey fonts and demonstrate textang
 */
main()
{
	char	buf[50];
	char	*str1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
	char	*str2 = "abcdefghijklmnopqrstuvwxyz" ;
	char	*str3 = "1234567890+-=!@#$%^&*(){}[]" ;
	char	*str4 = "<>,./?~`\\|_BONK,blark" ;
	int	i;
	short	val;

	vinit("mswin");
	winopen("circtxt");

	hleftjustify(1);

	unqdevice(INPUTCHANGE);
	qdevice(KEYBD);
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&val) != REDRAW)
		;

	color(BLACK);
	clear();

	ortho2(-14.0, 14.0, -14.0, 14.0);	/* define the world space */

	for(i = 0; i < 22; i++) {

		/*
		 * textang is used to specify the orientation of text. As
		 * we want the title to come out straight we make sure it is
		 * zero each time we go through this loop.
		 */
		htextang(0.0);

		/*
		 * do the title
		 */
		color(YELLOW);
		hfont("futura.m");
		sprintf(buf, "This is hershey font %s", fonts[i]);
		hboxtext(-11.0, 12.0, 20.0, 1.0, buf);

		/*
		 * draw a box around the title
		 */
		rect(-11.0, 12.0, 9.0, 13.0);

		color(GREEN);

		hfont(fonts[i]);		/* grab a font from the table */

		htextsize(1.5, 1.5);		/* show the outer ring */
		ShowCircularText(11.0, str1);

		htextsize(1.3, 1.3);		/* show the second ring */
		ShowCircularText(8.5, str2);

		htextsize(1.1, 1.1);		/* show the third ring */
		ShowCircularText(7.0, str3);

		htextsize(0.9, 0.9);		/* show the inside ring */
		ShowCircularText(5.0, str4);

		if (qread(&val)) {
			if (val == 'q') {
				gexit();
				exit(0);
			}
		}

		color(BLACK);
		clear();
	}

	gexit();
}
Пример #5
0
/*
 * using curves
 */
main()
{
	char	dev[20];
	int	i;
	short	val;

	vinit("mswin");
	winopen("curves");

	qdevice(KEYBD);
	unqdevice(INPUTCHANGE);
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&val) != REDRAW)
		;

	ortho2(-200.0, 400.0, -100.0, 500.0);

	color(BLACK);
	clear();

	color(YELLOW);

	/*
	 * label the control points in geom1
	 */
        for (i = 0; i < 4; i++) {
		cmov2(geom1[i][0], geom1[i][1]);
		sprintf(dev, "%d", i);
		charstr(dev);
	}
								 
	/*
	 * label the control points in geom2
	 */
	for (i = 0; i < 6; i++) {
		cmov2(geom2[i][0], geom2[i][1]);
		sprintf(dev, "%d", i);
		charstr(dev);
	}

	/*
	 * set the number of line segments appearing in each curve to 20
	 */
	curveprecision((short)20);

	/*
	 * copy the bezier basis matrix into the basis matrix stack and
	 * set the curve basis accordingly.
	 */
	defbasis((short)1, bezier);
	curvebasis((short)1);

	color(RED);

	/*
	 * draw a curve using the current basis matrix (bezier in this case)
	 * and the control points in geom1
	 */
	crv(geom1);

	cmov2(70.0, 60.0);
	charstr("Bezier Curve Segment");

	cmov2(-190.0, 450.0);
	charstr("Three overlapping Bezier Curves");

	/*
	 * crvn draws overlapping curve segments according to geom2, the
	 * number of curve segments drawn is three less than the number of
	 * points passed, assuming there are a least four points in the
	 * geometry matrix (in this case geom2). This call will draw 3
	 * overlapping curve segments in the current basis matrix - still
	 * bezier.
	 */
	crvn(6L, geom2);

	qread(&val);

	/*
	 * load in the cardinal basis matrix
	 */
	defbasis((short)1, cardinal);
	curvebasis((short)1);

	color(MAGENTA);

	cmov2(70.0, 10.0);
	charstr("Cardinal Curve Segment");

	/*
	 * plot out a curve segment using the cardinal basis matrix
	 */
	crv(geom1);

	cmov2(-190.0, 400.0);
	charstr("Three overlapping Cardinal Curves");

	/*
	 * now draw a bunch of them again.
	 */
	crvn(6L, geom2);

	qread(&val);

	/*
	 * change the basis matrix again
	 */
	defbasis((short)1, bspline);
	curvebasis((short)1);

	color(GREEN);

	cmov2(70.0, -40.0);
	charstr("Bspline Curve Segment");

	/*
	 * now draw our curve segment in the new basis...
	 */
	crv(geom1);

	cmov2(-190.0, 350.0);
	charstr("Three overlapping Bspline Curves");

	/*
	 * ...and do some overlapping ones
	 */
	crvn(6L, geom2);

	qread(&val);

	gexit();
}
Пример #6
0
main()
{
        char    *p;
	float	tdir = TRANS;
	float	scal = 1.0 + SCAL;
	int	but, nplanes;
	int	x, y, i, n;
	short	val;
	int	bf = 1;
	int	fill = 1;

	prefsize(500L, 500L);

	vinit("mswin");
	winopen("lcube");

	unqdevice(INPUTCHANGE);
	qdevice(SKEY);
	qdevice(XKEY);
	qdevice(YKEY);
	qdevice(ZKEY);
	qdevice(EQUALKEY);
	qdevice(MINUSKEY);
	qdevice(ESCKEY);
	qdevice(QKEY);
	qdevice(FKEY);
	qdevice(BKEY);
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&val) != REDRAW)
		;
	

	window(-800.0, 800.0, -800.0, 800.0, -800.0, 800.0);
	lookat(0.0, 0.0, 1500.0, 0.0, 0.0, 0.0, 0);

	if ((nplanes = getplanes()) == 1)
		makecubes(0);

	makecubes(1);

	backface(1);
		
	doublebuffer();
	gconfig();

	/*
	 * Doublebuffer does a backbuffer(TRUE)....
	 */

	while(1) {
		x = 500 - (int)getvaluator(MOUSEX);
		y = 500 - (int)getvaluator(MOUSEY);
		x *= 3;
		y *= 3;
		pushmatrix();
			rotate(x, 'y');
			rotate(y, 'x');
			color(BLACK);
			clear();
			callobj((Object)3);
			if (nplanes == 1)
				callobj((Object)2);
		popmatrix();
		swapbuffers();

		if (qtest()) {
			but = qread(&val);
			but = qread(&val);	/* swallow up event */

			switch (but) {

			case SKEY:
				scale(scal, scal, scal);
				break;
			case XKEY:
				translate(tdir, 0.0, 0.0);
				break;
			case YKEY:
				translate(0.0, tdir, 0.0);
				break;
			case ZKEY:
				translate(0.0, 0.0, tdir);
				break;
			case MINUSKEY:
				tdir = -tdir;

				if (scal < 1.0)
					scal = 1.0 + SCAL;
				else
					scal = 1.0 - SCAL;

				break;
			case EQUALKEY:
				tdir = TRANS;
				break;
			case BKEY:
				bf = !bf;
				backface(bf);
				break;
			case FKEY:
				fill = !fill;
				if (fill)
					polymode(PYM_FILL);
				else
					polymode(PYM_LINE);
				break;
			case ESCKEY:
			case QKEY:
				gexit();
				exit(0);
			default:
				;
			}
		}
	}
}
Пример #7
0
main()
{
	int	i, itest,  dobackface, dofill, dodouble;
	char	buf[100];
	float	H;
	short	idata;
	int	xr, yr;

	vinit("mswin");
	winopen("piston");
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&idata) != REDRAW)
		;

	doublebuffer();

	gconfig();

	unqdevice(INPUTCHANGE);
	qdevice(QKEY);
	qdevice(FKEY);
	qdevice(BKEY);
	qdevice(ESCKEY);
        qdevice(REDRAW);

	makecyl();

	polymode(PYM_FILL);

	backface(1);
/*
 * set up a perspective projection with a field of view of
 * 40.0 degrees, aspect ratio of 1.0, near clipping plane 0.1,
 * and the far clipping plane at 1000.0.
 */
	perspective(400, 1.5, 0.1, 600.0);
	lookat(0.0, -6.0, 4., 0.0, 0.0, 0.0, 0);

/*
 * here we loop back here adnaseum until someone hits a key
 */
	xr = yr = 0;

 	while(1) {
		for (i = 0; i < 360; i += 5) {
			color(BLACK);
			clear();
			color(RED);
			H = 1.0 + cos(2.0 * 3.14159265*i / 180.0);

			yr = 500 - (int)getvaluator(MOUSEY);
			xr = 500 - (int)getvaluator(MOUSEX);
			yr = 500 - (int)getvaluator(MOUSEY);
			xr *= 3;
			yr *= 3;

			pushmatrix();
				rotate(xr, 'x');
				rotate(yr, 'y');
				piston(H);
			popmatrix();

			if (dodouble)
				swapbuffers();

			if (qtest()) {
				itest = qread(&idata);
				itest = qread(&idata); /* Zap Up event */
				if (itest == BKEY) {
					dobackface = !dobackface;
					backface(dobackface);
				} else if (itest == FKEY) {
					dofill = !dofill;
					if (dofill)
						polymode(PYM_FILL);
					else
						polymode(PYM_LINE);
				} else if(itest == QKEY || itest == ESCKEY) {
					 gexit();
					 exit(0);
				}

			}
		}
	}
}
Пример #8
0
/*
 * a routine to demonstrate using locator.
 */
main()
{
	int		i, bt, act, nchars;
	short		data;
	Scoord		x, y, sx, sy;
	Screencoord	minx, maxx, miny, maxy;

	ginit();

	color(BLACK);
	clear();

	color(BLUE);

	getviewport(&minx, &maxx, &miny, &maxy);

	ortho2((Coord)minx, (Coord)maxx, (Coord)miny, (Coord)maxy);

	/*
	 * draw some axes
	 */
	move2s((Scoord)minx, (Scoord)((maxy - miny) / 2));
	draw2s((Scoord)maxx, (Scoord)((maxy - miny) / 2));

	move2s((Scoord)((maxx - minx) / 2), (Scoord)miny);
	draw2s((Scoord)((maxx - minx) / 2), (Scoord)maxy);

	color(GREEN);

	/*
	 * enable the left and middle mouse buttons
	 */
	unqdevice(INPUTCHANGE);
	qdevice(LEFTMOUSE);
	qdevice(MIDDLEMOUSE);
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&data) != REDRAW)
		;

	act = 0;

	/*
	 * getvaluator tells us the valuator's value. In
	 * this case it's the X and Y positions of the mouse.
	 * Note: these come back to us in screen coordinates.
	 */
	while((bt = qread(&data)) != MIDDLEMOUSE) {
		sx = getvaluator(MOUSEX);
		sy = getvaluator(MOUSEY);
		if (bt == -1) {
			gexit();
			printf("No locator device found\n");
			exit(0);
		} else {
			if (act) {
				act = 0;
				move2s(sx, sy);
				draw2s(x, y);
			} else {
				act = 1;
				x = sx;
				y = sy;
			}
		}
		(void)qread(&data);	/* swallow the up event */
	}

	gexit();

}
Пример #9
0
main()
{
    float ship[XY];
    long org[XY];
    long size[XY];
    Device dev;
    short val;
    Device mdev[XY];
    short mval[XY];
    long nhits;
    short buffer[BUFSIZE];
    Boolean run;

    prefsize(400, 400);
    winopen("select1");
    getorigin(&org[X], &org[Y]);
    getsize(&size[X], &size[Y]);
    mmode(MVIEWING);
    ortho2(-0.5, size[X] - 0.5, -0.5, size[Y] - 0.5);
    qdevice(LEFTMOUSE);
    qdevice(ESCKEY);
    color(BLACK);
    clear();
    mdev[X] = MOUSEX;
    mdev[Y] = MOUSEY;

    drawplanet();
    run = TRUE;
    while (run) {
	dev = qread(&val);
	if (val == 0) {				/* on upstroke */
	    switch (dev) {
	    case LEFTMOUSE:
		getdev(XY, mdev, mval);
		ship[X] = mval[X] - org[X];
		ship[Y] = mval[Y] - org[Y];
		color(BLUE);
		sbox(ship[X], ship[Y], 
		     ship[X] + SHIPWIDTH, ship[Y] + SHIPHEIGHT);

		/*
		 * specify the selecting region to be a box surrounding the
		 * rocket ship 
		 */
		ortho2(ship[X], ship[X] + SHIPWIDTH, 
		       ship[Y], ship[Y] + SHIPHEIGHT);

		initnames();
		gselect(buffer, BUFSIZE);
		    loadname(PLANET);
		    /* no actual drawing takes place */
		    drawplanet();
		nhits = endselect(buffer);

		/*
		 * restore the Projection matrix; NB. can't use push/popmatrix 
		 * since they only work for the ModelView matrix stack 
		 * when in MVIEWING mode
		 */
		ortho2(-0.5, size[X] - 0.5, -0.5, size[Y] - 0.5);

		/* 
		 * check to see if PLANET was selected; NB. nhits is NOT the
		 * number of buffer elements written
		 */
		if (nhits < 0) {
		    fprintf(stderr, "gselect buffer overflow\n");
		    run = FALSE;
		} 
		else if (nhits >= 1 && buffer[0] == 1 && buffer[1] == PLANET)
		    ringbell();
		break;
	    case ESCKEY:
		run = FALSE;
		break;
	    }
	}
    }
    gexit();
    return 0;
}
Пример #10
0
/*
 * Using polygons, hatching, and filling.
 */
main()
{
	short	val;

	winopen("poly");

	unqdevice(INPUTCHANGE);
	qdevice(KEYBD);		/* enable keyboard */
	/* 
	 * Wait for REDRAW event ...
	 */
	while (qread(&val) != REDRAW)
		;

	color(BLACK);		/* clear to black */
	clear();

	/*
	 * world coordinates are now in the range -10 to 10
	 * in x, y, and z. Note that positive z is towards us.
	 */
	ortho(-10.0, 10.0, -10.0, 10.0, 10.0, -10.0);

	color(YELLOW);

	/*
	 * write out the string "Polygon from poly()" in the
	 * starting at (-8.0, -4.0) and scaled to be 4.0 units long,
	 * 0.5 units high.
	 */
	hfont("futura.m");
	hboxtext(-8.0, -4.0, 4.0, 0.5, "Polygon from poly()/ polf()");

	color(GREEN);

	/*
	 * write out a scaled string starting at (0.0, 6.0)
	 */
	hboxtext(0.0, 6.0, 4.5, 0.5, "Polygon from bgnpoly()/ endpoly()");
	hboxtext(0.0, 5.0, 4.5, 0.5, "             pmv()/ pdr()/ pclos()");

	color(MAGENTA);

	/*
	 * write out a scaled string starting at (0.0, 6.0)
	 */
	hboxtext(3.5, -3.5, 1.9, 0.5, "Arc/ Arcf");

	/*
	 * draw some wire frame polygons
	 */
	drawpoly();

	/*
	 *  rotate so the next polygons will appear in a different place.
	 */
	rot(20.0, 'x');
	rot(30.0, 'y');

	/*
	 * draw some filled polygons.
	 */
	drawpolyf();

	gexit();
}