Home

Awesome

litegl.js

Litegl.js is a library that wraps WebGL to make it more user-friendly by creating classes for managing different items like Buffer, Mesh, Texture, Shader and other common aspects of any WebGL applications.

It helps simplifying working with WebGL without having to handle all the low-level calls but without losing any freedom.

Some features are:

It is a fork from LightGL.js by Evan Wallace, but some major changes have been made. Some of the main differences:

This library has been used in several projects like Rendeer.js or Canvas2DtoWebGL.</p>

For a list of similar libraries check this list

If you need something more high-level like ThreeJS check Rendeer.js, my own SceneGraph + Renderer library that supports GLTF, Skeletal Animation and PBR rendering.

Demos

Demos are included in the Examples folder but you can check them in this website.

Usage

Include the library and dependencies

<script src="js/gl-matrix-min.js"></script>
<script src="js/litegl.js"></script>

Create the context

var gl = GL.create({width:800, height:600});

Attach to DOM

document.getElementById("mycontainer").appendChild( gl.canvas )

Get user input

gl.captureMouse();
gl.onmousedown = function(e) { ... }

gl.captureKeys();
gl.onkey = function(e) { ... }

Compile shader

var shader = new GL.Shader( vertex_shader_code, fragment_shader_code );

Create Mesh

var mesh = new GL.Mesh({vertices:[-1,-1,0, 1,-1,0, 0,1,0], coords:[0,0, 1,0, 0.5,1]});

Load a texture

var texture = GL.Texture.fromURL("image.jpg", { minFilter: gl.LINEAR_MIPMAP_LINEAR });

Render

gl.ondraw = function() {
	texture.bind(0);
	var my_uniforms = { u_texture: 0, u_color: [1,1,1,1] };
	shader.uniforms( my_uniforms ).draw( mesh );
}

gl.animate(); //calls the requestAnimFrame constantly, which will call ondraw

For better understanding of all the features and how to use them check the guides folder.

Documentation

The doc folder contains the documentation. For info about glmatrix.net check the documentation in its website.

Check the guides folder to see how to use all the features.

Utils

It includes several commands in the utils folder to generate doc, check errors and build minifyed version.

Feedback

You can write any feedback to javi.agenjo@gmail.com