Comment by lostgame
4 years ago
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.
Using a framework is also constant factor overhead (at least in LoC, which is what I assume we're talking about here)
Right, and that's what the glslCanvas project I linked above is, though in this case it's negative overhead if you're just counting the lines of code you have to maintain :)
2 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.
Yeah, Canvas 2D is great, though it's not any more OO than WebGL, and I sometimes forget to create a new path and wonder why it keeps getting slower and slower with every frame. SVG is also pretty reasonable.
Neat, you do the math yourself and then render the tris/quads in canvas? I did something like that recently (in C/SDL, later RayLib). I found it amusing that to get performant 2D rendering you have to use a 3D API, so my "software rendered" 3D engine which just uses the gfx api for 2D draw calls ends up using 3D for the 2D under the hood...
There's at least one (great) game written like that though, Need for Madness with a custom 3D engine and just using java's 2D gfx api for rendering.
I did this in 02007 in JS: http://canonical.org/~kragen/sw/torus
Except that WebGL didn't exist so I just had to use the 2-D <canvas>. There's probably some trick for getting antialiased polygon edges in <canvas> to not show cracks...