【发布时间】:2012-06-24 14:18:18
【问题描述】:
我想将 GLSL 着色器中的 2 个纹理合并为 1 个。
问题是我未能从我的程序中在着色器中设置 sampler2D。 (着色器/程序编译正确,纹理加载正确,顶点着色器也正确)我用教程中的以下代码进行了尝试:
glUniform1i(program.getUniformLocation("Texture0"), 0);
glUniform1i(program.getUniformLocation("Texture1"), 1);
//texture 0, first texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, colorTexture.handle);
//texture 1, other texture
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, normalTexture.handle);
片段着色器代码如下所示
uniform sampler2D Texture0;
uniform sampler2D Texture1;
void main(void)
{
vec4 color = texture2D(Texture0, vec2(gl_TexCoord[0]));
vec4 normal = texture2D(Texture1, vec2(gl_TexCoord[0]));
gl_FragColor = normal + color;
}
它被绘制
glUseProgram(program.handle);
glColor3f(1, 1, 1);
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex3f(0, 0, 0);
glTexCoord2f(1, 0);
glVertex3f(500, 0, 0);
glTexCoord2f(1, 1);
glVertex3f(500, 500, 0);
glTexCoord2f(0, 1);
glVertex3f(0, 500, 0);
glEnd();
【问题讨论】:
-
你的顶点着色器是什么样的?更重要的是:该程序实际所做的与您预期的有何不同?
-
你在那里的东西对我来说看起来是正确的。你试过 glGetError 吗?