Manual
Examples
Multitexture
The following code sample shows how shaders can access two different textures simultaneously using two sampler2D uniform variables.
The command to run this example would be:
gander multitexture.xml
multitexture.xml
<texture file="crate.jpg" name="crate">
<texture file="stone.jpg" name="stone">
<program>
<shader file="multitexture.vert" />
<shader file="multitexture.frag" />
<translate x="-1.0">
<box>
<uniform type="mat4" name="MVPMatrix" />
<uniform type="sampler2D" name="left" link="crate" />
<uniform type="sampler2D" name="right" link="stone" />
</box>
</translate>
<translate x="+1.0">
<box>
<uniform type="mat4" name="MVPMatrix" />
<uniform type="sampler2D" name="left" link="stone" />
<uniform type="sampler2D" name="right" link="crate" />
</box>
</translate>
</program>
</texture>
</texture>
multitexture.vert
#version 130
uniform mat4 MVPMatrix;
in vec4 MCVertex;
in vec3 TexCoord0;
out vec3 TexCoord;
void main() {
TexCoord = TexCoord0;
gl_Position = MVPMatrix * MCVertex;
}
multitexture.frag
#version 130
uniform sampler2D left, right;
in vec3 TexCoord;
out vec4 FragColor;
void main() {
if (TexCoord.s < 0.5) {
FragColor = texture(left, TexCoord.st);
} else {
FragColor = texture(right, TexCoord.st);
}
}