1

我开始在 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 函数有关吗?

4

1 回答 1

1

在固定管道(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 );
于 2013-02-27T14:25:10.793 回答