gluBuild2DMipmaps vs glTexImage2D

Here’s a snip of my code:

glGenTextures(1, &texture);						// Get the First Free Name to use for the Font Texture
glBindTexture(GL_TEXTURE_2D, texture);							// Actually create the texture object
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,MagFilter);	// parameters...
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,MinFilter);

//#if defined(__sgi)
//glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->width , image1->height , 0, GL_RGB, GL_UNSIGNED_BYTE, image1->data); // load the image data into the object
//#else
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image1->width, image1->height, GL_RGB, GL_UNSIGNED_BYTE, image1->data);
//#endif

If I’m running this on a PC and I use gluBuild2DMipmaps function, all of my 20-some textures are fine.
If I’m running this on a PC and I use glTexImage2D function, it only loads certain 3 textures, and no others.
If I’m running this on an SGI (Irix) machine and I use glTexImage2D function, it only loads the same certain 3 textures, and no others.
If I’m running this on an SGI (Irix) machine and I use gluBuild2DMipmaps function, it crashes somewhere in the glu library because of a division by 0 error.

Any ideas what’s going on here?

The two, by far, most common problems you have to watch out for is texture size and minification filter. When using glTexImage, you have to take care of both these issues yourself, while gluBuild2DMipmaps automatically takes care of it (in default settings at least).

First, texture size. Make sure each dimension of the texture is a power of two. Since OpenGL 2.0, this requirement is relaxed, but if you’re using 1.5 or earlier, you must make the size a power of two. gluBuild2DMipmaps will rescale the image to a power of two, so an “invalid” texture is modified and accepted.

Second, default minification filter requires a complete mipmap chain. glTexImage only uploads a single mipmap level, but gluBuild2DMipmaps generates them all. Set minification filter to a non-mipmap filter, which don’t require the full mipmap chain to be present. Also check out SGIS_generate_mipmap if you want mipmaps, which I would prefer over gluBuild2DMipmap.

You were right :slight_smile: It turns out I was using GL_LINEAR_MIPMAP_LINEAR for both my filters, either with or without mipmaps. Huge thanks!