我正在生成纹理:
glGenTextures(1, &texA);
glBindTexture(GL_TEXTURE_2D, texA);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
GLubyte* data = (GLubyte *) malloc(32*32*4*sizeof(GLubyte));
for (int i = 0; i < 32 * 32 * 4; i+=4) {
data[i] = data[i+1] = data[i+2] = 123;
data[i+3] = 255;
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0, GL_RGBA,GL_UNSIGNED_BYTE, data);
现在我想将它传递给我的着色器:
glBindTexture(GL_TEXTURE_2D,texA);
glUniform1i(inputTextureLocation, 0);
但是当我尝试在片段着色器中使用它时,我只会得到黑色:
out vec4 color
uniform sampler2D inputTex;
void main() {
color = vec4(texture2D(inputTex, vec2(1,1)).xyz, 1);
}
谢谢你的帮助。