Comment by kragen

4 years ago

Why not? What's wrong with it?

Here is "drawing a triangle"

https://www.tutorialspoint.com/webgl/webgl_drawing_a_triangl...

  • That looks like a fair bit of boilerplate, and a shitty tutorial with comments that mostly just repeat what the code says, but the API doesn't look unusable.

    https://github.com/patriciogonzalezvivo/glslCanvas/blob/mast... has most of that same boilerplate in a less repulsive form. https://github.com/patriciogonzalezvivo/glslCanvas/blob/mast... has other bits.

    • Honestly I think your examples are both genuinely less comprehendible to someone without a deep understanding of GL going in than my example.

      It’s a very bad, non-object oriented API in an object oriented language. It was designed for and by people who know GL in other C like languages, not for people who know JavaScript. It is unlike any other part of the language.

      The fact that I have to write a shader myself, as a fricken string like I’m writing SQL over here, just to draw a triangle is absurd. There should at the very least be some sort of provided builder for simple shaders.

      8 replies →

  • Holy living crap. I was all with it up until I saw the actual full HTML example. That is an incredulous amount of overhead for what is essentially one of the most basic and fundamental operations in *GL.

    Comparing this to Canvas is almost like comparing assembly to C. I'm honestly very surprised.

    • Though boilerplate is never acceptable, most of that is constant-factor overhead, not per-triangle overhead, and tutorialspoint is not a site you should trust under any circumstances. See my links above for better sources.

      If you put more vertices and indices in Step 2 you can draw an arbitrarily complex 3-D object with this same code.

      And there's a lot of stuff in GLSL where you can program directly with high-level concepts like vectors, normals, and partial derivatives, instead of expressing them by hand the way you would in C.

      4 replies →

    • Yup. This is why my crappy little 3D game engine still uses canvas and not WebGL. I can’t feel good about myself and deal with all that.

      3 replies →

  • All OpenGL does it draw triangles.

    Once you get through the process of drawing a triangle on the screen then you're learnt 70% of the core of OpenGL. I think you're making the incorrect assumption of "wow if it takes this long to just get a triangle on the screen it must take 1000x as long to get an entire model of a watch" when really you're almost able to draw a model already, you just need to put multiple triangles on the screen now instead of just one.