Brian Furtaw (brian++at++hotsauce.clubfed.sgi.com)
Fri, 22 Sep 1995 08:10:30 -0400
Here's some code...
#include <GL/gl.h>
#include <il/ilGenericImgFile.h>
#include <il/ilImage.h>
unsigned char *
createTex( char *imgfile, GLsizei *width, GLsizei *height, GLsizei *depth)
{
unsigned char *buffer;
ilFileImg* img = ilOpenImgFile(imgfile, "r");
if (img == NULL) {
printf ("Couldn't open image file: %s\n", imgfile);
exit(0);
}
ilSize size;
img->getSize(size);
*width = size.x;
*height = size.y;
*depth = size.c;
buffer = (unsigned char *)
malloc( size.x * size.y * size.c * sizeof(unsigned char));
img->getTile(0, 0, size.x, size.y, buffer);
return buffer;
}
GLvoid
initTex( char *tfile )
{
unsigned char *textureMap;
GLsizei width, height, depth;
textureMap = createTex( tfile, &width, &height, &depth );
// assumes textureMap is already a power of two
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D( GL_TEXTURE_2D, 0, depth, width, height, 0,
GL_RGB, GL_UNSIGNED_BYTE, textureMap);
// generate the MipMaps
gluBuild2DMipmaps( GL_TEXTURE_2D, depth, width, height,
GL_RGB, GL_UNSIGNED_BYTE, textureMap);
// set up mapping parameters
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
GL_NEAREST_MIPMAP_NEAREST);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
GLvoid
drawScene( GLvoid )
{
This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:51:54 PDT