在《OpenGL Shading Language Second Edition》中发现多纹理在GLSL中的正确使用方法,先看c++源码:
view sourceprint?
01.
glActiveTexture(GL_TEXTURE0);
02.
glBindTexture(GL_TEXTURE_2D, earthDayTexName);
03.
04.
glActiveTexture(GL_TEXTURE1);
05.
glBindTexture(GL_TEXTURE_2D, earthNightTexName);
06.
07.
glActiveTexture(GL_TEXTURE2);
08.
glBindTexture(GL_TEXTURE_2D, earthCloudsTexName);
09.
10.
......
11.
12.
lightLoc = glGetUniformLocation(programObj, "LightPosition");
13.
glUniform3f(lightLoc, 0.0, 0.0, 4.0);
14.
texLoc = glGetUniformLocation(programObj, "EarthDay");
15.
glUniform1i(texLoc, 0);
16.
texLoc = glGetUniformLocation(programObj, "EarthNight");
17.
glUniform1i(texLoc, 1);
18.
texLoc = glGetUniformLocation(programObj, "EarthCloudGloss");
19.
glUniform1i(texLoc, 2);
其中"EarthDay"、"EarthNight"和"EarthCloudGloss"是GLSL的shader中的uniform前缀的sampler2D类型。