这是我的加载代码:
GLuint Utils::loadTextureRAW(const char *filename, int width, int height) {
GLuint texture;
char *data;
fstream file(filename, ios::binary | ios::in);
if (!file.good())
return 0;
// allocate buffer
data = static_cast<char*>(malloc(width * height * 4));
// read texture data
file.read(data, width * height * 4);
file.close();
int i;
for (i = 0; i < width * height * 4; ++i) {
cout << static_cast<int>(data[i]) << "|";
}
// allocate a texture name
glGenTextures(1, &texture);
// select our current texture
glBindTexture(GL_TEXTURE_2D, texture);
// select modulate to mix texture with color for shading
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_DECAL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_DECAL);
// when texture area is small, bilinear filter the closest mipmap
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
// when texture area is large, bilinear filter the first mipmap
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// texture should tile
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// build our texture mipmaps
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
// free buffer
delete data;
return texture; }
这是我的使用代码:
int Object::redraw() {
const float sizex = 0.5f;
const float sizey = 0.5f;
const float sizez = 0.5f;
glTranslatef(-px, -py, -pz);
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
glPushMatrix();
//поворачиваем будущий объект объект
//rotating next object
glRotatef(rx, 1.0, 0.0, 0.0);
glRotatef(ry, 0.0, 1.0, 0.0);
glRotatef(rz, 0.0, 0.0, 1.0);
//рисуем
//drawing
glBegin(GL_QUADS);
// FRONT
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-sizex, -sizey, sizez);
glTexCoord2f(sizex , 0.0f);
glVertex3f(sizex, -sizey, sizez);
glTexCoord2f(sizex, sizey);
glVertex3f(sizex, sizey, sizez);
glTexCoord2f(0.0f, sizey);
glVertex3f(-sizex, sizey, sizez);
// BACK
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-sizex, -sizey, -sizez);
glTexCoord2f(sizex, 0.0f);
glVertex3f(-sizex, sizey, -sizez);
glTexCoord2f(sizex, sizey);
glVertex3f(sizex, sizey, -sizez);
glTexCoord2f(0.0f, sizey);
glVertex3f(sizex, -sizey, -sizez);
// LEFT
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-sizex, -sizey, sizez);
glTexCoord2f(sizex, 0.0f);
glVertex3f(-sizex, sizey, sizez);
glTexCoord2f(sizex, sizey);
glVertex3f(-sizex, sizey, -sizez);
glTexCoord2f(0.0f, sizey);
glVertex3f(-sizex, -sizey, -sizez);
// RIGHT
glTexCoord2f(0.0f, 0.0f);
glVertex3f(sizex, -sizey, -sizez);
glTexCoord2f(sizex, 0.0f);
glVertex3f(sizex, sizey, -sizez);
glTexCoord2f(sizex, sizey);
glVertex3f(sizex, sizey, sizez);
glTexCoord2f(0.0f, sizey);
glVertex3f(sizex, -sizey, sizez);
// TOP
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-sizex, sizey, sizez);
glTexCoord2f(sizex, 0.0f);
glVertex3f(sizex, sizey, sizez);
glTexCoord2f(sizex, sizey);
glVertex3f(sizex, sizey, -sizez);
glTexCoord2f(0.0f, sizey);
glVertex3f(-sizex, sizey, -sizez);
// BOTTOM
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-sizex, -sizey, sizez);
glTexCoord2f(sizex, 0.0f);
glVertex3f(-sizex, -sizey, -sizez);
glTexCoord2f(sizex, sizey);
glVertex3f(sizex, -sizey, -sizez);
glTexCoord2f(0.0f, sizey);
glVertex3f(sizex, -sizey, sizez);
glEnd();
glPopMatrix();
glDisable(GL_TEXTURE_2D); }
这是纹理:
000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000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FFFFFFFFFFFFFFFFFFF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000000FF000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FFFFFFFFFFFFFFFFFFF
EDITED: 检测到另一个问题 - 对于(i = 0; i&lt; width * height * 4; ++ i)输出:
1|0|0|0|0|0|0|0|5|0|0|0|0|0|0|0|-128|63|59|20|1|0|0|0|64|9|-108|2|1|0|0|0|1|0|0|0|1|0|0|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|-64|27|-78|0|2|0|0|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|-128|63|0|0|-128|63|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|-98|70|41|-127|-1|127|0|0|99|-51|56|0|2|0|0|0|0|0|0|0|2|0|0|0|0|-16|117|0|1|0|0|0|0|0|0|0|0|0|0|0|-104|123|115|0|1|0|0|0|0|-16|117|0|1|0|0|0|0|0|0|0|0|0|0|0|64|0|-97|65|0|0|0|0|64|7|-86|34|0|0|0|0|-80|-15|-65|95|-1|127|0|0|-128|117|9|0|2|0|0|0|0|0|0|0|0|0|0|0|-80|52|-108|2|1|0|0|0|0|0|0|0|0|0|0|0|-128|-14|-65|95|-1|127|0|0|-32|-15|-65|95|-1|127|0|0|0|0|0|0|0|0|0|0|32|0|0|0|0|0|0|0|32|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|64|7|0|0|0|0|0|0|-96|110|118|0|1|0|0|0|64|7|0|0|0|0|0|0|-96|110|118|0|1|0|0|0|32|0|0|0|0|0|0|0|80|-13|-65|95|-1|127|0|0|-128|47|8|0|2|0|0|0|-32|-15|-65|95|-1|127|0|0|32|0|0|0|0|0|0|0|-128|-14|-65|95|-1|127|0|0|32|-12|-65|95|-1|127|0|0|64|7|-86|34|0|0|0|0|0|0|0|0|0|0|0|0|-16|28|-108|2|1|0|0|0|2|2|-17|-66|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|3|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|96|0|-97|65|0|0|0|0|0|0|0|0|42|0|0|0|-80|52|-108|2|1|0|0|0|-80|-10|-65|95|0|1|0|0|64|0|0|0|1|0|0|0|-64|45|-63|95|-1|127|0|0|-48|-13|-65|95|-1|127|0|0|3|0|0|0|-1|127|0|0|112|-12|-65|95|-1|127|0|0|73|86|-55|2|1|0|0|0|0|116|17|0|1|0|0|0|105|86|-55|2|1|0|0|0|-72|91|-55|2|1|0|0|0|48|-12|-65|95|-1|127|0|0|6|0|0|0|0|0|0|0|73|86|-55|2|1|0|0|0|-96|-12|-65|95|-1|127|0|0|16|0|0|0|-1|127|0|0|73|86|-55|2|1|0|0|0|5|0|0|0|0|0|0|0|-96|-10|-65|95|-1|127|0|0|64|-13|119|0|1|0|0|0|0|-120|-127|1|1|0|0|0|19|-74|36|92|32|-66|35|74|-96|110|118|0|1|0|0|0|45|0|0|0|0|0|0|0|-112|-11|-65|95|-1|127|0|0|112|-9|-65|95|-1|127|0|0|-64|-43|29|112|-1|127|0|0|-80|-10|-65|95|-1|127|0|0|-128|-11|-65|95|-1|127|0|0|-41|10|45|-127|-1|127|0|0|-78|-10|-65|95|-1|127|0|0|-112|-15|119|0|42|0|0|0|8|2|-1|-1|1|0|0|0|-80|-10|-65|95|-1|127|0|0|44|0|0|0|1|0|0|0|-128|-15|119|0|1|0|0|0|-16|-11|-65|95|-1|127|0|0|0|48|111|0|1|0|0|0|0|-16|117|0|1|0|0|0|0|-16|117|0|1|0|0|0|-16|-11|-65|95|-1|127|0|0|96|120|-108|2|1|0|0|0|16|-12|-65|95|-1|127|0|0|48|-12|-65|95|-1|127|0|0|0|0|0|0|0|0|0|0|16|-128|-108|2|1|0|0|0|0|48|111|0|1|0|0|0|16|-114|114|0|1|0|0|0|64|-10|-65|95|-1|127|0|0|-19|111|8|0|2|0|0|0|0|0|0|0|0|0|0|0|4|0|0|0|0|0|1|0|0|0|0|0|0|0|0|0|-89|-85|-86|50|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|
但如果我正确理解,其中一半必须为零,一半必须为255. WTF或我做错了什么?
EDITED: 试图这样做:
data[0] = 0;
data[1] = 0;
data[2] = 0;
data[3] = 255;
data[4] = 0;
data[5] = 0;
data[6] = 0;
data[7] = 255;
data[8] = 0;
data[9] = 0;
data[10] = 0;
data[11] = 255;
data[12] = 0;
data[13] = 0;
data[14] = 0;
data[15] = 255;
纹理全黑(http://cl.ly/7KJd),零改为255,纹理为白色。所以问题在于文件加载!
答案 0 :(得分:4)
在OpenGL中,当纹理不完整或出错时,会出现白色纹理。
大多数情况下,它与丢失的mipmap有关,但在使用gluBuild2DMipmaps
时,它可能与您没有直接关联。
您应该尝试致电glGetError
以尝试缩小问题范围:正如评论中提到的那样,您在发布的代码中进行了大量不正当的GL调用。