2017-02-15 63 views
1

在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.

這樣做,所以在那裏也必須有錯。

+0

您的瀏覽器是否支持webgl?你在控制檯中是否有任何錯誤?當我運行這段代碼時,我得到一個錯誤,說'this._renderer.line'不是一個函數。 –

+0

謝謝凱文,是的,我也是。上面添加了更多細節。 – rgh

回答

0

Googling your error會返回一整串結果,包括this GitHub issue

所以看起來這是一個已知的問題。 line()函數應該可以工作,但尚未正確實施。

使用Google搜索您的第二個錯誤返回this GitHub issue,其中提到可能是由於在繪製之前未設置fill()顏色導致的。