Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.





                html, body, canvas {
  width: 100%;
  height: 100%;
  border: 0;
  padding: 0;
  margin: 0;
  position: absolute;
form {
  position: absolute;
  bottom: 0;
  left: 0;


                const img = new Image();
img.crossOrigin = "";

// thanks to Ken Cheung
img.src = `${window.innerWidth}&q=80`;

img.onload = () => {
	// assume this runs all the code we've been writing so far

function initializeWebGLStuff() {
	const canvas = document.querySelector('canvas');
  // have the canvas dimensions match the actual image dimensions for best quality
  canvas.width = img.width;
  canvas.height = img.height;
	const gl = canvas.getContext('webgl');

	const vertexShaderSource = `
	attribute vec2 points;
	attribute vec2 texture_coordinate;

	varying highp vec2 v_texture_coordinate;

	void main(void) {
		gl_Position = vec4(points, 0.0, 1.0);
		v_texture_coordinate = texture_coordinate;

	const fragmentShaderSource = `
	precision highp float;
	varying highp vec2 v_texture_coordinate;
	uniform sampler2D sampler;

	void main() {
		gl_FragColor = texture2D(sampler, v_texture_coordinate);
	// create a program (which we'll access later)
	const program = gl.createProgram();

	// create a new vertex shader and a fragment shader
	const vertexShader = gl.createShader(gl.VERTEX_SHADER);
	const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);

	// specify the source code for the shaders using those strings
	gl.shaderSource(vertexShader, vertexShaderSource);
	gl.shaderSource(fragmentShader, fragmentShaderSource);

	// compile the shaders

	// attach the two shaders to the program
	gl.attachShader(program, vertexShader);
	gl.attachShader(program, fragmentShader);
	if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {

	const points = [
		// first triangle
		// top left
		-1, -1,

		// top right
		1, -1,

		// bottom left
		-1, 1,

		// second triangle
		// bottom right
		1, 1,

		// top right
		1, -1,

		// bottom left
		-1, 1,

	// create a buffer
	const buffer = gl.createBuffer();

	// activate the buffer, and specify that it contains an array
	gl.bindBuffer(gl.ARRAY_BUFFER, buffer);

	// upload the points array to the active buffer
	// gl.STATIC_DRAW tells the GPU this data won't change
	gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(points), gl.STATIC_DRAW);

	// get the location of our "points" attribute in our shader program
	const location = gl.getAttribLocation(program, 'points');

	// pull out pairs of float numbers from the active buffer
	// each pair is a vertex that will be available in our vertex shader
	gl.vertexAttribPointer(location, 2, gl.FLOAT, false, 0, 0);

	// enable the attribute in the program

	// create a new texture
	const texture = gl.createTexture();

	// specify that our texture is 2-dimensional
	gl.bindTexture(gl.TEXTURE_2D, texture);

	// upload the 2D image (img) and specify that it contains RGBA data
	gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img);

	// tell WebGL how to choose pixels when drawing our non-square image
	gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
	gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
	gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);

	// bind this texture to texture #0
	gl.bindTexture(gl.TEXTURE_2D, texture);

	// use the texture for the uniform in our program called "sampler",
	gl.uniform1i(gl.getUniformLocation(program, 'sampler'), 0);

	const textureCoordinates = [
		// first triangle
		// top left
		0, 1,

		// top right
		1, 1,

		// bottom left
		0, 0,

		// second triangle
		// bottom right
		1, 0,

		// top right
		1, 1,

		// bottom left
		0, 0,

	// same stuff we did earlier, but passing different numbers
	const textureCoordinateBuffer = gl.createBuffer();
	gl.bindBuffer(gl.ARRAY_BUFFER, textureCoordinateBuffer);
		new Float32Array(textureCoordinates),

	// and associating it with a different attribute
	const textureCoordinateLocation = gl.getAttribLocation(
	gl.vertexAttribPointer(textureCoordinateLocation, 2, gl.FLOAT, false, 0, 0);

	gl.drawArrays(gl.TRIANGLES, 0, 6);