可以将多个纹理传给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);
时间: 2024-10-11 19:59:49