#ifdef SCCS
static char sccsid[]="@(#)sofas.c	1.1 Oki 93/05/25";
#endif
/*
			Copyright (c) 1992 by 
			Oki Electric Industry Co., Ltd.
			All Rights Reserved
	
	
	This file is under sccs control at Oki in:
	/nfs/sole/root/sccs1.p/X11R5/mit/demos/pexdraw/s.sofas.c
*/
/*

			Copyright (c) 1992 by 
			Oki Electric Industry Co., Ltd.
			All Rights Reserved
	
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted,
 * provided that the above copyright notice appear in all copies and that
 * both that copyright notice and this permission notice appear in
 * supporting documentation, and that the name of Oki not be
 * used in advertising or publicity pertaining to distribution of the
 * software without specific, written prior permission. Oki
 * makes no representations about the suitability of this software for any
 * purpose.  It is provided "as is" without express or implied warranty.
*/
/* 27-APR-93 made into structure stuffer - PEXlib version */
/* 12-MAY-92 debugged letters */
/* 17-JUN-91 trueblue.c - find true color visual for PEX testing */
/* 17-NOV-90 visual hacking */

#include <X11/Xlib.h>
#include <X11/PEX5/PEXlib.h>

#define SET_POINT(p,a,b,c) {(p)->x=(a);(p)->y=(b);(p)->z=(c);}

#define RADICAL3 1.732
#define RAD3INV  (1.0/RADICAL3)

main (argc, argv)
     int argc;
     char  *argv[];
{
  Display		*theDisplay;
  char			*displayString = (char *)0;
  PEXExtensionInfo	*info_return;
  char			err_msg[PEXErrorStringLength];
  XID                   theStrux;  
  int                   i;
  PEXCoord p[2];
  PEXCoord verts[30];
  PEXVector normals[30];
 PEXCoord coords[4];
 PEXArrayOfVertex varr;
 PEXConnectivityData c10y[4];
 PEXListOfUShort clist[4];
 unsigned short indices[20];
 
 PEXArrayOfFacetData aFacetData;

  for ( i = 1; i<argc; i++ ) {
    if ((strncmp(argv[i],"-display",strlen(argv[i]))) == 0) {
      if (++i > argc) { printf("not enough args"); exit(1); }
      displayString = argv[i];
    } else if ((strncmp(argv[i],"-strux",strlen(argv[i]))) == 0) {
      if (++i > argc) { printf("not enough args"); exit(1); }
      theStrux = atoi(argv[i]);
    }
  }

  /*
   * Open the display and initialize the PEX extension.
   */
  
  if (!(theDisplay = XOpenDisplay(displayString)))
    {
      printf ( "Could not open display %s\n",displayString);
      exit (1);
    }
  
  if (PEXInitialize(theDisplay, &info_return, PEXErrorStringLength, err_msg))
    {
      printf ("%s\n", err_msg);
      exit (1);	    
    }

  PEXSetLineColorIndex( theDisplay, theStrux, PEXOCStore, 2);
  p[0].x = 0; p[0].y = 0; p[0].z = 0;
  p[1].x = -1; p[1].y = -1; p[1].z = -1;
  PEXPolyline(theDisplay, theStrux, PEXOCStore, 2, p );

  PEXSetSurfaceColorIndex( theDisplay, theStrux, PEXOCStore, 7 );

 
 SET_POINT(&coords[0], 0.2, 0.2, 0.2 );
 SET_POINT(&coords[1], 0.8, 0.2, 0.2 );
 SET_POINT(&coords[2], 0.5, 0.2+ 0.3*RADICAL3, 0.2 );
 SET_POINT(&coords[3], 0.5, 0.2+0.3*RAD3INV, 0.2+0.3*RADICAL3 );
 
 indices[0] = 0; indices[1] = 2; indices[2] = 1;
 indices[3] = 0; indices[4] = 3; indices[5] = 2;
 indices[6] = 0; indices[7] = 1; indices[8] = 3;
 indices[9] = 1; indices[10] = 3; indices[11] = 2;
 
 clist[0].count = 3;
 clist[0].shorts = &indices[0];
 clist[1].count = 3;
 clist[1].shorts = &indices[3];
 clist[2].count = 3;
 clist[2].shorts = &indices[6];
 clist[3].count = 3;
 clist[3].shorts = &indices[9];
 
 c10y[0].count = 1;
 c10y[0].lists = &clist[0];
 c10y[1].count = 1;
 c10y[1].lists = &clist[1];
 c10y[2].count = 1;
 c10y[2].lists = &clist[2];
 c10y[3].count = 1;
 c10y[3].lists = &clist[3];
 
 varr.no_data = coords;
 PEXSetOfFillAreaSets( theDisplay, theStrux, PEXOCStore,
		       PEXShapeUnknown, PEXGANone, PEXGANone, 
		       PEXGANone, PEXContourUnknown,
		       1, PEXColorTypeIndexed, 4, aFacetData,
		       4, varr, 12, (PEXSwitch *)0, c10y );

  XSync(theDisplay,0);
}
