All Projects → jagenjo → Canvas2dtowebgl

jagenjo / Canvas2dtowebgl

Licence: mit
Ports (almost) all Canvas2D functions to the GPU so it can be mixed with a WebGL canvas.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Canvas2dtowebgl

Pancake
Lightweight, Fast, Easy-to-use HTML5 2D game framework!
Stars: ✭ 79 (-61.65%)
Mutual labels:  webgl, canvas, canvas2d
Melonjs
a fresh & lightweight javascript game engine
Stars: ✭ 3,721 (+1706.31%)
Mutual labels:  webgl, canvas2d, canvas
Pixi.js
The HTML5 Creation Engine: Create beautiful digital content with the fastest, most flexible 2D WebGL renderer.
Stars: ✭ 34,982 (+16881.55%)
Mutual labels:  webgl, canvas2d, canvas
Picasso
Picasso is a high quality 2D vector graphic rendering library. It support path , matrix , gradient , pattern , image and truetype font.
Stars: ✭ 205 (-0.49%)
Mutual labels:  canvas2d, canvas
Hilo3d
Hilo3d, a WebGL Rendering Engine.
Stars: ✭ 123 (-40.29%)
Mutual labels:  webgl, canvas
Gcanvas
A lightweight cross-platform graphics rendering engine. (超轻量的跨平台图形引擎) https://alibaba.github.io/GCanvas
Stars: ✭ 1,705 (+727.67%)
Mutual labels:  webgl, canvas
Skqw
JavaScript Audio Visualizer
Stars: ✭ 112 (-45.63%)
Mutual labels:  webgl, canvas
Alien.js
Future web pattern
Stars: ✭ 141 (-31.55%)
Mutual labels:  webgl, canvas
Phaser Examples
Contains hundreds of source code examples and related media for the Phaser HTML5 Game Framework.
Stars: ✭ 1,680 (+715.53%)
Mutual labels:  webgl, canvas
Demos
One repo to rule them all.
Stars: ✭ 204 (-0.97%)
Mutual labels:  webgl, canvas
Zen 3d
JavaScript 3D library.
Stars: ✭ 155 (-24.76%)
Mutual labels:  webgl, canvas
Gown.js
UI system for pixi.js inspired by feathers-ui
Stars: ✭ 195 (-5.34%)
Mutual labels:  webgl, canvas
Freeciv Web
Freeciv-web is an Open Source strategy game implemented in HTML5 and WebGL, which can be played online against other players, or in single player mode against AI opponents.
Stars: ✭ 1,626 (+689.32%)
Mutual labels:  webgl, canvas
Earthjs
D3 Earth JS
Stars: ✭ 128 (-37.86%)
Mutual labels:  webgl, canvas
Knowledge
文档着重构建一个完整的「前端技术架构图谱」,方便 F2E(Front End Engineering又称FEE、F2E) 学习与进阶。
Stars: ✭ 1,620 (+686.41%)
Mutual labels:  webgl, canvas
R3f Next Starter
Repo is moving to https://github.com/pmndrs/react-three-next
Stars: ✭ 137 (-33.5%)
Mutual labels:  webgl, canvas
Proton
Javascript particle animation library
Stars: ✭ 1,958 (+850.49%)
Mutual labels:  webgl, canvas
Layaair discard
This is old LayaAir veriosn writetten by ActionScript 3.0 ,now LayaAir is using TypeScript as the Engine Script,Please use https://github.com/layabox/LayaAir instead.
Stars: ✭ 1,858 (+801.94%)
Mutual labels:  webgl, canvas
Pixi Haxe
Externs of Pixi.js for Haxe
Stars: ✭ 175 (-15.05%)
Mutual labels:  webgl, canvas
Fe Daily Record
📚前端书籍汇集点 + 每日好文推荐 + 公开课学习资料 + 各种大会资料
Stars: ✭ 94 (-54.37%)
Mutual labels:  webgl, canvas

Canvas2DtoWebGL.js

Canvas2DtoWebGL.js ports almost all the methods from the regular Canvas2D context (CanvasRenderingContext2D) of HTML5 to WebGL calls, this allows to mix 3D in your 2D Canvas or the opposite (to create GUIs, debug info, etc), and in some cases it could even improve the performance of your regular Canvas2D (when working with big images). It uses litegl.js as the base WebGL library. To improve performance it doesn't generate garbage (reuses the same containers). It can work with non power of two textures (no mipmaps obviously).

Fully supported functions:

  • translate, rotate, scale, transform, setTransform, save, restore
  • clearRect
  • strokeStyle, fillStyle, globalAlpha
  • drawImage you can use images or canvas (video not tested)
  • beginPath, lineTo, moveTo, closePath, stroke, rect, strokeRect, fillRect, arc
  • fill (limited to convex shapes)
  • createPattern with images
  • bezierCurveTo and quadraticCurveTo
  • fillText (it creates a texture atlas with all the characters)
  • lineWidth (only one mode supported)
  • imageSmoothingEnabled
  • getImageData and putImageData (not fully tested)
  • shadows (not blurred)
  • createLinearGradient
  • clip

Not supported (yet):

  • globalCompositeOperation
  • concave polygon shapes

Won't be supported:

  • Blurred shadows

It is easy to tweak, all the parameters are publicly available inside the context (matrix, colors, etc). Textures handlers are cached inside the Image object itself, this means that reusing the same images between different Canvas2D context would have a performance penalty.

Extra features

It not only provide the Canvas2D functions, it also comes with some extra ones that you can call directly to speed up some processes (like setting colors, modifying the matrix) or even creating some FX that would be hard in a regular Canvas (applying a shader to an image, colorizing an image).

Demos & Benchmark

Demos are included in demo folder, you can test it here

Usage

Include the library and dependencies

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

Once you have your Canvas created (and before a CanvasRenderingContext2D has been obtained), call this function:

var ctx = enableWebGLCanvas( mycanvas );

During your rendering you must call this two functions, it helps set the flags accordingly.

ctx.start2D();

//your rendering code
//...

ctx.finish2D();

Feedback

You can write any feedback to [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].