可以将多个纹理传给shader,下图是两个纹理叠加的效果
shader中定义如下:
uniform sampler2D U_MainTexture; uniform sampler2D U_SubTexture; varying vec2 M_coord; void main() { gl_FragColor = texture2D(U_SubTexture, M_coord) * 0.8 + texture2D(U_MainTexture, M_coord) * 0.2; }
CUP中参数传递
// 传递0号纹理单元 OpenGLCore->glActiveTexture(GL_TEXTURE0); OpenGLCore->glBindTexture(GL_TEXTURE_2D, m_Texture); OpenGLCore->glUniform1i(m_TextureLocation, 0); // 传递1号纹理单元 OpenGLCore->glActiveTexture(GL_TEXTURE1); OpenGLCore->glBindTexture(GL_TEXTURE_2D, m_Texture2); OpenGLCore->glUniform1i(m_Texture2Location, 1);
本文出自 “不会飞的纸飞机” 博客,请务必保留此出处http://douzhq.blog.51cto.com/12552184/1931033
原文地址:http://douzhq.blog.51cto.com/12552184/1931033