我正在尝试将纹理传递并使用着色器......但每次我尝试以最简单的方式使用它时,我都会得到黑匣子,有时是白色 - 取决于我放置他的纹理......不知何故......
这里的代码片段应该可以工作(我已经删除了我的包装以使其更容易):
fbo->bind();
fbo->drawBuffer(0);
fbo->setClearColor( 1.0, 1.0, 1.0, 1.0);
fbo->cleanCurrentTexture();
GLuint location;
location = glGetUniformLocation( Program->getID(), "sampler");
glActiveTexture( GL_TEXTURE0 );
glBindTexture(GL_TEXTURE_2D, fbo2->getTexture(0) );
glUniform1i(location, 0);
Program->begin();
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glVertex3f( -1.0f, -1.0f, 0.0f );
glVertex3f( -1.0f, 1.0f, 0.0f );
glVertex3f( 1.0f, 1.0f, 0.0f );
glVertex3f( 1.0f, -1.0f, 0.0f );
glEnd();
Program->end();
fbo->unbind();
glColor3f(1.0,1.0,1.0);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, fbo->getTexture(0) );
glBegin(GL_QUADS);
glTexCoord2d( 0.0f, 0.0f);
glVertex3f( -1.0f, -1.0f, 0.0f );
glTexCoord2d( 0.0f, 1.0f);
glVertex3f( -1.0f, 1.0f, 0.0f );
glTexCoord2d( 1.0f, 1.0f);
glVertex3f( 1.0f, 1.0f, 0.0f );
glTexCoord2d( 1.0f, 0.0f);
glVertex3f( 1.0f, -1.0f, 0.0f );
glEnd();
glDisable( GL_TEXTURE_2D);
顶点着色器:
#version 120
void main()
{
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
}
片段着色器:
#version 120
uniform sampler2D sampler;
void main()
{
gl_FragColor = texture2D(sampler, gl_TexCoord[0].xy);
}
当然,我试图绑定的纹理存在并且它是完整的。这是它的参数:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);