我想用 webgl 画出完美的线条。我没有在渲染器上下文中设置任何东西。我应该启用或设置什么或提供什么选项canvas.getContext
来帮助我画一条看起来不错的线?我认为使用线性和其他东西(我不知道)给我一条不像楼梯的线。
canvas = document.getElementById('canvas');
canvas.height = window.innerHeight;
canvas.width = window.innerWidth;
gl = canvas.getContext('webgl2',{
antialias: true,
depth: false,
stencil: false
});
gl.viewport(0,0,canvas.width,canvas.height);
array = {
pos: {
numComponents: 2,
data: [-0.03, -1 , 0.03, 1],
},
};
Program = twgl.createProgramInfo(gl, [
`#version 300 es
precision highp float;
in vec2 pos;
void main(){gl_Position = vec4(pos, 0.0 , 1.0);}`,
`#version 300 es
precision highp float;
out vec4 Color;
void main(){Color.xyz = vec3(0.0) ; Color.a = 1.0;}
`
]);
Attrib = twgl.createBufferInfoFromArrays(gl, array);
obj = {
type: gl.LINES,
programInfo: Program,
bufferInfo: Attrib,
//count: 1
};
requestAnimationFrame(() => twgl.drawObjectList(gl, [obj]));
<canvas id="canvas"></canvas>
<script src="https://twgljs.org/dist/3.x/twgl.min.js"></script>
提前致谢。