WebGL hello world
You should see a green square above this line.
<canvas> element, and its content is rendered with WebGL.
The code looks like this:
<div><canvas id="canvas" width="100" height="100"></canvas></div> <script> const canvasEl = document.getElementById("canvas"); const ctx = canvasEl.getContext("webgl"); ctx.clientWidth = canvas.width; ctx.clientHeight = canvas.height; ctx.clearColor(0,1,0,1); ctx.clear(ctx.COLOR_BUFFER_BIT); </script>
For old-school HTML canvas, we use
For WebGL, we pass a different string:
(There are other strings available,
A WebGL context is mostly unrelated to a
its methods and properties are entirely different.
The main thing we do is set the “color buffer” to entirely green. (We also set up some canvas and GL client sizes. I’ll deal with canvas/CSS/GL dimensions in a future post.)
More by Jim
- Your syntax highlighter is wrong
- Granddad died today
- The Three Ts of Time, Thought and Typing: measuring cost on the web
- I hate telephones
- The sorry state of OpenSSL usability
- The dots do matter: how to scam a Gmail user
- My parents are Flat-Earthers
- How Hacker News stays interesting
- Project C-43: the lost origins of asymmetric crypto
- The hacker hype cycle
- The inception bar: a new phishing method
- Time is running out to catch COVID-19
- A probabilistic pub quiz for nerds
- Smear phishing: a new Android vulnerability
Tagged . All content copyright James Fisher 2017. This post is not associated with my employer. Found an error? Edit this page.