Function:ss2wtga

From S2PLOT

(Difference between revisions)
Jump to: navigation, search
Revision as of 04:16, 4 December 2007
S2plot admin (Talk | contribs)

← Previous diff
Current revision
S2plot admin (Talk | contribs)

Line 26: Line 26:
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
 +#include <time.h>
#include "s2plot.h" #include "s2plot.h"
Line 31: Line 32:
{ {
static int lkc = 0; /* Has the spacebar been pressed? */ static int lkc = 0; /* Has the spacebar been pressed? */
- static int mode = 0; /* Should a frame be dumped */+ static int mode = 0; /* Should a frame be dumped */
static int frame = 0; /* Current output frame number */ static int frame = 0; /* Current output frame number */
if (*kc != lkc) { /* Has spacebar been pressed? */ if (*kc != lkc) { /* Has spacebar been pressed? */
if (!mode) { /* What is the current mode? */ if (!mode) { /* What is the current mode? */
- char string[64];+ char string[64];
sprintf(string,"myframe_%d",frame); /* Prepare filename */ sprintf(string,"myframe_%d",frame); /* Prepare filename */
fprintf(stderr,"Dumping frame: %s\n",string); /* Output message */ fprintf(stderr,"Dumping frame: %s\n",string); /* Output message */
ss2wtga(string); /* Write screen image to TGA file */ ss2wtga(string); /* Write screen image to TGA file */
frame++; /* Increment frame number */ frame++; /* Increment frame number */
- }+ }
mode = 1; /* Set mode - do not dump again */ mode = 1; /* Set mode - do not dump again */
} else { /* Write user message */ } else { /* Write user message */
Line 53: Line 54:
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
 + srand48((long)time(NULL)); /* Seed random numbers */
s2opend("/s2mono", argc, argv); /* Open in mono mode */ s2opend("/s2mono", argc, argv); /* Open in mono mode */
s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */ s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */
Line 60: Line 62:
XYZ xyz; XYZ xyz;
COLOUR col; COLOUR col;
- +
for (i=0;i<N;i++) { for (i=0;i<N;i++) {
xyz.x = drand48()*2.0 - 1.0; /* Random position */ xyz.x = drand48()*2.0 - 1.0; /* Random position */
Line 76: Line 78:
return 1; return 1;
} }
 +
</pre></code> </pre></code>

Current revision

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

s2showDraw the scene and enter interactive mode.
s2dispDraw the scene but return control on timeout.
ss2gpixFetch the current RGB buffer.

Code Example

#include <stdio.h>
#include <stdlib.h>
#include <time.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[])
{
   srand48((long)time(NULL));           /* Seed random numbers */
   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.


Personal tools