OpenGL:使用纹理时至少绑定一个纹理

OpenGL: bind at least one texture when working with textures?

本文关键字:纹理 一个 绑定 OpenGL      更新时间:2023-10-16

我开始在openGl中使用纹理,我注意到一些奇怪的行为。请看下面的伪代码示例:

int main()...
bindTexture1();
bindTexture2();
bindTexture3();
// None of these textures are actually used!
while(true) {
    begin();
    // draw stuff 
    end();
}

我加载和绑定3个纹理,但现在我只是绘制原语。但是这些原语是不可见的。它们在以下情况下是可见的:

int main()...
bindTexture1();   // <- So the first bind() remains the only one
//bindTexture2();
//bindTexture3();
// None of these textures are actually used!
while(true) {
    begin();
    // draw again just primitve stuff but now it's visible
    end();
}

int main()...
bindTexture1();
bindTexture2();
bindTexture3();
// None of these textures are actually used!
while(true) {
    begin();
    bindTexture1();  // Binding texture 1 again
    // draw again just primitve stuff but now it's visible 
    end();
}

所以我想我的问题是连接到这个glBindTexture功能?

在固定管道(opengl 1和2)中渲染2D纹理的过程是这样的:

glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, textureId );
// render
glBegin( GL_QUADS );
   glTexCoord2f( 0.0, 0.0 );
   glVertex2f( 0.0, 0.0 );
   glTexCoord2f( 1.0, 0.0 );
   glVertex2f( 1.0, 0.0 );
   glTexCoord2f( 1.0, 1.0 );
   glVertex2f( 1.0, 1.0 );
   glTexCoord2f( 0.0, 1.0 );
   glVertex2f( 0.0, 1.0 );
glEnd();
glDisable( GL_TEXTURE_2D );