OpenGL ES 2.0 render to texture

岁酱吖の 提交于 2019-11-28 23:31:32

Make sure the texture is not bound before trying to render into it. Even if not using texturing at all, trying to render into a currently bound texture may invoke undefined behaviour and just not work.

You should actually call glBindTexture(GL_TEXTURE_2D, 0) after the glTexImage2D in your RenderTexture constructor, or maybe restore the previously bound texture, like you do with the FBO. Just make sure the tex is not bound when you render into the FBO.

This has been a while, but as I wrote in the comments, be sure you're initializing a power of 2 texture.

I had exact the same problem as u do. Try to add

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

right after glBindTexture(GL_TEXTURE_2D, tex); and black square have to disappear.

You don't seem to make use of glActiveTexture. I recommend you to call glActiveTexture(GL_TEXTURE0+tex); before each glBindTexture(tex);, which will save you a lot of headaches when you use more than one texture. I guess the error is in the code you use for drawing the texture on the screen.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!