Exemple #1
0
int main(int argc, char *argv[])
{
   int width = 16, height = 16;		/* Dimensions of texture */
   int i, j;				/* Loop variables */
   int idx;				/* Index into texture array */
   unsigned char *tex;				/* Array of texture values */

   srand48((long)time(NULL));			/* Seed random numbers */
   s2opend("/?",argc,argv);			/* Open the display */
   s2svp(-1.0,1.0, -1.0,1.0, -1.0,1.0);		/* Set the viewport coords */
   s2swin(-1.0,1.0, -1.0,1.0, -1.0,1.0);	/* Set the window coordinates */
   s2box("BCDE",0,0,"BCDE",0,0,"BCDE",0,0);	/* Draw a bounding box */

   tid = ss2ct(width, height);		/* Create a new texture */
   tex = ss2gt(tid, &width, &height);	/* Get the texture */

   for (j=0;j<height;j++) {
      for (i=0;i<width;i++) {
         idx = (j*width + i) * 4;		/* Stored as (r,g,b,alpha) */
         tex[idx  ] = 127*drand48()+128;	/* Randomish red */
         tex[idx+1] = 0;			/* Green */
         tex[idx+2] = 0;			/* Blue */
						/* Do nothing to alpha */
      }
   }
   ss2pt(tid);				/* Push texture for usage */

   cs2scb(&cb);				/* Install a callback */

   s2show(1);				/* Open the s2plot window */

   return 1;
}
Exemple #2
0
int main(int argc, char *argv[])
{
   int Nx = 32, Ny = 32, Nz = 32;		/* Texture dimensions */
   int w,h,d;					/* Returned dimensions */

   s2opend("/?",argc,argv);			/* Open the s2plot display device */
   s2swin(-1,1,-1,1,-1,1);			/* Set the world coordinates */
   s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0);
	
   texid = ss2c3dt(Nx, Ny, Nz);			/* Create a new 3d texture */
   unsigned char *bits = (unsigned char *)ss2g3dt(texid, &w, &h, &d);
						/* Get the texture data for modification */
   int i, j, k;
   long idx;
   float x,y,z;  
   for (i=0;i<Nx;i++) {
      x = -1.0 + i*(2.0/(float)(Nx-1));
      for (j=0;j<Ny;j++) {
         y = -1.0 + j*(2.0/(float)(Ny-1));
         for (k=0;k<Nz;k++) {
            z = -1.0 + k*(2.0/(float)(Nz-1));
            idx = ((i*Ny + j)*Nz + k)*4;
	    if ((x*x + y*y + z*z) < 1.0) {	/* 3D solid red sphere */
               bits[idx + 1 ] = 255;
               ns2point(x,y,z,1,1,1);		/* Plot point in sphere */
            } else { 
               bits[idx + 0 ] = 0;
            }

	    bits[idx + 1 ] = 0;			/* Blue channel */
	    bits[idx + 2 ] = 0;			/* Green channel */
	    bits[idx + 3 ] = 255;		/* Alpha channel */
         }     
      }     
   }     

   fprintf(stderr, "3d texture IS %d x %d x %d\n", w, h, d);
   ss2pt(texid);				/* Push back the texture */

   cs2scb(cb);					/* Install a dynamic callback */
   				
   s2show(1);					/* Display the geometry */

   return 0;
}