我创建如下纹理:
GLuint tex;
unsigned char data[12] = {255, 255, 255,
255, 255, 255,
255, 255, 255,
255, 255, 255};
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
我知道它的位置:
GLuint texloc = glGetUniformLocation(program, "tex_map");
然后在我的绘图循环中,我有:
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glUniform1i(texloc, 0);
然后在片段着色器中,我有:
out vec3 color;
uniform sampler2D tex_map;
void main()
{
.
.
color = texture(tex_map, vec2(-0.1, -0.5));
}
有时,当我运行程序时,我正在绘制的对象会变成随机的非白色,通常是红色。我以为我已经用
GL_CLAMP_TO_EDGE
. 是什么导致了这种行为?
编辑:当两个值都在
vec2(_, _)
在0-1范围内。。。