Question: A typical WEBGL function is written as: gl.uniform3f(x,y,z) Explain the significance of each part of the function. A) var gl; var points; var NumPoints =

A typical WEBGL function is written as: gl.uniform3f(x,y,z) Explain the significance of each part of the function. A)

var gl; var points; var NumPoints = 5000; window.onload = function init() { var canvas = document.getElementById( "gl-canvas" ); gl = WebGLUtils.setupWebGL( canvas ); if ( !gl ) { alert( "WebGL isn't available" ); } // // Initialize our data for the Sierpinski Gasket // // First, initialize the corners of our gasket with three points. var vertices = [ vec2( -1, -1 ), vec2( 0, 1 ), vec2( 1, -1 ) ]; // Specify a starting point p for our iterations // p must lie inside any set of three vertices var u = add( vertices[0], vertices[1] ); var v = add( vertices[0], vertices[2] ); var p = scale( 0.25, add( u, v ) ); // And, add our initial point into our array of points points = [ p ]; // Compute new points // Each new point is located midway between // last point and a randomly chosen vertex for ( var i = 0; points.length < NumPoints; ++i ) { var j = Math.floor(Math.random() * 3); p = add( points[i], vertices[j] ); p = scale( 0.5, p ); points.push( p ); } // // Configure WebGL // gl.viewport( 0, 0, canvas.width, canvas.height ); gl.clearColor( 1.0, 1.0, 1.0, 1.0 ); // Load shaders and initialize attribute buffers var program = initShaders( gl, "vertex-shader", "fragment-shader" ); gl.useProgram( program ); // Load the data into the GPU var bufferId = gl.createBuffer(); gl.bindBuffer( gl.ARRAY_BUFFER, bufferId ); gl.bufferData( gl.ARRAY_BUFFER, flatten(points), gl.STATIC_DRAW ); // Associate out shader variables with our data buffer var vPosition = gl.getAttribLocation( program, "vPosition" ); gl.vertexAttribPointer( vPosition, 2, gl.FLOAT, false, 0, 0 ); gl.enableVertexAttribArray( vPosition ); render(); }; function render() { gl.clear( gl.COLOR_BUFFER_BIT ); gl.drawArrays( gl.POINTS, 0, points.length ); }

b) How are the vertices represented in the graphic program? c) Localize these codes so you can make changes to it d) Set NumPoints to 100. Explain what happens to the graph. d) Multiply the vector coordinates by 2. what do you observe? e) Include your name on the graph and screen shot or print

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!