Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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.



Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO


Save Automatically?

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.


Make Template?

Templates are Pens that can be used to start other Pens quickly from the create menu. The new Pen will copy all the code and settings from the template and make a new Pen (that is not a fork). You can view all of your templates, or learn more in the documentation.

Template URL

Any Pen can act as a template (even if you don't flip the toggle above) with a special URL you can use yourself or share with others. Here's this Pen's template URL:


Screenshot or Custom Thumbnail

Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO



        <title>Learning WebGL &mdash; lesson 1</title>
        <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">

        <script src=""></script>
        <script src=""></script>

        <script id="shader-fs" type="x-shader/x-fragment">
            precision mediump float;

            void main(void) {
                gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);

        <script id="shader-vs" type="x-shader/x-vertex">
            attribute vec3 aVertexPosition;

            uniform mat4 uMVMatrix;
            uniform mat4 uPMatrix;

            void main(void) {
                gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);

        <script type="text/javascript">
            var game;
            var gl;
            var mvMatrix = mat4.create();
            var pMatrix = mat4.create();
            var triangleVertexPositionBuffer;
            var shaderProgram;
            var baseTexture;
            var sprite;

            function initGL(canvas) {
                try {
                    gl = canvas.getContext("webgl");
                    gl.viewportWidth = canvas.width;
                    gl.viewportHeight = canvas.height;
                } catch (e) {
                if (!gl) {
                    alert("Could not initialise WebGL, sorry :-(");

            function getShader(gl, id) {
                var shaderScript = document.getElementById(id);
                if (!shaderScript) {
                    return null;

                var str = "";
                var k = shaderScript.firstChild;
                while (k) {
                    if (k.nodeType == 3) {
                        str += k.textContent;
                    k = k.nextSibling;

                var shader;
                if (shaderScript.type == "x-shader/x-fragment") {
                    shader = gl.createShader(gl.FRAGMENT_SHADER);
                } else if (shaderScript.type == "x-shader/x-vertex") {
                    shader = gl.createShader(gl.VERTEX_SHADER);
                } else {
                    return null;

                gl.shaderSource(shader, str);

                if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
                    return null;

                return shader;

            function initShaders() {
                var fragmentShader = getShader(gl, "shader-fs");
                var vertexShader = getShader(gl, "shader-vs");

                shaderProgram = gl.createProgram();
                gl.attachShader(shaderProgram, vertexShader);
                gl.attachShader(shaderProgram, fragmentShader);

                if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
                    alert("Could not initialise shaders");


                shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");

                shaderProgram.pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix");
                shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");

            function setMatrixUniforms() {
                gl.uniformMatrix4fv(shaderProgram.pMatrixUniform, false, pMatrix);
                gl.uniformMatrix4fv(shaderProgram.mvMatrixUniform, false, mvMatrix);

            function initBuffers() {
                triangleVertexPositionBuffer = gl.createBuffer();
                gl.bindBuffer(gl.ARRAY_BUFFER, triangleVertexPositionBuffer);
                var vertices = [
                    0.0,  1.0,  0.0,
                    -1.0, -1.0,  0.0,
                    1.0, -1.0,  0.0
                gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW);
                triangleVertexPositionBuffer.itemSize = 3;
                triangleVertexPositionBuffer.numItems = 3;

            function drawScene() {
                gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
                gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

                mat4.perspective(45, gl.viewportWidth / gl.viewportHeight, 0.1, 100.0, pMatrix);


                mat4.translate(mvMatrix, [0.0, 0.0, -7.0]);
                gl.bindBuffer(gl.ARRAY_BUFFER, triangleVertexPositionBuffer);
                gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, triangleVertexPositionBuffer.itemSize, gl.FLOAT, false, 0, 0);
                gl.drawArrays(gl.TRIANGLES, 0, triangleVertexPositionBuffer.numItems);

            function initPhaser() {
                game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.WEBGL, 'phaser-container', {
                    preload: preload,
                    create: create,
                    update: update,
                    render: render

            function preload () {
                var canvas = document.getElementById("backbuffer-canvas");

            function create () {
                var canvas = document.getElementById('backbuffer-canvas');
                var context = canvas.getContext('2d');
                baseTexture = new PIXI.BaseTexture(canvas);
                var texture = new PIXI.Texture(baseTexture);
                var textureFrame = new Phaser.Frame(0, 0, 0, game.width, game.height, 'debug', game.rnd.uuid());
                sprite = game.add.sprite(0, 0, texture, textureFrame);
                sprite.fixedToCamera = true;

            function zoomIn() {
                tween = game.add.tween(sprite.scale).to( { x: 2, y: 2 }, 2000, Phaser.Easing.Exponential.In, true);
                tween.onComplete.add(zoomOut, this);

            function zoomOut() {
                tween = game.add.tween(sprite.scale).to( { x: 0, y: 0 }, 2000, Phaser.Easing.Exponential.Out, true);
                tween.onComplete.add(zoomIn, this);

            function update() {

            function render() {
                gl.clearColor(0.0, 0.0, 0.0, 1.0);


    <body onload="initPhaser();">
        <div id="phaser-container"></div>
        <div id="backbuffer" style="display: none;">
            <canvas id="backbuffer-canvas" style="border: none;" width="500" height="500"></canvas>





Keep the <main> thing the <main> thing.