What are WebGL's draw primitives?

回眸只為那壹抹淺笑 提交于 2019-12-04 17:43:25

问题


I've been doing some graphics programming using webgl to draw OBJMesh's, but it hasn't gone too well as it is not drawing it correctly. I think thats because of the drawing primitives that I'm using e.g : gl.drawArrays(gl.TRIANGLE_STRIP, 0, vertexBuffer.numItems);

So can I ask what primitives do webGL allow? is it the same as openGL? I've been trying to use gl.QUADS as I thought it would allow it as openGL does, so I'm not too sure anymore.


回答1:


From https://www.khronos.org/registry/webgl/specs/1.0/:

const GLenum POINTS                         = 0x0000;
const GLenum LINES                          = 0x0001;
const GLenum LINE_LOOP                      = 0x0002;
const GLenum LINE_STRIP                     = 0x0003;
const GLenum TRIANGLES                      = 0x0004;
const GLenum TRIANGLE_STRIP                 = 0x0005;
const GLenum TRIANGLE_FAN                   = 0x0006;



回答2:


Yes, WebGL draws the same primitives as OpenGL ES (same also as OpenGL). Have you tried drawing some trivial meshes so you can narrow down what the problem could be? Are you setting culling, drawing the right primitive, etc.?

I've done a few WebGL demos where I draw complex meshes, and I always use GL_TRIANGLES (TRIANGLES). If I try the same meshes with other primitives, it breaks the mesh, so it depends how the mesh was created.

Here are my demos http://rodrigo-silveira.com/webgl-3d-demos/



来源:https://stackoverflow.com/questions/14503600/what-are-webgls-draw-primitives

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!