您好我花了很多时间试图在WebGL中进行简单的选择。我在绘制每个对象之前使用过:
if(Window.stencilEnabled)
gl.stencilFunc(gl.ALWAYS, mesh.pickingID, -1);
最后:
mouse_x = this.lastPickingCoords.x;
mouse_y = this.lastPickingCoords.y;
var pixels = new Uint8Array(4);
if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE) {
gl.readPixels(mouse_x, mouse_y, 1, 1, gl.STENCIL_INDEX, gl.UNSIGNED_BYTE, pixels);
}else{
console.log("Framebuffer error.");
}
oID = -1 + pixels[0];
console.log("Picking object: " + oID + " at " + mouse_x + ":" + mouse_y);
if(this.mapArray[oID] != undefined){
console.log("Object exists!");
console.log(this.mapArray[oID]);
}else{
console.log("Object not found");
}
this.lastPickingCoords.x = 0;
this.lastPickingCoords.y = 0;
但似乎是错误" WebGL:INVALID_ENUM:readPixels:格式无效"不允许读取模板缓冲区...是否有任何解决方法,扩展名?如何在不编写选择着色器的情况下以其他方式执行操作谢谢。