[英]OpenGL: bind at least one texture when working with textures?
I started using textures in openGl and I noticed some strange behavior. 我开始在openGl中使用纹理,并且发现一些奇怪的行为。 See the following pseudo code example:
请参见以下伪代码示例:
int main()...
bindTexture1();
bindTexture2();
bindTexture3();
// None of these textures are actually used!
while(true) {
begin();
// draw stuff
end();
}
Im loading and binding 3 textures but right now Im just drawing primitives. 我加载并绑定了3个纹理,但现在我只是在绘制图元。 But those primitives are not visible.
但是这些原语是不可见的。 They are visible in the following cases:
在以下情况下它们是可见的:
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();
}
Or 要么
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();
}
So I guess my problem is connected to this glBindTexture function? 所以我想我的问题与这个glBindTexture函数有关吗?
The procedure when rendering a 2D texture in fixed pipeline (opengl 1 and 2) is this : 在固定管线(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 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.