1

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 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Ironically the glPixelStorei settings the OS sets for each texture upload are not bound to the texture object.
@datenwolf: When you start to think of OpenGL with a client-server model, those distinctions actually make a lot of sense. For example, arrays (the OpenGL 1.x variety) are all client-side so they are managed with glEnableClientState and the like. Basically anything that directly touches program memory is going to pass through the client, and this includes texture packing and unpacking. The client packs or unpacks the pixels to/from a myriad of formats that can be supplied by the user, and the server only has to work with packed data. So the glPixelStore behavior should be unsurprising.
Thanks, I'm well familiar with OpenGL's client server model, and use it regularily for OpenGL over GLX over TCP.
@datenwolf: That's a different concept. I'm talking about the client/server model inside OpenGL itself, even when you are not using the network. Parts of the OpenGL API manipulate client state, such as glPixelStore, which notes in the documentation that "pixel storage modes are client state". No TCP, no GLX necessary. The client/server model explains why there are separate functions glPushAttrib and glPushClientAttrib.
Where do you think the OpenGL client/server model stems from? Hint: SGI, Irix (= a Unix), X11 (a server and clients). Also the concept of Display Lists is a direct influence of X11 on OpenGL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.