WebGL Textures & Vertices

Beginner's Guide

Page Fifty Six

WebGL API enableVertexAttribArray(Number)

The WebGL API method enableVertexAttribArray(Number) activates an attribute within the vertex shader. Reference the attribute by it's index location within the shader.

The following listing demonstrates activating attribute a_position, by index location. The property aPosition within the GLControl class maintains the location of the attribute a_position. The section titled Prepare Buffers assigns vertex data to the shader attribute a_position, through the property aPosition.


Listing 52: WebGL API enableVertexAttribArray(Number)

WebGL API viewport(Number x,Number y,Number w,Number h)

Finally method getProgramVariables() assigns the WebGL viewport width and height. The viewport represents the renderable area for WebGL content. The WebGL API method viewport(Number x,Number y,Number w,Number h) includes four parameters representing the X and Y coordinate of the upper left corner, along with the width and height. The book's examples draw to an HTML5 canvas with width and height of 512 pixels. The following listing demonstrates assigning WebGL viewport dimensions.


Listing 53: WebGL API viewport(Number x,Number y,Number w,Number h)

Access Shader Program Variables Summary

Method getProgramVariables() accesses attribute a_position and uniform um4_matrix. Method getProgramVariables() assigns viewport settings and a perspective projection matrix. We discussed WebGL API methods getUniformLocation(WebGLProgram, String), uniformMatrix4fv(uniform, false, Float32Array), getAttribLocation(WebGLProgram, String), enableVertexAttribArray(Number), and viewport(Number x, Number y, Number w, Number h). See the section titled Perspective Projection for an overview of perspective with WebGL. See method getProgramVariables() for details.

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