CS351 Lecture5
CS351 Lecture5
Graphics
(CS351)
Lecturer:
Dr. Ahmed Hosny
CS Department
Faculty of Computer and Information
Assiut University
Lecture 5
TranslatedTriangle
6
CS351 - Dr. Ahmed Hosny 7
Operations
• As these are a per-vertex operation, you need to
implement the operations in a vertex shader.
var FSHADER_SOURCE =`
void main() {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}`;
function main() {
// Retrieve <canvas> element
var canvas = document.getElementById('webgl’);
// Initialize shaders
if (!initShaders(gl, VSHADER_SOURCE, FSHADER_SOURCE)) {
console.log('Failed to intialize shaders.’);
return;
}
// Clear <canvas>
gl.clear(gl.COLOR_BUFFER_BIT);
Can we use uniform3f?
// Draw the rectangle
gl.drawArrays(gl.TRIANGLES, 0, n);
}
var FSHADER_SOURCE =`
void main() {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}`;
function main() {
// Retrieve <canvas> element
var canvas = document.getElementById('webgl’);
Normal Rotated 90
• Because the rotation is around the z-axis, the z coordinate does not
change, and you can ignore it for now.
x’ = r cos (α + β)
y’ = r sin (α + β)
x’ = x cos β – y sin β
y’ = x sin β + y cos β
// Initialize shaders
if (!initShaders(gl, VSHADER_SOURCE, FSHADER_SOURCE)) {
console.log('Failed to intialize shaders.’);
return;
}
// Clear <canvas>
gl.clear(gl.COLOR_BUFFER_BIT);