Giter Club home page Giter Club logo

litegl.js's Introduction

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:

  • Easy context creation
  • Classes for:
    • Meshes and Buffers: Fill a buffer easily and upload it to the GPU
    • Textures: load, fill, clone, copy (even blur) for TEXTURE_2D and TEXTURE_CUBE_MAP
    • Shaders: compile from string, from file, insert preprocessor macros, extracts all the uniform locations
    • FrameBufferObjects: to render to a texture, to multiple textures, to depth texture.
  • Some basic primitive shapes (plane, cube, sphere, cylinder, hemisphere).
  • OBJ parser and encoder (easy to add new ones)
  • Loaders for Images and Meshes from URL (uses a placeholder till its loaded)
  • Uses typed-arrays for everything (uses glMatrix for all operations)
  • No garbage generated (reuses containers)
  • Basic Raytracing (for ray-sphere, ray-aabb, ray-plane, and ray-mesh)
  • Events system
  • Cross-browser input handling for mouse, keyboard and gamepad
  • Supports multiple WebGL contexts
  • Supports WebGL1 and WebGL2
  • Octree class

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

  • Matrices have been replaced by glMatrix
  • Meshes are forced to be stored in ArrayBuffer formats
  • Meshes support range rendering with offset
  • Removed fixed pipeline behaviour
  • Better event handling (mouse position, mouse wheel, dragging)
  • Textures expanded to support Arraybuffers and Cubemaps
  • Events system to trigger events from any object
  • Support for multiple WebGL contexts in the same page

This library has been used in several projects like Rendeer.js or Canvas2DtoWebGL.

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 [email protected]

litegl.js's People

Contributors

jagenjo avatar gustavoraush-tmrwgit avatar mik-c avatar

Stargazers

iorileslie avatar mohamad hani janaty avatar Mario Garcia avatar Dheia avatar Niranjan Anandkumar avatar Crosstyan avatar  avatar JRT avatar 侠客令狐 avatar Johannes Vollmer avatar Gerald Nnebe avatar guoyuandong avatar Zhaoxiaoyang avatar linround avatar  avatar Edgar Bermejo avatar Jacoby Johnson avatar Lucas Jones avatar Vladimir Angelov avatar Manuel Engel avatar Kirill Poga avatar Arne Koenig avatar  avatar Joachim Wester avatar Jack Lee avatar Damaru avatar Dmitry Kolesnikovich avatar pratik vakil avatar  avatar Luke Deen Taylor avatar  avatar Tenvi avatar Li,Weitao avatar Nikita avatar  avatar Andrejs Agejevs avatar Gwenaël Gallon avatar Rutvik Bariya avatar ermouth avatar 胡伟杰 avatar xushicheng avatar  avatar peppemas avatar Tim avatar Antonio Ramírez  avatar Magnus Felix avatar Rexami avatar christian dugenio avatar Serezha avatar  avatar david harvey avatar Sadegh Barati avatar Travis Arnold avatar Max Lawrence avatar  avatar KGBDESIGNGLOBAL avatar Gauss Zhou avatar benzsuankularb avatar Miguel Medina Ballesteros avatar  avatar Lisddbue302 avatar Horus avatar Bao avatar Zibx avatar Dan Bish avatar  avatar Dheera Venkatraman avatar  avatar Faded Weiss avatar  avatar  avatar Lahcéne Belbachir avatar Mikhail Angelov avatar v1rtl avatar Ting Shao avatar Ian Huang (Shaoru) avatar  avatar Chris​‌​‮ ‬Hayes‌​​​ avatar Salt avatar hester avatar plops avatar hwæþere avatar Dave C avatar Pankaj Doharey avatar MJimRenman avatar Masanori Ogino avatar Future Infinity avatar Scott J avatar Jimmy avatar Vladimir Mandic avatar Julien Espagnon avatar Yuanzk avatar Nick avatar Zy avatar Dawid Górny avatar citizenl avatar lixl avatar  avatar  avatar Jaron Wanderley avatar

Watchers

Leon Sorokin avatar Isaac A. Dettman avatar André Philip avatar Xin Chen avatar finscn avatar  avatar timelyportfolio avatar James Cloos avatar mincau avatar Michael Anthony avatar  avatar Jan Marsch avatar Hou Chunlei avatar  avatar  avatar Krtolica Vujadin avatar yisky avatar  avatar  avatar Nico Raftis avatar  avatar  avatar  avatar  avatar Satish Goda avatar bxavier avatar  avatar

litegl.js's Issues

Possible memory leak ?

Hi !

I'm trying to develop video texture plane but I have some problems, since GPU memory increase until crash:

		 gl.ondraw = function()
				 {

					 if (_stream ){
						 first =false;
						 let texture = Texture.fromVideo(_stream,{minFilter: gl.NEAREST});
						 texture.bind(0);
						 shader.uniforms({
								 u_color: [1,1,1,1],
								 u_model: model,
								 u_texture: 0,
								 u_mvp: mvp
							 }).draw(mesh);


				 }
			 }

What am I doing wrong ?

Thanks !

How can I use vertex colors?

I learned that litegl.js is a library developed by forking lightgl.js.
I tried to port a sample of lightgl.js using vertex colors to a version using litegl.js.
However, I did not know how to use vertex colors in litegl.js.
Is it possible to use vertex colors in this library?

The following is a sample using vertex color in lightgl.js.
http://jsdo.it/cx20/br0W

image

Multiple contexts on the same page

Is there a good example illustrating multiple contexts on the same page? I'm getting WebGL: INVALID_OPERATION: bindBuffer: object does not belong to this context and not quite sure where to start.

examples/threejs.html not work in the latest version

Hi Jagenjo,

before I ever tested and threejs example works well, but when I updated repo these days it won't work right now, no error but many warnings.

"three.js:4505 WebGL: INVALID_OPERATION: uniformMatrix4fv: location is not from current program"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.