Question: * Computer Graphis app.js var canvas; var gl; var sq; window.onload = function init ( ) { canvas = document.getElementById ( gl - canvas

*Computer Graphis
app.js
var canvas;
var gl;
var sq;
window.onload = function init(){
canvas = document.getElementById("gl-canvas" );
gl = canvas.getContext('webgl2');
if (!gl ){ alert( "WebGL 2.0 isn't available" ); }
gl.viewport(0,0, canvas.width, canvas.height );
gl.clearColor(0.0,0.0,0.0,1.0);
sq = new Square2D();
render();
};
function render(){
gl.clear( gl.COLOR_BUFFER_BIT );
sq.draw();
}
square.js
class Square2D{
static vertexPositions =[
vec2(-0.5,-0.5),
vec2(-0.5,0.5),
vec2(0.5,0.5),
vec2(0.5,-0.5)];
static shaderProgram =-1;
static positionBuffer =-1;
static aPositionShader =-1;
static initialize(){
Square2D.shaderProgram = initShaders( gl,"./vshader.glsl","./fshader.glsl");
// Load the data into the GPU
Square2D.positionBuffer = gl.createBuffer();
gl.bindBuffer( gl.ARRAY_BUFFER, Square2D.positionBuffer);
gl.bufferData( gl.ARRAY_BUFFER, flatten(Square2D.vertexPositions), gl.STATIC_DRAW );
// Associate our shader variables with our data buffer
Square2D.aPositionShader = gl.getAttribLocation( Square2D.shaderProgram, "aPosition" );
}
constructor(){
if(Square2D.shaderProgram ==-1)
Square2D.initialize()
}
draw(){
gl.useProgram(Square2D.shaderProgram);
gl.bindBuffer( gl.ARRAY_BUFFER, Square2D.positionBuffer);
gl.vertexAttribPointer(Square2D.aPositionShader, 2, gl.FLOAT, false, 0,0);
gl.enableVertexAttribArray(Square2D.aPositionShader);
gl.drawArrays( gl.TRIANGLE_FAN, 0,4);
gl.disableVertexAttribArray(Square2D.aPositionShader);
}
}
Modify the code to create an image with WebGL that contains 1 red pentagon (any 5-sided polygon) that fits inside the default view volume.
You should also change the viewport so the pentagon is displayed in the upper left portion of the canvas.
Do NOT change the values of the vertices in the example. You may ONLY change their order and add new vertices.
Create a pentagon.js file from square.js with the appropriate changes and modify some of the remaining files to display your pentagon, instead of the square.
Here's an example of what I am looking for.
 *Computer Graphis app.js var canvas; var gl; var sq; window.onload =

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!