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.getElementByIdglcanvas" ;
gl canvas.getContextwebgl;
if gl alert "WebGL isn't available" ;
glviewport canvas.width, canvas.height ;
glclearColor;
sq new SquareD;
render;
;
function render
glclear glCOLORBUFFERBIT ;
sqdraw;
square.js
class SquareD
static vertexPositions
vec
vec
vec
vec;
static shaderProgram ;
static positionBuffer ;
static aPositionShader ;
static initialize
SquareDshaderProgram initShaders glvshaderglslfshaderglsl;
Load the data into the GPU
SquareDpositionBuffer glcreateBuffer;
glbindBuffer glARRAYBUFFER, SquareDpositionBuffer;
glbufferData glARRAYBUFFER, flattenSquareDvertexPositions glSTATICDRAW ;
Associate our shader variables with our data buffer
SquareDaPositionShader glgetAttribLocation SquareDshaderProgram, "aPosition" ;
constructor
ifSquareDshaderProgram
SquareDinitialize
draw
gluseProgramSquareDshaderProgram;
glbindBuffer glARRAYBUFFER, SquareDpositionBuffer;
glvertexAttribPointerSquareDaPositionShader, glFLOAT, false, ;
glenableVertexAttribArraySquareDaPositionShader;
gldrawArrays glTRIANGLEFAN, ;
gldisableVertexAttribArraySquareDaPositionShader;
Modify the code to create an image with WebGL that contains red pentagon any 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.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
