多维数据集地图上的OpenGL奇怪的红绿蓝线重复三次

时间:2016-09-27 17:10:31

标签: c++ opengl

请查看以下图片:

enter image description here

我无法弄清楚为什么会发生这种情况,它只是没有意义,我一遍又一遍地检查它并且它一直显示相同的东西,天空盒两侧的三个相同的图像和红色,沿着它们的绿色和蓝色条纹。

我做错了什么?

顶点着色器:

#version 400
uniform samplerCube defuse;
in vec3 tex;

out vec4 out_Color;
void main(void) {
    out_Color = texture(defuse, tex);
}

Fragmant Shader:

GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_CUBE_MAP, texture);

int width, height, numComponents;
unsigned char* imageData = stbi_load((path.getURL() + "posx.png").c_str(), &width, &height, &numComponents, 4);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData);
stbi_image_free(imageData);
imageData = stbi_load((path.getURL() + "posy.png").c_str(), &width, &height, &numComponents, 4);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData);
stbi_image_free(imageData);
imageData = stbi_load((path.getURL() + "posz.png").c_str(), &width, &height, &numComponents, 4);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData);
stbi_image_free(imageData);
imageData = stbi_load((path.getURL() + "negx.png").c_str(), &width, &height, &numComponents, 4);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData);
stbi_image_free(imageData);
imageData = stbi_load((path.getURL() + "negy.png").c_str(), &width, &height, &numComponents, 4);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData);
stbi_image_free(imageData);
imageData = stbi_load((path.getURL() + "negz.png").c_str(), &width, &height, &numComponents, 4);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData);
stbi_image_free(imageData);

glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAX_LEVEL, 0);
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
return new GLTexture(texture);

CubeMap Loader

function onOpen(e) {
DocumentApp.getUi().createMenu('Senate Secretary Menu')
   .addItem('Snapshot', 'snapshot')
  .addToUi();
}

1 个答案:

答案 0 :(得分:0)

指定stbi以使用4个组件加载纹理 - 所需的组件数是stbi_load的最后一个参数。您还指定OpenGL纹理为GL_RGB,而不是。{解决这个问题的方法是将纹理指定为OpenGL为GL_RGBA,或者将纹理解析为3个组件,如果可能的话。