CG Class 5, Mon 2019-09-09
Table of contents
1 How to print info from inside your javascript program
-
There are several ways; here is the easiest.
-
Reference: http://www.w3schools.com/js/js_output.asp
-
Examples to do inside square.js:
- window.alert('this is an alert');
- window.alert('vertices length: ' + vertices.length + ' 1: ' + vertices[1]);
-
Note that you can write variable values as well as strings.
-
Another way is to write to the console log thus:
console.log('this is a log message');
-
In firefox, you can display the log window with F12.
-
An advantage of the log is that you see all the messages together.
-
I'll demo these methods.
2 Today's demo program
For today's demo program, I'll modify triangle to add a slider that controls the amount of green to add to the triangle color.
- The amount of green will be read from a slider.
- Scrounge your slider code from gasket5.
- The value will be transmitted to the fragment shader in a uniform variable.
- Scrounge around in Angel's examples to see how to use a uniform variable. (I grepped for 'uniform').
3 Textbook slides
We'll finish the Chapter 2 slides.
4 Iclicker questions
- What is your major?
- CSYS
- ELEC
- CSCI
- GSAS
- Other
- What is your class?
- 2020
- 2021
- 2022
- Grad
- Other
- What is the correct order of the graphics pipeline?
- vertex-shader fragment-shader rasterizer primitive-assembly
- fragment-shader rasterizer primitive-assembly vertex-shader
- rasterizer primitive-assembly vertex-shader fragment-shader
- primitive-assembly vertex-shader fragment-shader rasterizer
- vertex-shader primitive-assembly rasterizer fragment-shader
- If you wanted to change all the vertex positions by multiplying each x-coordinate by the same vertex's y-coordinate, the best place to do it is:
- with a javascript function
- in the vertex shader
- in the fragment shader
- in the html file
- it can't be done.