This assignment is worth 10 points.
attribute vec4 vPosition;
void main() {
float d = 0.2;
// translate matrix
// note the matrix appears to be transposed, it is not.
// GLSL is column major, not row major
mat4 translate = mat4(
vec4(1.0, 0.0, 0.0, 0.0), // first column
vec4(0.0, 1.0, 0.0, 0.0), // second column
vec4(0.0, 0.0, 1.0, 0.0), // third column
vec4(0.0, 0.25, 0.75, 1.0) // last column
);
// pinhole camera projection matrix.
mat4 project = mat4(
vec4(1.0, 0.0, 0.0, 0.0),
vec4(0.0, 1.0, 0.0, 0.0),
vec4(0.0, 0.0, 0.0, 1.0/d),
vec4(0.0, 0.0, 0.0, 0.0)
);
// apply the transformations
gl_Position = project * translate * vPosition;
}
void main(){
gl_FragColor = vec4 (1.0, 0.0, 1.0, 1.0) ;
}
class Canvas {
constructor (width, height, Keypress, vertShader, fragShader) {
this.height = height;
this.width = width;
this.MakeCanvas();
this.canvas.addEventListener("keypress", Keypress);
this.SetupGL();
this.MakeShaders(vertShader, fragShader);
this.Init();
}
MakeCanvas() {
if (this.width == undefined || this.width < 0) {
this.width = 300;
}
if (this.height == undefined || this.height < 0) {
this.height = 300;
}
this.canvas = document.createElement('canvas')
this.canvas.tabIndex=0;
this.canvas.height = this.height;
this.canvas.width = this.width;
this.canvas.style="border:1px solid #000000;"
document.body.appendChild(this.canvas);
}
SetupGL() {
this.gl = WebGLUtils.setupWebGL(this.canvas);
if (!this.gl) {
alert ("WebGL isn't available");
return;
}
this.gl.getExtension('OES_standard_derivatives');
}
MakeShaders(vertShader, fragShader) {
this.program = initShaders(this.gl, vertshader,fragshader);
this.gl.useProgram(this.program);
}
Init() {
this.gl.clearColor(1.0, 1.0, 1.0, 1.0);
this.gl.viewport(0,0, this.width, this.height);
}
Program() {
return this.program;
}
GL() {
return this.gl;
}
Clear() {
this.gl.clear(this.gl.COLOR_BUFFER_BIT);
}
} // closing of class
class Widget {
constructor(gl, program, posName, edges) {
this.visible = true;
this.size = edges.length;
this.SetupVBO(gl, program, posName, edges);
}
SetupVBO(gl, program, posName, edges) {
this.vbuf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, this.vbuf);
this.pos = gl.getAttribLocation(program, posName);
gl.vertexAttribPointer(this.pos, 3, gl.FLOAT, false, 0, 0);
gl.enableVertexAttribArray(this.pos);
gl.bufferData(gl.ARRAY_BUFFER,flatten(edges),gl.STATIC_DRAW);
}
Show() {
this.visible = true;
}
Hide() {
this.visible = false;
}
Visible() {
return this.visible;
}
Display(gl) {
if (this.visible) {
gl.bindBuffer(gl.ARRAY_BUFFER, this.vbuf);
gl.vertexAttribPointer(this.pos, 3, gl.FLOAT, false, 0, 0);
gl.drawArrays(gl.LINE_LOOP, 0, this.size);
}
}
} // closing of class.
Create a tar/zip file containing your HW5 directory.
Submit your tar/zip file as an attachment to a message to dbennett@edinboro.edu. Please include your name, and the homework number in the title of the message. Please only submit files in the HW5 directory, not the Common directory.