Skip to content

Commit 69edb7a

Browse files
author
Nicholas Oxford
committed
fix webcam
1 parent dc6ccfe commit 69edb7a

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

src/data/examples/zh-Hans/20_3D/11_shader_using_webcam.js

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,35 @@
44
* <br> To learn more about using shaders in p5.js: <a href="https://itp-xstory.github.io/p5js-shaders/">p5.js Shaders</a>
55
*/
66

7-
// this variable will hold our shader object
8-
let theShader;
9-
// this variable will hold our webcam video
10-
let cam;
11-
12-
function preload(){
13-
// load the shader
14-
theShader = loadShader('assets/webcam.vert', 'assets/webcam.frag');
15-
}
16-
17-
function setup() {
18-
// shaders require WEBGL mode to work
19-
createCanvas(710, 400, WEBGL);
20-
noStroke();
21-
22-
cam = createCapture(VIDEO);
23-
cam.size(710, 400);
24-
25-
cam.hide();
26-
}
27-
28-
function draw() {
29-
// shader() sets the active shader with our shader
30-
shader(theShader);
31-
32-
// passing cam as a texture
33-
theShader.setUniform('tex0', cam);
34-
35-
// rect gives us some geometry on the screen
36-
rect(0,0,width,height);
37-
}
7+
// this variable will hold our shader object
8+
let theShader;
9+
// this variable will hold our webcam video
10+
let cam;
11+
12+
function preload() {
13+
// load the shader
14+
theShader = loadShader('assets/webcam.vert', 'assets/webcam.frag');
15+
}
16+
17+
function sizeVideo() {
18+
cam.size(710, 400);
19+
cam.hide();
20+
}
21+
function setup() {
22+
// shaders require WEBGL mode to work
23+
createCanvas(710, 400, WEBGL);
24+
noStroke();
25+
26+
cam = createCapture(VIDEO, sizeVideo);
27+
}
28+
29+
function draw() {
30+
// shader() sets the active shader with our shader
31+
shader(theShader);
32+
33+
// passing cam as a texture
34+
theShader.setUniform('tex0', cam);
35+
36+
// rect gives us some geometry on the screen
37+
rect(0, 0, width, height);
38+
}

0 commit comments

Comments
 (0)