我创建了一个立方体,然后更改了它的坐标以使其成为这样的光束(点击我)。
我确信纹理加载正常,因为我已成功加载项目中的其他纹理(使用 SOIL)。
梁的代码是这样的:
glBindTexture(GL_TEXTURE_2D, obstacle_texture);
glBegin(GL_QUAD_STRIP);
// front
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(side, 0.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(side, height, 0.0f);
glTexCoord2f(0.0f, 1.0f ); glVertex3f(0.0f, height, 0.0f);
// back
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, -side);
glTexCoord2f(0.0f, 1.0f); glVertex3f(side, 0.0f, -side);
glTexCoord2f(1.0f, 0.0f); glVertex3f(side, height, -side);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.0f, height, -side);
// right
glTexCoord2f(0.0f, 0.0f); glVertex3f(side, 0.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(side, 0.0f, -side);
glTexCoord2f(1.0f, 0.0f); glVertex3f(side, height, -side);
glTexCoord2f(1.0f, 1.0f); glVertex3f(side, height, 0.0f);
// left
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 0.0f, -side);
glTexCoord2f(1.0f, 0.0f); glVertex3f(0.0f, height, -side);
glTexCoord2f(1.0f, 1.0f); glVertex3f(0.0f, height, 0.0f);
// top
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, height, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(side, height, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(side, height, -side);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, height, -side);
// bottom
glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(side, 0.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(side, 0.0f, -side);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 0.0f, -side);
glEnd();
结果是这样的:
纹理映射应该有问题,或者
我应该让立方体保持原样并将纹理应用到它,然后对其进行缩放(但我认为这会使纹理看起来失真)。
我该怎么办?
更新#1: 在 SOIL 之前,我一直在使用加载器来加载我在网站上找到的 BMP 文件。我现在使用它,它看起来像这样:
请注意,在我指出的地方,立方体似乎有一些三角形整体。我正在使用这样的土壤:
GLuint tex_2d = SOIL_load_OGL_texture
(
imagepath,
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
);
glBindTexture(GL_TEXTURE_2D, tex_2d);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );