1
votes

I have successfully loaded a single texture using the gltLoadTGA function that I have. Now that I am trying to load multiple textures it's not working. This is the texturing part of my setup function:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glGenTextures(numTextures, textures);

// Load the first texture
glBindTexture(GL_TEXTURE_2D, textures[SHAPE_TEX]);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
pBytes = gltLoadTGA("TexasFlag.tga", &iWidth, &iHeight, &iComponents, &eFormat);
glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, pBytes);
free(pBytes);

// Load the "A"
glBindTexture(GL_TEXTURE_2D, textures[A_TEX]);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
pBytesA = gltLoadTGA("letter a.tga", &iWidth, &iHeight, &iComponents, &eFormat);
glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, pBytesA);
free(pBytesA);

// Load the "B"
glBindTexture(GL_TEXTURE_2D, textures[B_TEX]);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
pBytesB = gltLoadTGA("letter b.tga", &iWidth, &iHeight, &iComponents, &eFormat);
glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, pBytesB);
free(pBytesB);

// Load the "C"
glBindTexture(GL_TEXTURE_2D, textures[C_TEX]);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
pBytesC = gltLoadTGA("letter c.tga", &iWidth, &iHeight, &iComponents, &eFormat);
glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, pBytesC);
free(pBytesC);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glEnable(GL_TEXTURE_2D);

And my draw function is basically: glBindTexture(GL_TEXTURE_2D, SHAPE_TEX); // draw a lot...

But no texture is showing up at all. Whats wrong?

**By the way this has to be in C only, not C++

1

1 Answers

5
votes

When you call glTexParameteri (man page), it only applies to the current texture. You will have to call it separately for each texture whose parameters you want to change, after you bind the texture. Failing to set the minification / magnification filter can make it look like texture loading failed.

You may also wish to call glGetError after attempting to load a texture, to see if it failed.