Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 着色器纹理值与创建纹理时写入的值不同_C++_Opengl_Textures_Shader - Fatal编程技术网

C++ 着色器纹理值与创建纹理时写入的值不同

C++ 着色器纹理值与创建纹理时写入的值不同,c++,opengl,textures,shader,C++,Opengl,Textures,Shader,我创建了一个纹理,并用纹理填充: size_t size = width * height * 4; float *pixels = new float[size]; for (size_t i = 0; i < size; ++i) { pixels[i] = 1.0f; } glTextureStorage2D(texture_id, 1, GL_RGBA16F, width, height); glTextureSubImage2D(t

我创建了一个纹理,并用纹理填充:

size_t size = width * height * 4;
float *pixels = new float[size];
for (size_t i = 0; i < size; ++i) {
    pixels[i] = 1.0f;
}

glTextureStorage2D(texture_id, 1, GL_RGBA16F, width,
                   height);
glTextureSubImage2D(texture_id, 0, 0, 0, width, height, GL_RGBA,
                    GL_FLOAT, pixels);
最后一行的alpha值似乎小于1。如果在着色器中,我将alpha设置为1:

color.a = 1.0f;

它画得很正确。这可能是什么原因?

问题来自于
GL\u线性
GL\u夹紧到\u边框的组合:

  • “钳制到边框”表示[0,1]之外的每个纹理坐标 将返回边框颜色。此颜色可设置为
    glTexParameterf(…,GL_纹理_边框_颜色,…)
    并且是黑色的 默认

  • 线性滤波器将考虑与图像相邻的像素 采样位置(除非采样恰好发生在texel中心1), 因此也将读取边框颜色纹理(此处为黑色)

如果您不希望出现这种行为,最简单的解决方案是使用
GL\u CLAMP\u to\u EDGE
,它将无限重复最后一行/列的texel。不同的包装模式在中有很好的解释

1) 采样很可能不在像素中心进行

color.a = 1.0f;