Function:ss2gt

From S2PLOT

(Difference between revisions)
Jump to: navigation, search

Revision as of 23:02, 28 October 2007

ss2gt

Get a pointer to an identified texture.

Prototype

char *ss2gt(unsigned int textureID, int *width, int *height);

Description

Get a pointer to an identified texture. The return value of the function is a (char *), which points to a chunk of memory which is 4 * width * height bytes. A 4-byte segment of this memory contains r, g, b and a (alpha / transparency) values [0,255]. If the texture is not found, NULL is returned.

See Also

Textures Important information on using textures in S2PLOT.
ss2lt Load a texture for future (generally repeated) use.
ss2pt Reinstall a texture.


Code Example

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

int main(int argc, char *argv[])
{
   char *texture = "firetile2_pow2_rgb.tga";
 		/* Texture in directory pointed to by S2PLOT_TEXPATH */ 
   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 */

   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 */

   texid = ss2lt(texture);		/* Get an ID for texture */
   tex = ss2gt(texid, &width, &height);	/* Store texture */

	
   for (j=0;j<(height/2);j++) {			/* Bottom half of texture */
      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 */

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

Back to S2PLOT function list.


Personal tools