在p5.js中绘制线条是否在3D中工作?如何使用WEBGL在p5.js中绘制线条
这里的教程: 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);
}
正如凯文,以下,所指出的那样,控制台提供了一个错误:
TypeError: this._renderer.line is not a function
当我尝试使用线
();
我的浏览器支持WebGL,如果我写得出()作为
function draw(){
box();
}
箱子确实拿得出。
目前我发现画一条线的唯一办法就是写我自己的函数
function drawLine(x1, y1, z1, x2,y2, z2){
beginShape();
vertex(x1,y1,z1);
vertex(x2,y2,z2);
endShape();
}
这确实绘制3D空间中的线,但控制台生成表单的许多错误
Error: 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.
这样做,所以在那里也必须有错。
您的浏览器是否支持webgl?你在控制台中是否有任何错误?当我运行这段代码时,我得到一个错误,说'this._renderer.line'不是一个函数。 –
谢谢凯文,是的,我也是。上面添加了更多细节。 – rgh