簡體   English   中英

OpenGL:使用紋理時綁定至少一個紋理?

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

我開始在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 );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM