OpenGL ES 2.0 Multiple shader programs - texture rendering not working anymore

别来无恙 提交于 2019-12-05 21:19:18

Where do you set up the texture uniform for your shaders? You need to assign the number of the appropriate texture unit to use for the texture uniform, using code like the following:

glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, sphereDepthMappingTexture);
glUniform1i(sphereDepthPrecalculatedDepthTextureUniform, 2);

The second argument in glUniform1i() here is the number of the texture unit to pull the texture from.

By default, this uniform would be 0, corresponding to GL_TEXTURE0, which is why it might have worked in the first place, but if you switched the active texture unit to something else you no longer would be able to read the texture in your shader.

This, strangely, turned out to be somehow related to the name of the project directory. My Xcode project directory was named as such: "ProjectName (current)". This is the project I was having trouble with. Changing this folder name to anything different made the app work, and properly render the background texture. Very strange.

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