[英]How to draw a line in p5.js using WEBGL
Does drawing lines in 3D work in p5.js? 3D 画线在 p5.js 中有效吗?
The tutorial here: https://github.com/processing/p5.js/wiki/Getting-started-with-WebGL-in-p5 says that it should, but my attempt just gives a blank page.这里的教程: https ://github.com/processing/p5.js/wiki/Getting-started-with-WebGL-in-p5 说它应该,但我的尝试只是给出一个空白页。
function setup() {
createCanvas(400,400, WEBGL);
}
function draw(){
line(-100,-100,-100, 100,100,100);
}
As Kevin, below, has pointed out, the console gives an error:正如下面的凯文所指出的,控制台给出了一个错误:
TypeError: this._renderer.line is not a function
when I attempt to use line();当我尝试使用 line();
My browser does support WEBGL, if I write draw() as如果我将 draw() 写为,我的浏览器确实支持 WEBGL
function draw(){
box();
}
a box does indeed get drawn.一个盒子确实被画了。
The only way I've currently found to draw a line is to write my own function我目前发现画一条线的唯一方法是编写我自己的函数
function drawLine(x1, y1, z1, x2,y2, z2){
beginShape();
vertex(x1,y1,z1);
vertex(x2,y2,z2);
endShape();
}
which does draw a line in 3D space, but the console generates many errors of the form它确实在 3D 空间中画了一条线,但控制台会产生许多形式的错误
Error: WebGL: vertexAttribPointer: -1 is not a valid
index
.错误:WebGL: vertexAttribPointer: -1 is not a valid
index
。 This value probably comes from a getAttribLocation() call, where this return value -1 means that the passed name didn't correspond to an active attribute in the specified program.此值可能来自 getAttribLocation() 调用,其中此返回值 -1 表示传递的名称与指定程序中的活动属性不对应。
in so doing, so something must be wrong there as well.这样做,所以那里也一定有问题。
Googling your error returns a ton of results, including this GitHub issue . 谷歌搜索您的错误会返回大量结果,包括此GitHub问题 。
So it looks like this is a known issue. 所以看起来这是一个已知的问题。 The
line()
function is supposed to work, but it hasn't been properly implemented yet. line()
函数应该可以工作,但尚未正确实现。
Googling your second error returns this GitHub issue , which mentions that it might be caused by not setting a fill()
color before drawing. 谷歌搜索你的第二个错误返回此GitHub问题 ,它提到它可能是由于在绘制之前没有设置
fill()
颜色。
ROFL.罗弗莱。
If you sit by the river long enough, you will see the body of your enemy float by.
如果你在河边坐得够久,你会看到敌人的尸体飘过。
https://codepen.io/micrub/pen/rNGXJPJ?editors=0011
push();
fill(255);
stroke(255);
line(0, 0, 0, C_ZISE / F, 0, 0);
pop();
push();
fill(255);
stroke(255);
line(0, 0, 0, 0, C_ZISE / F, 0);
pop();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.