Function:ss2dt
From S2PLOT
(Difference between revisions)
Revision as of 01:16, 30 October 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" | ||
int main(int argc, char *argv[]) | int main(int argc, char *argv[]) | ||
{ | { | ||
- | int texid; /* ID for this texture */ | + | int texid; /* ID for this texture */ |
- | char *tex; /* Array holding texture */ | + | char *tex; /* Array holding texture */ |
- | int width, height; /* Dimensions of texture */ | + | int width, height; /* Dimensions of texture */ |
- | int i, j; /* Loop variables */ | + | int i, j; /* Loop variables */ |
- | int idx; /* Temporary index into array */ | + | int idx; /* Temporary index into array */ |
- | XYZ xyz = { 0.0, 0.0, 0.0 }; /* Location of sphere */ | + | XYZ xyz = { 0.0, 0.0, 0.0 }; /* Location of sphere */ |
- | float r = 0.3; /* Radius of sphere */ | + | float r = 0.3; /* Radius of sphere */ |
- | COLOUR col = { 1.0, 1.0, 1.0 }; /* Colour of sphere */ | + | COLOUR col = { 1.0, 1.0, 1.0 }; /* Colour of sphere */ |
- | s2opend("/?",argc, argv); /* Open the display */ | + | srand48((long)time(NULL)); /* Seed random numbers */ |
- | s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */ | + | s2opend("/?",argc, argv); /* Open the display */ |
- | s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */ | + | s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */ |
+ | s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */ | ||
- | width = 128; /* Width of new texture */ | + | width = 128; /* Width of new texture */ |
- | height = 16; /* Height of new texture */ | + | height = 16; /* Height of new texture */ |
- | texid = ss2ct(width, height); /* Create a new texture */ | + | texid = ss2ct(width, height); /* Create a new texture */ |
- | tex = ss2gt(texid, &width, &height); /* Store texture */ | + | tex = ss2gt(texid, &width, &height); /* Store texture */ |
- | for (j=0;j<height;j++) { | + | for (j=0;j<height;j++) { |
for (i=0;i<width;i++) { | for (i=0;i<width;i++) { | ||
- | idx = (j*width + i)*4; /* Stored as (r, g, b, alpha) */ | + | idx = (j*width + i)*4; /* Stored as (r, g, b, alpha) */ |
- | tex[idx ] = 127*drand48()+128; /* Randomish Red */ | + | tex[idx ] = 127*drand48()+128; /* Randomish Red */ |
- | tex[idx+1] = 0; /* Green */ | + | tex[idx+1] = 0; /* Green */ |
- | tex[idx+2] = 0; /* Blue */ | + | tex[idx+2] = 0; /* Blue */ |
- | /* Do nothing to alpha */ | + | /* Do nothing to alpha */ |
} | } | ||
} | } | ||
- | ss2pt(texid); /* Restore texture for use */ | + | ss2pt(texid); /* Restore texture for use */ |
- | ns2vspherex(xyz, r, col, texid); /* Draw textured sphere */ | + | ns2vspherex(xyz, r, col, texid); /* Draw textured sphere */ |
fprintf(stderr,"There should be no texture on the sphere\n"); | fprintf(stderr,"There should be no texture on the sphere\n"); | ||
- | ss2dt(texid); /* Delete the texture */ | + | ss2dt(texid); /* Delete the texture */ |
- | s2show(1); /* Open the s2plot window */ | + | s2show(1); /* Open the s2plot window */ |
return 1; | return 1; | ||
} | } | ||
+ | |||
</pre></code> | </pre></code> | ||
[[S2PLOT:Function List | Back]] to S2PLOT function list. | [[S2PLOT:Function List | Back]] to S2PLOT function list. | ||
__NOTOC__ | __NOTOC__ | ||
__NOEDITSECTION__ | __NOEDITSECTION__ |
Current revision
ss2dt
Delete a texture
Prototype
unsigned int ss2ct(int width, int height);
Description
Delete a texture that is no longer required.
See Also
ss2ct | Create a texture with specified width and height |
ss2lt | Load a texture for future (generally repeated) use. |
ss2pt | Reinstall a texture. |
ss2gt | Get a pointer to an identified texture. |
Code Example
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "s2plot.h"
int main(int argc, char *argv[])
{
int texid; /* ID for this texture */
char *tex; /* Array holding texture */
int width, height; /* Dimensions of texture */
int i, j; /* Loop variables */
int idx; /* Temporary index into array */
XYZ xyz = { 0.0, 0.0, 0.0 }; /* Location of sphere */
float r = 0.3; /* Radius of sphere */
COLOUR col = { 1.0, 1.0, 1.0 }; /* Colour of sphere */
srand48((long)time(NULL)); /* Seed random numbers */
s2opend("/?",argc, argv); /* Open the display */
s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */
s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */
width = 128; /* Width of new texture */
height = 16; /* Height of new texture */
texid = ss2ct(width, height); /* Create a new texture */
tex = ss2gt(texid, &width, &height); /* Store 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(texid); /* Restore texture for use */
ns2vspherex(xyz, r, col, texid); /* Draw textured sphere */
fprintf(stderr,"There should be no texture on the sphere\n");
ss2dt(texid); /* Delete the texture */
s2show(1); /* Open the s2plot window */
return 1;
}
Back to S2PLOT function list.