WebGL Textures & Vertices

Beginner's Guide

Page Seventy

WebGL API activeTexture(Number)

Step 3 call the WebGL method activeTexture(Number) to activate a texture unit. Specify texture units with numbers. After activating a texture unit, subsequent texture settings apply to the active texture. In other words, call activeTexture(Number) before assigning image data, filter and wrapping modes. Specify the number as an offset from the WebGL constant TEXTURE0. For example activeTexture(gl.TEXTURE0 + 2) enables texture unit 2.

The GLEntity method setActiveTexture(entity,gl) activates a texture by number. The WebGL constant TEXTURE0 references the location of the first texture. TEXTURE1 references the location of the second texture. However, TEXTURE0 + 1 also references the second texture. We simply use the GLEntity.idx property to activate the correct texture for each GLEntity. The following listing demonstrates activating a texture by number.

gl.activeTexture
(
 gl.TEXTURE0 + entity.idx
);

Listing 70: WebGL API activeTexture(Number)

WebGL Beginner's Guide Introduction WebGL Beginner's Guide
Copyright © 2015 Seven Thunder Software. All Rights Reserved.

Fatal error: Internal zval's can't be arrays, objects or resources in Unknown on line 0