Function:ss2wtga

From S2PLOT

Revision as of 04:13, 4 December 2007; view current revision
←Older revision | Newer revision→
Jump to: navigation, search

ss2wtga

Write the current frame to a named TGA file.

Prototype

void ss2wtga(char *fname);

Description

Write the current frame image to a named TGA file. This can be used immediately after a call to s2show or s2disp to save a rendered image, or from within a callback.

For effective use, s2disp must display the image long enough to go beyond the S2PLOT "fade-in" time; the best way to do this is to set the S2PLOT_FADETIME environment variable to 0.0, and then call s2disp(0,1).

Do not include the ".tga" extension in the filename, as this is added automatically.

See Also

s2open.

Code Example

#include <stdio.h>
#include <stdlib.h>
#include "s2plot.h"

void cb(double *t, int *kc)
{
   static int lkc = 0;                  /* Has the spacebar been pressed? */
   static int mode = 0;                 /* Should a frame be dumped */
   static int frame = 0;                /* Current output frame number */

   if (*kc != lkc) {                    /* Has spacebar been pressed? */
      if (!mode) {                      /* What is the current mode? */
         char string[64];
         sprintf(string,"myframe_%d",frame);            /* Prepare filename */
         fprintf(stderr,"Dumping frame: %s\n",string);  /* Output message */
         ss2wtga(string);               /* Write screen image to TGA file */
         frame++;                       /* Increment frame number */
      }
      mode = 1;                         /* Set mode - do not dump again */
   } else {                             /* Write user message */
      s2textxy(-1,0,0,"Press <space> to dump TGA frame");
      mode = 0;                         /* Make sure ready to dump frame */
   }

   lkc = *kc;                           /* Update count of spacebar presses */
}

int main(int argc, char *argv[])
{
   s2opend("/s2mono", argc, argv);      /* Open in mono mode */
   s2swin(-1.,1., -1.,1., -1.,1.);      /* Set the window coordinates */
   s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0);  /* Draw coordinate box */

   int i, N = 200;                      /* Loop variables */
   XYZ xyz;
   COLOUR col;

   for (i=0;i<N;i++) {
      xyz.x = drand48()*2.0 - 1.0;      /* Random position */
      xyz.y = drand48()*2.0 - 1.0;
      xyz.z = drand48()*2.0 - 1.0;
      col.r = drand48()*2.0 - 1.0;      /* Random colour */
      col.g = drand48()*2.0 - 1.0;
      col.b = drand48()*2.0 - 1.0;
      ns2vthpoint(xyz, col,3);          /* Draw the point */
   }

   cs2scb(&cb);                         /* Install dynamic callback */
   s2show(1);                           /* Open the s2plot window */

   return 1;
}

Back to S2PLOT function list.