Game Development Reference
In-Depth Information
gl.bindTexture(gl.TEXTURE_CUBE_MAP, cubeTex);
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER,
gl.NEAREST);
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER,
gl.LINEAR);
loadFace(gl.TEXTURE_CUBE_MAP_POSITIVE_X,
'cubemap/positive_x.jpg');
loadFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_X,
'cubemap/negative_x.jpg');
loadFace(gl.TEXTURE_CUBE_MAP_POSITIVE_Y,
'cubemap/positive_y.jpg');
loadFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y,
'cubemap/negative_y.jpg');
loadFace(gl.TEXTURE_CUBE_MAP_POSITIVE_Z,
'cubemap/positive_z.jpg');
loadFace(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z,
'cubemap/negative_z.jpg');
}
In the drawScene function, we initialize our two textures as follows:
function drawScene() {
...
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.uniform1i(gl.getUniformLocation(shaderProgram, "uSampler"),
0);
gl.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_CUBE_MAP, cubeTex);
gl.uniform1i(gl.getUniformLocation(shaderProgram,
"uCubeSampler"), 1);
...
}
In the preceding code, we activate our first texture, and then we associate our current
2D texture by using the parameter 0 in the gl.uniform1i(..., 0) call. Similarly,
we activate our second texture gl.activeTexture(gl.TEXTURE1) and then
associate our cubemap texture as 1 in the gl.uniform1i(..., 1) call.
 
Search WWH ::




Custom Search