1
我試圖通過2個紋理着色器,我有點困惑在這裏工作 這是OpenGL的代碼改變片段着色器顯示的紋理
GLuint textures;
GLuint textures1;</code>
glGenTextures(1,&textures);
glGenTextures(1,&textures1);
glBindTexture(GL_TEXTURE_2D,textures);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,256,256,0,GL_RGB,GL_UNSIGNED_BYTE,texImg);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D,textures1);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,256,256,0,GL_RGB,GL_UNSIGNED_BYTE,texImg1);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D,textures1);
GLuint location1=glGetUniformLocation(programObjectFloor,"Tex1");
GLuint location2=glGetUniformLocation(programObjectFloor,"Tex2");
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D,textures1);
glUniform1i(location2, 1);
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,textures);
glUniform1i(location1, 0);
頂點着色引擎是
attribute vec4 position;
attribute vec4 texture;
uniform mat4 MVP;
varying vec4 ptexture;
void main()
{
ptexture = texture;
gl_Position = MVP * position;
}
片斷着色是
varying vec4 ptexture;
uniform sampler2D Tex1;
uniform sampler2D Tex2;
uniform bool swit;
void main()
{
gl_FragColor = texture2D(Tex1,ptexture.st);
}
當我改變線
gl_FragColor = texture2D(Tex2,ptexture.st);
不過只有第一個紋理顯示,但是當我註釋掉以下行,第二個紋理顯示,你可以請解釋爲什麼發生這種情況?
// glActiveTexture(GL_TEXTURE0);
// glEnable(GL_TEXTURE_2D);
// glBindTexture(GL_TEXTURE_2D,textures);
// glUniform1i(location1, 0);
你打電話給glUseProgram的地方在哪裏? –
你的#版本指令在哪裏? – genpfault