我使用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 ++
答案 0 :(得分:5)
当您致电glTexParameteri
(man page)时,它仅适用于当前纹理。您必须为要更改其参数的每个纹理单独调用它,在之后绑定纹理。未能设置缩小/放大过滤器可能使其看起来像纹理加载失败。
您可能还希望在尝试加载纹理后调用glGetError
,看看它是否失败。