Socket
Socket
Sign inDemoInstall

regl

Package Overview
Dependencies
Maintainers
5
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

regl

regl is a fast functional WebGL framework.


Version published
Weekly downloads
254K
increased by2.4%
Maintainers
5
Weekly downloads
 
Created

What is regl?

regl is a functional abstraction for WebGL that simplifies the process of creating and managing WebGL contexts and rendering pipelines. It provides a declarative API for defining shaders, buffers, and other WebGL resources, making it easier to build complex graphics applications.

What are regl's main functionalities?

Creating a WebGL Context

This code initializes a new regl instance, which sets up a WebGL context and prepares it for rendering.

const regl = require('regl')();

Drawing a Simple Triangle

This code defines a simple triangle using regl. It specifies the vertex and fragment shaders, the vertex positions, and the draw call. The triangle is drawn in each frame.

const drawTriangle = regl({
  frag: `
  precision mediump float;
  void main () {
    gl_FragColor = vec4(1, 0, 0, 1);
  }
  `,
  vert: `
  precision mediump float;
  attribute vec2 position;
  void main () {
    gl_Position = vec4(position, 0, 1);
  }
  `,
  attributes: {
    position: [
      [-1, 0],
      [0, -1],
      [1, 1]
    ]
  },
  count: 3
});

regl.frame(() => {
  regl.clear({
    color: [0, 0, 0, 1],
    depth: 1
  });
  drawTriangle();
});

Managing Buffers

This code demonstrates how to create and use a buffer in regl. The buffer stores vertex positions, which are then used in the draw call.

const positionBuffer = regl.buffer([
  [-1, 0],
  [0, -1],
  [1, 1]
]);

const drawWithBuffer = regl({
  frag: `
  precision mediump float;
  void main () {
    gl_FragColor = vec4(0, 1, 0, 1);
  }
  `,
  vert: `
  precision mediump float;
  attribute vec2 position;
  void main () {
    gl_Position = vec4(position, 0, 1);
  }
  `,
  attributes: {
    position: positionBuffer
  },
  count: 3
});

regl.frame(() => {
  regl.clear({
    color: [0, 0, 0, 1],
    depth: 1
  });
  drawWithBuffer();
});

Using Uniforms

This code shows how to use uniforms in regl. The uniform 'color' is passed to the fragment shader, allowing dynamic control over the color of the rendered triangle.

const drawWithUniforms = regl({
  frag: `
  precision mediump float;
  uniform vec4 color;
  void main () {
    gl_FragColor = color;
  }
  `,
  vert: `
  precision mediump float;
  attribute vec2 position;
  void main () {
    gl_Position = vec4(position, 0, 1);
  }
  `,
  attributes: {
    position: [
      [-1, 0],
      [0, -1],
      [1, 1]
    ]
  },
  uniforms: {
    color: [0, 0, 1, 1]
  },
  count: 3
});

regl.frame(() => {
  regl.clear({
    color: [0, 0, 0, 1],
    depth: 1
  });
  drawWithUniforms();
});

Other packages similar to regl

Keywords

FAQs

Package last updated on 14 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc