Game Development Reference
In-Depth Information
gl.enableVertexAttribArray(shaderProgram.textureCoordAttribute);
shaderProgram.hasTexture = gl.getUniformLocation(shaderProgram,
"hasTexture");
...
}
Finally, we modified our drawScene function to initialize the variables ( hasTexture ,
uSampler and textureCoordAttribute ) to be passed to the shaders, as shown in
the following code:
function drawScene() {
...
for(var i=0;i<stage.stageObjects.length;++i){
...
if(stage.stageObjects[i].materialFile!=null){
gl.uniform1i(shaderProgram.hasTexture,1);
try{
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, stage.textures[stage.stageObjects[i].
textureIndex].texture);
gl.uniform1i(gl.getUniformLocation(shaderProgram, "uSampler"), 0);
gl.bindBuffer(gl.ARRAY_BUFFER, stage.stageObjects[i].
verticesTextureBuffer);
gl.vertexAttribPointer(shaderProgram.textureCoordAttribute, 2,
gl.FLOAT, false, 0, 0);
}
catch(e){
console.log("Could not initialize texture buffer.");
}
}
else{
gl.uniform1i(shaderProgram.hasTexture,0);
}
...
}
...
}
 
Search WWH ::




Custom Search