1

我已经使用我拥有的 gltLoadTGA 函数成功加载了单个纹理。现在我正在尝试加载多个纹理它不起作用。这是我的设置功能的纹理部分:

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);

而我的绘制函数基本上是:glBindTexture(GL_TEXTURE_2D, SHAPE_TEX); // 画很多...

但根本没有纹理出现。怎么了?

**顺便说一句,这只能在 C 中,而不是 C++

4

1 回答 1

5

当您调用glTexParameteri手册页)时,它仅适用于当前纹理。绑定纹理,您必须为要更改其参数的每个纹理单独调用它。未能设置缩小/放大过滤器会使它看起来像纹理加载失败。

您可能还希望glGetError在尝试加载纹理后调用,以查看它是否失败。

于 2012-07-24T16:05:42.937 回答