gpt4 book ai didi

c++ - 损坏的纹理编号 OpenGL,在 glGenTextures/glBindTexture 之后

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:22:22 29 4
gpt4 key购买 nike

我的一个纹理在 OpenGL 上有一个糟糕的行为。

删除纹理后,我创建一个新纹理,它生成与之前相同的 tex 编号,但纹理不正确。另外 glGetError 在每一行总是返回 0!我试图在 glDeleteTextures 之后添加 glFlush/glFinish,但它没有任何改变!纹理编号似乎锁定在某处......为什么?

它是单线程的,这里是行为:

//myTexture == 24 is loaded and works correctly
GLboolean bIsTexture = glIsTexture(myTexture); //returns 1 = > ok
glDeleteTextures(1,&myTexture);
bIsTexture = glIsTexture(myTexture); //returns 0 => ok

//Let's create a new texture
glGenTextures(1,&myTexture);//myTexture == 24 (as the glDelete was ok)
glBindTexture(GL_TEXTURE_2D,myTexture);
bIsTexture = glIsTexture(myTexture); //returns 0 => FAILS

最佳答案

在创建已经绑定(bind)的纹理之前调用 BindTexture 为 0 :

//Let's create a new texture
glBindTexture(GL_TEXTURE_2D,0); // free the old bind texture if deleted
glGenTextures(1,&myTexture);//myTexture == 24 (as the glDelete was ok)
glBindTexture(GL_TEXTURE_2D,myTexture);
bIsTexture = glIsTexture(myTexture); //returns 1 => Ok

关于c++ - 损坏的纹理编号 OpenGL,在 glGenTextures/glBindTexture 之后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18641988/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com