CSCI 461: Computer Graphics

Middlebury College, Fall 2023

Lecture 08: Buffers, Varyings, Attributes & Uniforms

By the end of today's lecture, you will be able to:

  • compile shader programs,
  • write data to the GPU using buffers,
  • bind data in a buffer to an attribute in a shader program,
  • declare and assign varyings passed from the vertex processing stage to the fragment processing stage,
  • set and use global variables (uniforms) in your shader program,
  • respond to events such as mouse clicks, motion & key presses,
  • write a complete WebGL application from start to finish.

Last week we introduced rasterization - recall our rendering pipeline.


      
    


Warmup question (event # 9000135): in last week's lab we used
gl.clear(gl.DEPTH_BUFFER_BIT | gl.COLOR_BUFFER_BIT)
See WebGL constants: https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants
Hint: Open a console and retrieve a WebGL context:
const gl = document.createElement("canvas").getContext("webgl");

WebGL is a state machine.

How to develop a WebGL application is best learned by writing code.

https://replit.com/team/csci461f23/Week-08-WebGL
Can we use this instead? (event # 9000135)
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint8Array(mesh.triangles), gl.STATIC_DRAW);